#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 */
char *get_argv(int, char **, int, char *);
int str_2_int(char *, int *, int /*<<< orphan*/);
int opt_parse_int(int i, int argc, char *argv[], int *p, int default_val) {
  char *arg = get_argv(argc, argv, i, "int");
  ;
  if (arg) {
    int b_err = str_2_int(arg, p, 0);
    return (++i) * (b_err ? -1 : 1);
  } else {
    *p = default_val;
    return i;
  }
}


x86 assembly (clang, -O0):
<opt_parse_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%edx
lea    0xeb5(%rip),%rcx
call   1030 <get_argv@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1198 <opt_parse_int+0x78>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1040 <str_2_int@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x34(%rbp),%esi
mov    $0x1,%ecx
mov    $0xffffffff,%edx
cmp    $0x0,%esi
cmovne %edx,%ecx
imul   %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    11a7 <opt_parse_int+0x87>
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<opt_parse_int>:
push   %rbp
push   %r14
push   %rbx
mov    %r8d,%ebp
mov    %rcx,%r14
mov    %edi,%ebx
lea    0xecd(%rip),%rcx
mov    %esi,%edi
mov    %rdx,%rsi
mov    %ebx,%edx
call   1030 <get_argv@plt>
test   %rax,%rax
je     115d <opt_parse_int+0x3d>
mov    %rax,%rdi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <str_2_int@plt>
lea    0x1(%rbx),%ecx
test   %eax,%eax
not    %ebx
cmove  %ecx,%ebx
jmp    1160 <opt_parse_int+0x40>
mov    %ebp,(%r14)
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"int\00"
define i32 @opt_parse_int(i32 %0, i32 %1, i8** %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i8** %2, i8*** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%14 = load i32, i32* %8
%15 = load i8**, i8*** %9
%16 = load i32, i32* %7
%17 = call i8* @get_argv(i32 %14, i8** %15, i32 %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %17, i8** %12
%18 = load i8*, i8** %12
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %31
20: ; preds = %5
%21 = load i8*, i8** %12
%22 = load i32*, i32** %10
%23 = call i32 @str_2_int(i8* %21, i32* %22, i32 0)
store i32 %23, i32* %13
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 1
store i32 %25, i32* %7
%26 = load i32, i32* %13
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 -1, i32 1
%30 = mul nsw i32 %25, %29
store i32 %30, i32* %6
br label %35
31: ; preds = %5
%32 = load i32, i32* %11
%33 = load i32*, i32** %10
store i32 %32, i32* %33
%34 = load i32, i32* %7
store i32 %34, i32* %6
br label %35
35: ; preds = %31, %20
%36 = load i32, i32* %6
ret i32 %36
}

LLVM IR (-O2):
@.str = [4 x i8] c"int\00"
define i32 @opt_parse_int(i32 %0, i32 %1, i8** %2, i32* %3, i32 %4) {
%6 = tail call i8* @get_argv(i32 %1, i8** %2, i32 %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i8* %6, null
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = tail call i32 @str_2_int(i8* %6, i32* %3, i32 0)
%10 = add nsw i32 %0, 1
%11 = icmp eq i32 %9, 0
%12 = xor i32 %0, -1
%13 = select i1 %11, i32 %10, i32 %12
br label %15
14: ; preds = %5
store i32 %4, i32* %3
br label %15
15: ; preds = %14, %8
%16 = phi i32 [ %13, %8 ], [ %0, %14 ]
ret i32 %16
}