#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 atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main() {
  int in = 0;
  char s[5];
  printf("Practice 04\n");
  do {
    fputs("in > ", stdout);
    fgets(s, 5, stdin);
    in = atoi(s);
    printf("in=%d\n", in);
  } while (in > 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e6d(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
call   1040 <fputs@plt>
lea    -0xd(%rbp),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1050 <fgets@plt>
lea    -0xd(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
jg     1164 <main+0x24>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeab(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e6a(%rip),%r12
lea    0xe8b(%rip),%r14
mov    0x2e6c(%rip),%r13
lea    0x3(%rsp),%rbx
lea    0xe7e(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    (%r12),%esi
mov    %r14,%rdi
call   1050 <fputs@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1070 <atoi@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jg     1190 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Practice 04\0A\00"
@.str.1 = [6 x i8] c"in > \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [7 x i8] c"in=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i8]
store i32 0, i32* %1
store i32 0, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %5
5: ; preds = %15, %0
%6 = load i32, i32* @stdout
%7 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%9 = load i32, i32* @stdin
%10 = call i32 @fgets(i8* %8, i32 5, i32 %9)
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %5
%16 = load i32, i32* %2
%17 = icmp sgt i32 %16, 0
br i1 %17, label %5, label %18
18: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c"in > \00"
@stdout = global i32 0
@stdin = global i32 0
@.str.2 = [7 x i8] c"in=%d\0A\00"
@str = [12 x i8] c"Practice 04\00"
define i32 @main() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %4
4: ; preds = %4, %0
%5 = load i32, i32* @stdout
%6 = call i32 @fputs(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = load i32, i32* @stdin
%8 = call i32 @fgets(i8* %2, i32 5, i32 %7)
%9 = call i32 @atoi(i8* %2)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %9)
%11 = icmp sgt i32 %9, 0
br i1 %11, label %4, label %12
12: ; preds = %4
ret i32 0
}