#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char const *);
unsigned long strtoul(char *, char **, int /*<<< orphan*/);
int ul_arg(int argc, char *argv[], int *i, const char *arg,
           unsigned long *result) {
  char *endpt;
  if (i == NULL || result == NULL) {
    return 0;
  }
  if (!strcmp(argv[*i], arg)) {
    if (*i >= argc - 1) {
      fprintf(stderr, "binmat-test: Error: missing argument to %s\n", arg);
      exit(1);
    }
    (*i)++;
    *result = strtoul(argv[*i], &endpt, 0);
    if (*endpt) {
      fprintf(stderr, "binmat-test: Error converting argument to %s\n", arg);
      exit(1);
    }
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ul_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1171 <ul_arg+0x31>
cmpq   $0x0,-0x28(%rbp)
jne    117d <ul_arg+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    1247 <ul_arg+0x107>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%eax
jne    1240 <ul_arg+0x100>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jl     11d5 <ul_arg+0x95>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe3a(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x30(%rbp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1234 <ul_arg+0xf4>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe07(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x1,-0x4(%rbp)
jmp    1247 <ul_arg+0x107>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ul_arg>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
test   %rdx,%rdx
je     11b0 <ul_arg+0x70>
mov    %r8,%r15
test   %r8,%r8
je     11b0 <ul_arg+0x70>
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %edi,%r13d
movslq (%rdx),%r14
mov    (%rsi,%r14,8),%rdi
mov    %rcx,0x8(%rsp)
mov    %rcx,%rsi
call   1030 <strcmp@plt>
test   %eax,%eax
jne    11b0 <ul_arg+0x70>
add    $0xffffffff,%r13d
cmp    %r13d,%r14d
jge    11c1 <ul_arg+0x81>
lea    0x1(%r14),%rax
mov    %eax,(%rbx)
mov    0x8(%r12,%r14,8),%rdi
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <strtoul@plt>
mov    %rax,(%r15)
mov    0x10(%rsp),%rax
mov    $0x1,%ebp
cmpb   $0x0,(%rax)
jne    11d3 <ul_arg+0x93>
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
jmp    11e3 <ul_arg+0xa3>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
mov    0x8(%rsp),%rdx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [44 x i8] c"binmat-test: Error: missing argument to %s\0A\00"
@.str.1 = [46 x i8] c"binmat-test: Error converting argument to %s\0A\00"
define i32 @ul_arg(i32 %0, i8** %1, i32* %2, i8* %3, i64* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i64*
%12 = alloca i8*
store i32 %0, i32* %7
store i8** %1, i8*** %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i64* %4, i64** %11
%13 = load i32*, i32** %9
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %5
%16 = load i64*, i64** %11
%17 = icmp eq i64* %16, null
br i1 %17, label %18, label %19
18: ; preds = %15, %5
store i32 0, i32* %6
br label %62
19: ; preds = %15
%20 = load i8**, i8*** %8
%21 = load i32*, i32** %9
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8*, i8** %20, i64 %23
%25 = load i8*, i8** %24
%26 = load i8*, i8** %10
%27 = call i32 @strcmp(i8* %25, i8* %26)
%28 = icmp ne i32 %27, 0
br i1 %28, label %61, label %29
29: ; preds = %19
%30 = load i32*, i32** %9
%31 = load i32, i32* %30
%32 = load i32, i32* %7
%33 = sub nsw i32 %32, 1
%34 = icmp sge i32 %31, %33
br i1 %34, label %35, label %40
35: ; preds = %29
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %10
%38 = call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = load i32*, i32** %9
%42 = load i32, i32* %41
%43 = add nsw i32 %42, 1
store i32 %43, i32* %41
%44 = load i8**, i8*** %8
%45 = load i32*, i32** %9
%46 = load i32, i32* %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %44, i64 %47
%49 = load i8*, i8** %48
%50 = call i64 @strtoul(i8* %49, i8** %12, i32 0)
%51 = load i64*, i64** %11
store i64 %50, i64* %51
%52 = load i8*, i8** %12
%53 = load i8, i8* %52
%54 = icmp ne i8 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %40
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %10
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %57)
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %40
store i32 1, i32* %6
br label %62
61: ; preds = %19
store i32 0, i32* %6
br label %62
62: ; preds = %61, %60, %18
%63 = load i32, i32* %6
ret i32 %63
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [44 x i8] c"binmat-test: Error: missing argument to %s\0A\00"
@.str.1 = [46 x i8] c"binmat-test: Error converting argument to %s\0A\00"
define i32 @ul_arg(i32 %0, i8** nocapture %1, i32* %2, i8* %3, i64* writeonly %4) {
%6 = alloca i8*
%7 = bitcast i8** %6 to i8*
%8 = icmp eq i32* %2, null
%9 = icmp eq i64* %4, null
%10 = or i1 %8, %9
br i1 %10, label %38, label %11
11: ; preds = %5
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %1, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @strcmp(i8* dereferenceable(1) %15, i8* dereferenceable(1) %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %38
18: ; preds = %11
%19 = add nsw i32 %0, -1
%20 = icmp slt i32 %12, %19
br i1 %20, label %25, label %21
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %3)
%24 = tail call i32 @exit(i32 1)
unreachable
25: ; preds = %18
%26 = add nsw i32 %12, 1
store i32 %26, i32* %2
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %1, i64 %27
%29 = load i8*, i8** %28
%30 = call i64 @strtoul(i8* %29, i8** %6, i32 0)
store i64 %30, i64* %4
%31 = load i8*, i8** %6
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %25
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%37 = tail call i32 @exit(i32 1)
unreachable
38: ; preds = %11, %25, %5
%39 = phi i32 [ 0, %5 ], [ 1, %25 ], [ 0, %11 ]
ret i32 %39
}