#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*/ buf;

/* Variables and functions */
int EXIT_SUCCESS;
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ gimme(size_t const);
int /*<<< orphan*/ stdin;
size_t strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int loop(void) {
  char buf[1000];
  while (fgets(buf, sizeof(buf), stdin)) {
    const size_t target = strtoul(buf, NULL, 0);
    if (target)
      gimme(target);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x400,%rsp
lea    -0x3f0(%rbp),%rdi
mov    0x2e9f(%rip),%rax
mov    (%rax),%edx
mov    $0x3e8,%esi
call   1030 <fgets@plt>
cmp    $0x0,%rax
je     1197 <loop+0x67>
lea    -0x3f0(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
mov    %rax,-0x3f8(%rbp)
cmpq   $0x0,-0x3f8(%rbp)
je     1192 <loop+0x62>
mov    -0x3f8(%rbp),%rdi
call   1050 <gimme@plt>
jmp    113b <loop+0xb>
mov    0x2e3a(%rip),%rax
mov    (%rax),%eax
add    $0x400,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loop>:
push   %r14
push   %rbx
sub    $0x3e8,%rsp
mov    0x2ea7(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rdi
mov    $0x3e8,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     1190 <loop+0x60>
mov    %rsp,%rbx
jmp    1175 <loop+0x45>
nopl   0x0(%rax,%rax,1)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1030 <fgets@plt>
test   %rax,%rax
je     1190 <loop+0x60>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtoul@plt>
test   %rax,%rax
je     1160 <loop+0x30>
mov    %rax,%rdi
call   1050 <gimme@plt>
jmp    1160 <loop+0x30>
mov    0x2e41(%rip),%rax
mov    (%rax),%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @loop() {
%1 = alloca [1000 x i8]
%2 = alloca i64
br label %3
3: ; preds = %16, %0
%4 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i64 @fgets(i8* %4, i32 1000, i32 %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %3
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%10 = call i64 @strtoul(i8* %9, i32* null, i32 0)
store i64 %10, i64* %2
%11 = load i64, i64* %2
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i64, i64* %2
%15 = call i32 @gimme(i64 %14)
br label %16
16: ; preds = %13, %8
br label %3
17: ; preds = %3
%18 = load i32, i32* @EXIT_SUCCESS
ret i32 %18
}

LLVM IR (-O2):
@stdin = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @loop() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdin
%4 = call i64 @fgets(i8* %2, i32 1000, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %0, %11
%7 = call i64 @strtoul(i8* nocapture %2, i32* null, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = call i32 @gimme(i64 %7)
br label %11
11: ; preds = %9, %6
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %2, i32 1000, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %11, %0
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
}