#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__ is_valid_input(int);
int /*<<< orphan*/ printGreeting();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ scanf(char *, int *);
int launch_shell(int memory[]) {
  printGreeting();
  int user_input = 0;
  int i = 0;
  while ((user_input != -99999) && (i < 100)) {
    printf("%02d ? ", i);
    scanf("%d", &user_input);
    if (is_valid_input(user_input)) {
      memory[i] = user_input;
      ++i;
    } else if (user_input == -99999) {
      ;
    } else {
      puts("*** ERROR: acceptable range is from -9999 to 9999 ***");
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<launch_shell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <printGreeting@plt>
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0xfffe7961,-0xc(%rbp)
mov    %al,-0x11(%rbp)
je     118d <launch_shell+0x3d>
cmpl   $0x64,-0x10(%rbp)
setl   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    119d <launch_shell+0x4d>
jmp    1212 <launch_shell+0xc2>
mov    -0x10(%rbp),%esi
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0xc(%rbp),%edi
call   1070 <is_valid_input@plt>
cmp    $0x0,%rax
je     11ea <launch_shell+0x9a>
mov    -0xc(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    120d <launch_shell+0xbd>
cmpl   $0xfffe7961,-0xc(%rbp)
jne    11fc <launch_shell+0xac>
jmp    1208 <launch_shell+0xb8>
lea    0xe08(%rip),%rdi
call   1040 <puts@plt>
jmp    120d <launch_shell+0xbd>
jmp    1171 <launch_shell+0x21>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<launch_shell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printGreeting@plt>
movl   $0x0,0x4(%rsp)
lea    0xe8a(%rip),%r15
lea    0xe8b(%rip),%r12
lea    0x4(%rsp),%r13
lea    0xe82(%rip),%rbp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %ebx,%esi
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1060 <scanf@plt>
mov    0x4(%rsp),%edi
call   1070 <is_valid_input@plt>
mov    0x4(%rsp),%ecx
test   %rax,%rax
je     11d0 <launch_shell+0x80>
movslq %ebx,%rax
mov    %ecx,(%r14,%rax,4)
add    $0x1,%ebx
cmp    $0xfffe7961,%ecx
jne    11ec <launch_shell+0x9c>
jmp    11f1 <launch_shell+0xa1>
nopl   0x0(%rax,%rax,1)
cmp    $0xfffe7961,%ecx
je     11f1 <launch_shell+0xa1>
mov    %rbp,%rdi
call   1040 <puts@plt>
mov    0x4(%rsp),%ecx
cmp    $0xfffe7961,%ecx
je     11f1 <launch_shell+0xa1>
cmp    $0x64,%ebx
jl     1190 <launch_shell+0x40>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%02d ? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"*** ERROR: acceptable range is from -9999 to 9999 ***\00"
define i32 @launch_shell(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32
store i32* %0, i32** %2
%5 = call i32 (...) @printGreeting()
store i32 0, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %36, %1
%7 = load i32, i32* %3
%8 = icmp ne i32 %7, -99999
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 100
br label %12
12: ; preds = %9, %6
%13 = phi i1 [ false, %6 ], [ %11, %9 ]
br i1 %13, label %14, label %37
14: ; preds = %12
%15 = load i32, i32* %4
%16 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%18 = load i32, i32* %3
%19 = call i64 @is_valid_input(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = load i32, i32* %3
%23 = load i32*, i32** %2
%24 = load i32, i32* %4
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
store i32 %22, i32* %26
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %36
29: ; preds = %14
%30 = load i32, i32* %3
%31 = icmp eq i32 %30, -99999
br i1 %31, label %32, label %33
32: ; preds = %29
br label %35
33: ; preds = %29
%34 = call i32 @puts(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %32
br label %36
36: ; preds = %35, %21
br label %6
37: ; preds = %12
%38 = load i32, i32* %4
ret i32 %38
}

LLVM IR (-O2):
@.str = [8 x i8] c"%02d ? \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [54 x i8] c"*** ERROR: acceptable range is from -9999 to 9999 ***\00"
define i32 @launch_shell(i32* nocapture writeonly %0) {
%2 = alloca i32
%3 = tail call i32 (...) @printGreeting()
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
br label %5
5: ; preds = %1, %22
%6 = phi i32 [ %24, %22 ], [ 0, %1 ]
%7 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = load i32, i32* %2
%10 = call i64 @is_valid_input(i32 %9)
%11 = icmp eq i64 %10, 0
%12 = load i32, i32* %2
br i1 %11, label %17, label %13
13: ; preds = %5
%14 = sext i32 %6 to i64
%15 = getelementptr inbounds i32, i32* %0, i64 %14
store i32 %12, i32* %15
%16 = add nsw i32 %6, 1
br label %22
17: ; preds = %5
%18 = icmp eq i32 %12, -99999
br i1 %18, label %28, label %19
19: ; preds = %17
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.2, i64 0, i64 0))
%21 = load i32, i32* %2
br label %22
22: ; preds = %19, %13
%23 = phi i32 [ %12, %13 ], [ %21, %19 ]
%24 = phi i32 [ %16, %13 ], [ %6, %19 ]
%25 = icmp ne i32 %23, -99999
%26 = icmp slt i32 %24, 100
%27 = select i1 %25, i1 %26, i1 false
br i1 %27, label %5, label %28
28: ; preds = %17, %22
%29 = phi i32 [ %24, %22 ], [ %6, %17 ]
ret i32 %29
}