#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 *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char *);
int main() {
  char *repstext = getenv("reps");
  int reps = repstext ? atoi(repstext) : 10;
  char *msg = getenv("msg");
  if (!msg)
    msg = "Hello.";
  for (int i = 0; i < reps; i++)
    printf("%s\n", msg);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116b <main+0x3b>
mov    -0x10(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    1178 <main+0x48>
mov    $0xa,%eax
mov    %eax,-0x28(%rbp)
jmp    1178 <main+0x48>
mov    -0x28(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    0xe80(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a4 <main+0x74>
lea    0xe69(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d5 <main+0xa5>
mov    -0x20(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ab <main+0x7b>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
lea    0xec4(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1152 <main+0x22>
mov    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebx
jmp    1157 <main+0x27>
mov    $0xa,%ebx
lea    0xea7(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe9c(%rip),%r14
cmovne %rax,%r14
test   %ebx,%ebx
jle    1190 <main+0x60>
lea    0xe94(%rip),%r15
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
add    $0xffffffff,%ebx
jne    1180 <main+0x50>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"reps\00"
@.str.1 = [4 x i8] c"msg\00"
@.str.2 = [7 x i8] c"Hello.\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
%6 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %2
%7 = load i8*, i8** %2
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = load i8*, i8** %2
%11 = call i32 @atoi(i8* %10)
br label %13
12: ; preds = %0
br label %13
13: ; preds = %12, %9
%14 = phi i32 [ %11, %9 ], [ 10, %12 ]
store i32 %14, i32* %3
%15 = call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %19, label %18
18: ; preds = %13
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %4
br label %19
19: ; preds = %18, %13
store i32 0, i32* %5
br label %20
20: ; preds = %27, %19
%21 = load i32, i32* %5
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %30
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24
%28 = load i32, i32* %5
%29 = add nsw i32 %28, 1
store i32 %29, i32* %5
br label %20
30: ; preds = %20
%31 = load i32, i32* %1
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"reps\00"
@.str.1 = [4 x i8] c"msg\00"
@.str.2 = [7 x i8] c"Hello.\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i8* %1, null
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 @atoi(i8* %1)
br label %5
5: ; preds = %0, %3
%6 = phi i32 [ %4, %3 ], [ 10, %0 ]
%7 = tail call i8* @getenv(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %7
%10 = icmp sgt i32 %6, 0
br i1 %10, label %12, label %11
11: ; preds = %12, %5
ret i32 0
12: ; preds = %5, %12
%13 = phi i32 [ %15, %12 ], [ 0, %5 ]
%14 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%15 = add nuw nsw i32 %13, 1
%16 = icmp eq i32 %15, %6
br i1 %16, label %11, label %12
}