#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 */
char EOF;
char getchar();
int /*<<< orphan*/ printf(char *);
int main() {
  int i;
  char s[100];
  char c;
  void print_string(char *s);
  for (i = 0; i < 100; i++)
    s[i] = 0;
  printf("\nEnter a string, I will repeat it.\n\n");
  for (i = 0; i < 100 - 1 && (c = getchar()) != '\n' && c != EOF; ++i)
    s[i] = c;
  printf("\nYou entered: ");
  print_string(s);
  printf("\n\nNow enter it again and I will use a different loop...\n\n");
  for (i = 0; i < 100; i++)
    s[i] = 0;
  for (i = 0; i < 100 - 1; i++) {
    c = getchar();
    if (c == '\n')
      i = 100;
    else if (c == EOF)
      i = 100;
    else
      s[i] = c;
  }
  printf("\nYou entered: ");
  print_string(s);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    116a <main+0x3a>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1149 <main+0x19>
lea    0xe8f(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
xor    %eax,%eax
cmpl   $0x63,-0x8(%rbp)
mov    %al,-0x72(%rbp)
jge    11bd <main+0x8d>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x71(%rbp)
movsbl %al,%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x72(%rbp)
je     11bd <main+0x8d>
movsbl -0x71(%rbp),%eax
mov    0x2e36(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
setne  %al
mov    %al,-0x72(%rbp)
mov    -0x72(%rbp),%al
test   $0x1,%al
jne    11cd <main+0x9d>
jmp    11e6 <main+0xb6>
mov    -0x71(%rbp),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117d <main+0x4d>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <print_string@plt>
lea    0xe32(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x8(%rbp)
cmpl   $0x64,-0x8(%rbp)
jge    122f <main+0xff>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    120e <main+0xde>
movl   $0x0,-0x8(%rbp)
cmpl   $0x63,-0x8(%rbp)
jge    12a8 <main+0x178>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x71(%rbp)
movsbl -0x71(%rbp),%eax
cmp    $0xa,%eax
jne    1263 <main+0x133>
movl   $0x64,-0x8(%rbp)
jmp    1295 <main+0x165>
movsbl -0x71(%rbp),%eax
mov    0x2d7a(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    1285 <main+0x155>
movl   $0x64,-0x8(%rbp)
jmp    1290 <main+0x160>
mov    -0x71(%rbp),%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x70(%rbp,%rax,1)
jmp    1295 <main+0x165>
jmp    129a <main+0x16a>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1236 <main+0x106>
lea    0xd76(%rip),%rdi
call   1030 <printf@plt>
lea    -0x70(%rbp),%rdi
call   1040 <print_string@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xe98(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e65(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     11ad <main+0x6d>
cmp    (%r14),%al
je     11ad <main+0x6d>
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
cmp    $0x63,%rbx
jne    1190 <main+0x50>
lea    0xe4c(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <print_string@plt>
lea    0xe68(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movl   $0x0,0x60(%rsp)
mov    $0xffffffff,%ebp
nopl   (%rax)
xor    %eax,%eax
call   1060 <getchar@plt>
cmp    $0xa,%al
je     121e <main+0xde>
cmp    (%r14),%al
je     121e <main+0xde>
mov    %al,(%rbx)
add    $0x1,%ebp
add    $0x1,%rbx
cmp    $0x62,%ebp
jb     1200 <main+0xc0>
lea    0xddb(%rip),%rdi
call   1040 <printf@plt>
mov    %rsp,%rdi
call   1050 <print_string@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"\0AEnter a string, I will repeat it.\0A\0A\00"
@EOF = global i8 0
@.str.1 = [15 x i8] c"\0AYou entered: \00"
@.str.2 = [58 x i8] c"\0A\0ANow enter it again and I will use a different loop...\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i8
store i32 0, i32* %1
store i32 0, i32* %2
br label %5
5: ; preds = %12, %0
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 100
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %10
store i8 0, i8* %11
br label %12
12: ; preds = %8
%13 = load i32, i32* %2
%14 = add nsw i32 %13, 1
store i32 %14, i32* %2
br label %5
15: ; preds = %5
%16 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %17
17: ; preds = %37, %15
%18 = load i32, i32* %2
%19 = icmp slt i32 %18, 99
br i1 %19, label %20, label %30
20: ; preds = %17
%21 = call signext i8 (...) @getchar()
store i8 %21, i8* %4
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 10
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8, i8* %4
%26 = sext i8 %25 to i32
%27 = load i8, i8* @EOF
%28 = sext i8 %27 to i32
%29 = icmp ne i32 %26, %28
br label %30
30: ; preds = %24, %20, %17
%31 = phi i1 [ false, %20 ], [ false, %17 ], [ %29, %24 ]
br i1 %31, label %32, label %40
32: ; preds = %30
%33 = load i8, i8* %4
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %35
store i8 %33, i8* %36
br label %37
37: ; preds = %32
%38 = load i32, i32* %2
%39 = add nsw i32 %38, 1
store i32 %39, i32* %2
br label %17
40: ; preds = %30
%41 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%43 = call i32 @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %2
br label %44
44: ; preds = %51, %40
%45 = load i32, i32* %2
%46 = icmp slt i32 %45, 100
br i1 %46, label %47, label %54
47: ; preds = %44
%48 = load i32, i32* %2
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %49
store i8 0, i8* %50
br label %51
51: ; preds = %47
%52 = load i32, i32* %2
%53 = add nsw i32 %52, 1
store i32 %53, i32* %2
br label %44
54: ; preds = %44
store i32 0, i32* %2
br label %55
55: ; preds = %78, %54
%56 = load i32, i32* %2
%57 = icmp slt i32 %56, 99
br i1 %57, label %58, label %81
58: ; preds = %55
%59 = call signext i8 (...) @getchar()
store i8 %59, i8* %4
%60 = load i8, i8* %4
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 10
br i1 %62, label %63, label %64
63: ; preds = %58
store i32 100, i32* %2
br label %77
64: ; preds = %58
%65 = load i8, i8* %4
%66 = sext i8 %65 to i32
%67 = load i8, i8* @EOF
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %66, %68
br i1 %69, label %70, label %71
70: ; preds = %64
store i32 100, i32* %2
br label %76
71: ; preds = %64
%72 = load i8, i8* %4
%73 = load i32, i32* %2
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %74
store i8 %72, i8* %75
br label %76
76: ; preds = %71, %70
br label %77
77: ; preds = %76, %63
br label %78
78: ; preds = %77
%79 = load i32, i32* %2
%80 = add nsw i32 %79, 1
store i32 %80, i32* %2
br label %55
81: ; preds = %55
%82 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%83 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
ret i32 0
}

LLVM IR (-O2):
@EOF = global i8 0
@.str.1 = [15 x i8] c"\0AYou entered: \00"
@str = [36 x i8] c"\0AEnter a string, I will repeat it.\0A\00"
@str.3 = [57 x i8] c"\0A\0ANow enter it again and I will use a different loop...\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
br label %5
5: ; preds = %0, %12
%6 = phi i64 [ 0, %0 ], [ %14, %12 ]
%7 = tail call signext i8 (...) @getchar()
%8 = icmp eq i8 %7, 10
%9 = load i8, i8* @EOF
%10 = icmp eq i8 %7, %9
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %16, label %12
12: ; preds = %5
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %6
store i8 %7, i8* %13
%14 = add nuw nsw i64 %6, 1
%15 = icmp eq i64 %14, 99
br i1 %15, label %16, label %5
16: ; preds = %12, %5
%17 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.3, i64 0, i64 0))
br label %19
19: ; preds = %16, %26
%20 = phi i32 [ %29, %26 ], [ 0, %16 ]
%21 = call signext i8 (...) @getchar()
%22 = icmp eq i8 %21, 10
%23 = load i8, i8* @EOF
%24 = icmp eq i8 %21, %23
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %31, label %26
26: ; preds = %19
%27 = zext i32 %20 to i64
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %27
store i8 %21, i8* %28
%29 = add nuw nsw i32 %20, 1
%30 = icmp ult i32 %20, 98
br i1 %30, label %19, label %31
31: ; preds = %19, %26
%32 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}