#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 */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int main() {
  char input[500];
  int i;
  i = 5;
  while (i > 0 && fgets(input, 500, stdin)) {
    printf("You sent:%s", input);
    printf("I will echo %d more times\n", --i);
    memset(input, 0, strlen(input));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x5,-0x204(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x204(%rbp)
mov    %al,-0x205(%rbp)
jle    1198 <main+0x58>
lea    -0x200(%rbp),%rdi
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
mov    $0x1f4,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x205(%rbp)
mov    -0x205(%rbp),%al
test   $0x1,%al
jne    11ab <main+0x6b>
jmp    120c <main+0xcc>
lea    -0x200(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x204(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0x204(%rbp)
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x200(%rbp),%rax
mov    %rax,-0x210(%rbp)
lea    -0x200(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x210(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
jmp    115c <main+0x1c>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x1f8,%rsp
mov    0x2e97(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rdi
mov    $0x1f4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12ee <main+0x1ae>
lea    0xe8f(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe87(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12ee <main+0x1ae>
lea    0xe3b(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe33(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12ee <main+0x1ae>
lea    0xde7(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xddf(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12ee <main+0x1ae>
lea    0xd93(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd8b(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x1f4,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     12ee <main+0x1ae>
lea    0xd43(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd3b(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
xor    %eax,%eax
add    $0x1f8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [12 x i8] c"You sent:%s\00"
@.str.1 = [27 x i8] c"I will echo %d more times\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [500 x i8]
%3 = alloca i32
store i32 0, i32* %1
store i32 5, i32* %3
br label %4
4: ; preds = %14, %0
%5 = load i32, i32* %3
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i64 @fgets(i8* %8, i32 500, i32 %9)
%11 = icmp ne i64 %10, 0
br label %12
12: ; preds = %7, %4
%13 = phi i1 [ false, %4 ], [ %11, %7 ]
br i1 %13, label %14, label %24
14: ; preds = %12
%15 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* %3
%18 = add nsw i32 %17, -1
store i32 %18, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %18)
%20 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%21 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 @memset(i8* %20, i32 0, i32 %22)
br label %4
24: ; preds = %12
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [12 x i8] c"You sent:%s\00"
@.str.1 = [27 x i8] c"I will echo %d more times\0A\00"
define i32 @main() {
%1 = alloca [500 x i8]
%2 = getelementptr inbounds [500 x i8], [500 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i64 @fgets(i8* %2, i32 500, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %43, label %6
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 4)
%9 = call i32 @strlen(i8* %2)
%10 = call i32 @memset(i8* %2, i32 0, i32 %9)
%11 = load i32, i32* @stdin
%12 = call i64 @fgets(i8* %2, i32 500, i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %43, label %14
14: ; preds = %6
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 3)
%17 = call i32 @strlen(i8* %2)
%18 = call i32 @memset(i8* %2, i32 0, i32 %17)
%19 = load i32, i32* @stdin
%20 = call i64 @fgets(i8* %2, i32 500, i32 %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %43, label %22
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 2)
%25 = call i32 @strlen(i8* %2)
%26 = call i32 @memset(i8* %2, i32 0, i32 %25)
%27 = load i32, i32* @stdin
%28 = call i64 @fgets(i8* %2, i32 500, i32 %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %43, label %30
30: ; preds = %22
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 1)
%33 = call i32 @strlen(i8* %2)
%34 = call i32 @memset(i8* %2, i32 0, i32 %33)
%35 = load i32, i32* @stdin
%36 = call i64 @fgets(i8* %2, i32 500, i32 %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2)
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 0)
%41 = call i32 @strlen(i8* %2)
%42 = call i32 @memset(i8* %2, i32 0, i32 %41)
br label %43
43: ; preds = %38, %30, %22, %14, %6, %0
ret i32 0
}