#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 */
typedef int /*<<< orphan*/ line;

/* Variables and functions */
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int main(int argc, char const *argv[]) {
  printf("Hello world.\n");
  char line[100];
  int count = 1;
  while (fgets(line, sizeof(line), stdin)) {
    fprintf(stderr, "input line=>%d\n", count++);
    if (count > 3)
      break;
  }
  printf("Exiting now\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x84(%rbp)
lea    -0x80(%rbp),%rdi
mov    0x2e7e(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11bd <main+0x8d>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x84(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x84(%rbp)
lea    0xe6d(%rip),%rsi
call   1050 <fprintf@plt>
cmpl   $0x3,-0x84(%rbp)
jle    11b8 <main+0x88>
jmp    11bd <main+0x8d>
jmp    115f <main+0x2f>
lea    0xe5a(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xed2(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e9e(%rip),%rbx
mov    (%rbx),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11c9 <main+0x99>
mov    0x2e73(%rip),%r14
mov    (%r14),%edi
lea    0xe91(%rip),%rsi
mov    $0x1,%edx
call   1050 <fprintf@plt>
mov    (%rbx),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11c9 <main+0x99>
mov    (%r14),%edi
lea    0xe69(%rip),%rsi
mov    $0x2,%edx
call   1050 <fprintf@plt>
mov    (%rbx),%edx
mov    %rsp,%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     11c9 <main+0x99>
mov    (%r14),%edi
lea    0xe41(%rip),%rsi
mov    $0x3,%edx
call   1050 <fprintf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Hello world.\0A\00"
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"input line=>%d\0A\00"
@.str.2 = [13 x i8] c"Exiting now\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %7
br label %9
9: ; preds = %22, %2
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%11 = load i32, i32* @stdin
%12 = call i64 @fgets(i8* %10, i32 100, i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i32, i32* %7
%17 = add nsw i32 %16, 1
store i32 %17, i32* %7
%18 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%19 = load i32, i32* %7
%20 = icmp sgt i32 %19, 3
br i1 %20, label %21, label %22
21: ; preds = %14
br label %23
22: ; preds = %14
br label %9
23: ; preds = %21, %9
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@stdin = global i32 0
@stderr = global i32 0
@.str.1 = [16 x i8] c"input line=>%d\0A\00"
@str = [13 x i8] c"Hello world.\00"
@str.3 = [12 x i8] c"Exiting now\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i64 @fgets(i8* %5, i32 100, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 1)
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %5, i32 100, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 2)
%18 = load i32, i32* @stdin
%19 = call i64 @fgets(i8* %5, i32 100, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %15
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 3)
br label %24
24: ; preds = %21, %15, %9, %2
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.3, i64 0, i64 0))
ret i32 0
}