#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*/ close_elf_object();
int /*<<< orphan*/ create_elf_object(char *);
int /*<<< orphan*/ save_elf_section_bindata(unsigned char *, unsigned char *);
int argparse_elfcmd(int num_args, char **arg_ptr) {
  char *cur_cmd;
  if (arg_ptr[0][1] == 'e' && num_args--) {
    cur_cmd = &arg_ptr[0][2];
    arg_ptr++;
    switch (*cur_cmd++) {
    case 'o':
      if (num_args < 1) {
        return 0;
      }
      if (create_elf_object(arg_ptr[0])) {
        return 2;
      }
      break;
    case 's':
      if (num_args < 2) {
        return 0;
      }
      if (save_elf_section_bindata((unsigned char *)arg_ptr[0],
                                   (unsigned char *)arg_ptr[1])) {
        return 3;
      }
      break;
    case 'c':
      if (close_elf_object()) {
        return 1;
      }
      break;
    default:
      return 0;
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<argparse_elfcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x65,%eax
jne    1279 <argparse_elfcmd+0x149>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1279 <argparse_elfcmd+0x149>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
add    $0x2,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
movsbl (%rax),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x63,%eax
je     1247 <argparse_elfcmd+0x117>
jmp    11a5 <argparse_elfcmd+0x75>
mov    -0x1c(%rbp),%eax
sub    $0x6f,%eax
je     11c7 <argparse_elfcmd+0x97>
jmp    11b6 <argparse_elfcmd+0x86>
mov    -0x1c(%rbp),%eax
sub    $0x73,%eax
je     1203 <argparse_elfcmd+0xd3>
jmp    1268 <argparse_elfcmd+0x138>
cmpl   $0x1,-0x8(%rbp)
jge    11dd <argparse_elfcmd+0xad>
movl   $0x0,-0x4(%rbp)
jmp    1280 <argparse_elfcmd+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <create_elf_object@plt>
cmp    $0x0,%eax
je     11fe <argparse_elfcmd+0xce>
movl   $0x2,-0x4(%rbp)
jmp    1280 <argparse_elfcmd+0x150>
jmp    1274 <argparse_elfcmd+0x144>
cmpl   $0x2,-0x8(%rbp)
jge    1219 <argparse_elfcmd+0xe9>
movl   $0x0,-0x4(%rbp)
jmp    1280 <argparse_elfcmd+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <save_elf_section_bindata@plt>
cmp    $0x0,%eax
je     1242 <argparse_elfcmd+0x112>
movl   $0x3,-0x4(%rbp)
jmp    1280 <argparse_elfcmd+0x150>
jmp    1274 <argparse_elfcmd+0x144>
mov    $0x0,%al
call   1040 <close_elf_object@plt>
cmp    $0x0,%eax
je     1263 <argparse_elfcmd+0x133>
movl   $0x1,-0x4(%rbp)
jmp    1280 <argparse_elfcmd+0x150>
jmp    1274 <argparse_elfcmd+0x144>
movl   $0x0,-0x4(%rbp)
jmp    1280 <argparse_elfcmd+0x150>
jmp    1279 <argparse_elfcmd+0x149>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<argparse_elfcmd>:
push   %rax
test   %edi,%edi
je     119f <argparse_elfcmd+0x6f>
mov    (%rsi),%rax
cmpb   $0x65,0x1(%rax)
jne    119f <argparse_elfcmd+0x6f>
movsbl 0x2(%rax),%ecx
cmp    $0x63,%ecx
je     116e <argparse_elfcmd+0x3e>
xor    %eax,%eax
cmp    $0x73,%ecx
je     1182 <argparse_elfcmd+0x52>
cmp    $0x6f,%ecx
jne    1180 <argparse_elfcmd+0x50>
cmp    $0x2,%edi
jl     1180 <argparse_elfcmd+0x50>
mov    0x8(%rsi),%rdi
call   1050 <create_elf_object@plt>
mov    %eax,%ecx
mov    $0x2,%eax
test   %ecx,%ecx
jne    1180 <argparse_elfcmd+0x50>
jmp    119f <argparse_elfcmd+0x6f>
xor    %eax,%eax
call   1040 <close_elf_object@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
je     119f <argparse_elfcmd+0x6f>
pop    %rcx
ret
cmp    $0x3,%edi
jl     1180 <argparse_elfcmd+0x50>
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
call   1030 <save_elf_section_bindata@plt>
mov    %eax,%ecx
mov    $0x3,%eax
test   %ecx,%ecx
jne    1180 <argparse_elfcmd+0x50>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
define i32 @argparse_elfcmd(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i8**, i8*** %5
%8 = getelementptr inbounds i8*, i8** %7, i64 0
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp eq i32 %12, 101
br i1 %13, label %14, label %63
14: ; preds = %2
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %63
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 0
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 2
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i32 1
store i8** %24, i8*** %5
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i32 1
store i8* %26, i8** %6
%27 = load i8, i8* %25
%28 = sext i8 %27 to i32
switch i32 %28, label %61 [
i32 111, label %29
i32 115, label %41
i32 99, label %56
]
29: ; preds = %18
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 1
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 0, i32* %3
br label %64
33: ; preds = %29
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 @create_elf_object(i8* %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %33
store i32 2, i32* %3
br label %64
40: ; preds = %33
br label %62
41: ; preds = %18
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 2
br i1 %43, label %44, label %45
44: ; preds = %41
store i32 0, i32* %3
br label %64
45: ; preds = %41
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 0
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 @save_elf_section_bindata(i8* %48, i8* %51)
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %55
54: ; preds = %45
store i32 3, i32* %3
br label %64
55: ; preds = %45
br label %62
56: ; preds = %18
%57 = call i32 (...) @close_elf_object()
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %56
store i32 1, i32* %3
br label %64
60: ; preds = %56
br label %62
61: ; preds = %18
store i32 0, i32* %3
br label %64
62: ; preds = %60, %55, %40
br label %63
63: ; preds = %62, %14, %2
store i32 0, i32* %3
br label %64
64: ; preds = %63, %61, %59, %54, %44, %39, %32
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
define i32 @argparse_elfcmd(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = getelementptr inbounds i8, i8* %3, i64 1
%5 = load i8, i8* %4
%6 = icmp ne i8 %5, 101
%7 = icmp eq i32 %0, 0
%8 = or i1 %7, %6
br i1 %8, label %31, label %9
9: ; preds = %2
%10 = getelementptr inbounds i8, i8* %3, i64 2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8, i8* %10
%13 = sext i8 %12 to i32
switch i32 %13, label %32 [
i32 111, label %14
i32 115, label %20
i32 99, label %28
]
14: ; preds = %9
%15 = icmp slt i32 %0, 2
br i1 %15, label %32, label %16
16: ; preds = %14
%17 = load i8*, i8** %11
%18 = tail call i32 @create_elf_object(i8* %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %31, label %32
20: ; preds = %9
%21 = icmp slt i32 %0, 3
br i1 %21, label %32, label %22
22: ; preds = %20
%23 = load i8*, i8** %11
%24 = getelementptr inbounds i8*, i8** %1, i64 2
%25 = load i8*, i8** %24
%26 = tail call i32 @save_elf_section_bindata(i8* %23, i8* %25)
%27 = icmp eq i32 %26, 0
br i1 %27, label %31, label %32
28: ; preds = %9
%29 = tail call i32 (...) @close_elf_object()
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %16, %22, %28, %2
br label %32
32: ; preds = %9, %28, %22, %20, %16, %14, %31
%33 = phi i32 [ 0, %31 ], [ 0, %14 ], [ 2, %16 ], [ 0, %20 ], [ 3, %22 ], [ 1, %28 ], [ 0, %9 ]
ret i32 %33
}