#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  char *fmt = "%[^\n]%*c";
  while (1) {
    char text[50] = {0};
    printf("Type something\n");
    scanf(fmt, text);
    if (text[0] == '\0') {
      break;
    }
    int cnt = 0;
    printf("The result is \n");
    while (text[cnt] != '\0') {
      putchar(text[cnt]);
      cnt++;
    }
    printf("\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x32,%edx
call   1050 <memset@plt>
lea    0xe98(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1060 <scanf@plt>
movsbl -0x50(%rbp),%eax
cmp    $0x0,%eax
jne    1195 <main+0x55>
jmp    11e7 <main+0xa7>
movl   $0x0,-0x54(%rbp)
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11d6 <main+0x96>
movslq -0x54(%rbp),%rax
movsbl -0x50(%rbp,%rax,1),%edi
call   1030 <putchar@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    11a8 <main+0x68>
lea    0xe4a(%rip),%rdi
call   1040 <printf@plt>
jmp    115a <main+0x1a>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
lea    0xeac(%rip),%rdi
call   1040 <puts@plt>
lea    0xe97(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
cmpb   $0x0,(%rsp)
je     1206 <main+0xd6>
lea    0x1(%rsp),%r13
lea    0xe91(%rip),%r14
lea    0xe7b(%rip),%r15
lea    0xe6b(%rip),%r12
mov    %rsp,%rbx
jmp    11db <main+0xab>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   1030 <putchar@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movw   $0x0,0x30(%rsp)
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
cmpb   $0x0,(%rsp)
je     1206 <main+0xd6>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    (%rsp),%al
test   %al,%al
je     11a0 <main+0x70>
mov    %r13,%rbp
nopl   (%rax)
movsbl %al,%edi
call   1030 <putchar@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    11f0 <main+0xc0>
jmp    11a0 <main+0x70>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%[^\0A]%*c\00"
@.str.1 = [16 x i8] c"Type something\0A\00"
@.str.2 = [16 x i8] c"The result is \0A\00"
@.str.3 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca [50 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8** %2
br label %5
5: ; preds = %0, %33
%6 = bitcast [50 x i8]* %3 to i8*
%7 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%8 = load i8*, i8** %2
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%10 = call i32 @scanf(i8* %8, i8* %9)
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %5
br label %35
16: ; preds = %5
store i32 0, i32* %4
%17 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %25, %16
%19 = load i32, i32* %4
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %18
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @putchar(i8 signext %29)
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %18
33: ; preds = %18
%34 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %5
35: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"%[^\0A]%*c\00"
@str = [15 x i8] c"Type something\00"
@str.4 = [15 x i8] c"The result is \00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%5 = load i8, i8* %2
%6 = icmp eq i8 %5, 0
br i1 %6, label %25, label %7
7: ; preds = %0, %19
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.4, i64 0, i64 0))
%9 = load i8, i8* %2
%10 = icmp eq i8 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %7, %11
%12 = phi i64 [ %15, %11 ], [ 0, %7 ]
%13 = phi i8 [ %17, %11 ], [ %9, %7 ]
%14 = call i32 @putchar(i8 signext %13)
%15 = add nuw i64 %12, 1
%16 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %19, label %11
19: ; preds = %11, %7
%20 = call i32 bitcast (i32 (i8)* @putchar to i32 (i32)*)(i32 10)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%22 = call i32 @scanf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %2)
%23 = load i8, i8* %2
%24 = icmp eq i8 %23, 0
br i1 %24, label %25, label %7
25: ; preds = %19, %0
ret i32 0
}