#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 not 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    11b5 <parse_int+0x95>
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11ae <parse_int+0x8e>
mov    -0x1c(%rbp),%esi
lea    0xe7e(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b5 <parse_int+0x95>
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
mov    $0x1,%ecx
test   %eax,%eax
jg     1162 <parse_int+0x42>
lea    0xe9e(%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 = [27 x i8] c"argv[%d] is not 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 %31
23: ; preds = %15
%24 = load i32*, i32** %6
%25 = load i32, i32* %24
%26 = icmp sle 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 ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %28)
store i32 0, i32* %4
br label %31
30: ; preds = %23
store i32 1, i32* %4
br label %31
31: ; preds = %30, %27, %20
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@.str = [27 x i8] c"argv[%d] is not a number \0A\00"
@.str.1 = [27 x i8] c"argv[%d] is not 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 %14, label %9
9: ; preds = %3
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = icmp slt i32 %6, 1
br i1 %13, label %14, label %17
14: ; preds = %12, %3, %9
%15 = 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 ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %12 ]
%16 = tail call i32 @printf(i8* %15, i32 %2)
br label %17
17: ; preds = %14, %12
%18 = phi i32 [ 1, %12 ], [ 0, %14 ]
ret i32 %18
}