#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 /*<<< orphan*/ printf(char *, int);
int strtol(char *, char **, int);
int parse_int(char *str, int *n, int i) {
  char *endptr;
  *n = strtol(str, &endptr, 10);
  if ((endptr == str) || (*endptr != '\0')) {
    printf("argv[%d] is not a number \n", i);
    return 0;
  } else if (*n < 0) {
    printf("argv[%d] is negative \n", i);
    return 0;
  } else if ((*n == 0) && (i != 3)) {
    printf("argv[%d] should be positive \n", i);
    return 0;
  } else
    return 1;
}


x86 assembly (clang, -O0):
<parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rax
cmp    -0x10(%rbp),%rax
je     116b <parse_int+0x4b>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1186 <parse_int+0x66>
mov    -0x1c(%rbp),%esi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <parse_int+0xc7>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jge    11ae <parse_int+0x8e>
mov    -0x1c(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <parse_int+0xc7>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    11e0 <parse_int+0xc0>
cmpl   $0x3,-0x1c(%rbp)
je     11e0 <parse_int+0xc0>
mov    -0x1c(%rbp),%esi
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <parse_int+0xc7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_int>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
lea    0x8(%rsp),%rsi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %eax,(%rbx)
mov    0x8(%rsp),%rcx
lea    0xeb2(%rip),%rdi
cmp    %rbp,%rcx
je     1158 <parse_int+0x38>
cmpb   $0x0,(%rcx)
je     116d <parse_int+0x4d>
mov    %r14d,%esi
call   1030 <printf@plt>
xor    %ecx,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %eax,%eax
js     1189 <parse_int+0x69>
mov    $0x1,%ecx
cmp    $0x3,%r14d
je     1162 <parse_int+0x42>
test   %eax,%eax
jne    1162 <parse_int+0x42>
lea    0xeab(%rip),%rdi
jmp    1158 <parse_int+0x38>
lea    0xe8b(%rip),%rdi
jmp    1158 <parse_int+0x38>

LLVM IR (-O0):
@.str = [27 x i8] c"argv[%d] is not a number \0A\00"
@.str.1 = [23 x i8] c"argv[%d] is negative \0A\00"
@.str.2 = [30 x i8] c"argv[%d] should be positive \0A\00"
define i32 @parse_int(i8* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i8*, i8** %5
%10 = call i32 @strtol(i8* %9, i8** %8, i32 10)
%11 = load i32*, i32** %6
store i32 %10, i32* %11
%12 = load i8*, i8** %8
%13 = load i8*, i8** %5
%14 = icmp eq i8* %12, %13
br i1 %14, label %20, label %15
15: ; preds = %3
%16 = load i8*, i8** %8
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %15, %3
%21 = load i32, i32* %7
%22 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %21)
store i32 0, i32* %4
br label %41
23: ; preds = %15
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* %7
%29 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 0, i32* %4
br label %41
30: ; preds = %23
%31 = load i32*, i32** %6
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = load i32, i32* %7
%36 = icmp ne i32 %35, 3
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %7
%39 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %38)
store i32 0, i32* %4
br label %41
40: ; preds = %34, %30
store i32 1, i32* %4
br label %41
41: ; preds = %40, %37, %27, %20
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@.str = [27 x i8] c"argv[%d] is not a number \0A\00"
@.str.1 = [23 x i8] c"argv[%d] is negative \0A\00"
@.str.2 = [30 x i8] c"argv[%d] should be positive \0A\00"
define i32 @parse_int(i8* %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtol(i8* %0, i8** %4, i32 10)
store i32 %6, i32* %1
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, %0
br i1 %8, label %18, label %9
9: ; preds = %3
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = icmp slt i32 %6, 0
br i1 %13, label %18, label %14
14: ; preds = %12
%15 = icmp eq i32 %6, 0
%16 = icmp ne i32 %2, 3
%17 = and i1 %16, %15
br i1 %17, label %18, label %21
18: ; preds = %14, %12, %3, %9
%19 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %9 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), %12 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %14 ]
%20 = tail call i32 @printf(i8* %19, i32 %2)
br label %21
21: ; preds = %18, %14
%22 = phi i32 [ 1, %14 ], [ 0, %18 ]
ret i32 %22
}