#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*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int get_limit(int argc, char *argv[]) {
  int limit;
  if (argc > 1) {
    int limit_arg = atoi(argv[1]);
    if (limit_arg > 0) {
      limit = limit_arg;
    } else {
      limit = -1;
    }
  } else {
    int user_input;
    printf(
        "Please enter an integer above zero (pro tip: don't enter letters): ");
    scanf("%d", &user_input);
    if (user_input > 0) {
      limit = user_input;
    } else {
      limit = -2;
    }
  }
  return limit;
}


x86 assembly (clang, -O0):
<get_limit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x4(%rbp)
jle    117a <get_limit+0x4a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    116e <get_limit+0x3e>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <get_limit+0x45>
movl   $0xffffffff,-0x14(%rbp)
jmp    11b7 <get_limit+0x87>
lea    0xe7f(%rip),%rdi
call   1030 <printf@plt>
lea    0xeb7(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    11ab <get_limit+0x7b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11b2 <get_limit+0x82>
movl   $0xfffffffe,-0x14(%rbp)
jmp    11b7 <get_limit+0x87>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_limit>:
push   %rax
cmp    $0x2,%edi
jl     114a <get_limit+0x1a>
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
test   %eax,%eax
mov    $0xffffffff,%eax
jmp    1172 <get_limit+0x42>
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
lea    0xee7(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
mov    $0xfffffffe,%eax
cmovg  %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [68 x i8] c"Please enter an integer above zero (pro tip: don't enter letters): \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @get_limit(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %21
10: ; preds = %2
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @atoi(i8* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = load i32, i32* %6
store i32 %18, i32* %5
br label %20
19: ; preds = %10
store i32 -1, i32* %5
br label %20
20: ; preds = %19, %17
br label %30
21: ; preds = %2
%22 = call i32 @printf(i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%24 = load i32, i32* %7
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %21
%27 = load i32, i32* %7
store i32 %27, i32* %5
br label %29
28: ; preds = %21
store i32 -2, i32* %5
br label %29
29: ; preds = %28, %26
br label %30
30: ; preds = %29, %20
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@.str = [68 x i8] c"Please enter an integer above zero (pro tip: don't enter letters): \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @get_limit(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = icmp sgt i32 %0, 1
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = icmp sgt i32 %8, 0
%10 = select i1 %9, i32 %8, i32 -1
br label %18
11: ; preds = %2
%12 = bitcast i32* %3 to i8*
%13 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([68 x i8], [68 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
%17 = select i1 %16, i32 %15, i32 -2
br label %18
18: ; preds = %11, %5
%19 = phi i32 [ %10, %5 ], [ %17, %11 ]
ret i32 %19
}