#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 atoi(char *);
int /*<<< orphan*/ print_usage();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int parse_opt(int argc, char **argv, int *pnum, int *pauto) {
  *pauto = 0;
  if (argc == 2) {
    *pnum = atoi(argv[1]);
    if (*pnum <= 0) {
      printf("invalid argument %s\n", argv[1]);
      return 2;
    }
  } else if (argc == 3) {
    *pnum = atoi(argv[1]);
    if (*pnum <= 0) {
      printf("invalid argument %s\n", argv[1]);
      print_usage();
      return 2;
    }
    if (!strcmp(argv[2], "-auto"))
      *pauto = 1;
    else {
      printf("invalid argument %s\n", argv[2]);
      print_usage();
      return 3;
    }
  } else {
    print_usage();
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_opt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
cmpl   $0x2,-0x8(%rbp)
jne    11b2 <parse_opt+0x72>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     11ad <parse_opt+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    127c <parse_opt+0x13c>
jmp    1275 <parse_opt+0x135>
cmpl   $0x3,-0x8(%rbp)
jne    125d <parse_opt+0x11d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jg     1205 <parse_opt+0xc5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe13(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <print_usage@plt>
movl   $0x2,-0x4(%rbp)
jmp    127c <parse_opt+0x13c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe01(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    1231 <parse_opt+0xf1>
mov    -0x20(%rbp),%rax
movl   $0x1,(%rax)
jmp    1258 <parse_opt+0x118>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xdc0(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1060 <print_usage@plt>
movl   $0x3,-0x4(%rbp)
jmp    127c <parse_opt+0x13c>
jmp    1270 <parse_opt+0x130>
mov    $0x0,%al
call   1060 <print_usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    127c <parse_opt+0x13c>
jmp    1275 <parse_opt+0x135>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_opt>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
movl   $0x0,(%rcx)
cmp    $0x3,%edi
je     118f <parse_opt+0x4f>
cmp    $0x2,%edi
jne    11d9 <parse_opt+0x99>
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%ecx
mov    %eax,(%r14)
xor    %eax,%eax
test   %ecx,%ecx
jg     120d <parse_opt+0xcd>
lea    0xe80(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    $0x2,%eax
jmp    120d <parse_opt+0xcd>
mov    %rcx,%r15
mov    0x8(%rbx),%r12
mov    %r12,%rdi
call   1050 <atoi@plt>
mov    %eax,(%r14)
test   %eax,%eax
jle    11e7 <parse_opt+0xa7>
mov    0x10(%rbx),%rbx
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
test   %eax,%eax
je     1204 <parse_opt+0xc4>
lea    0xe3d(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <print_usage@plt>
mov    $0x3,%eax
jmp    120d <parse_opt+0xcd>
xor    %eax,%eax
call   1060 <print_usage@plt>
mov    $0x1,%eax
jmp    120d <parse_opt+0xcd>
lea    0xe12(%rip),%rdi
mov    %r12,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <print_usage@plt>
mov    $0x2,%eax
jmp    120d <parse_opt+0xcd>
movl   $0x1,(%r15)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"invalid argument %s\0A\00"
@.str.1 = [6 x i8] c"-auto\00"
define i32 @parse_opt(i32 %0, i8** %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%10 = load i32*, i32** %9
store i32 0, i32* %10
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 2
br i1 %12, label %13, label %28
13: ; preds = %4
%14 = load i8**, i8*** %7
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
%18 = load i32*, i32** %8
store i32 %17, i32* %18
%19 = load i32*, i32** %8
%20 = load i32, i32* %19
%21 = icmp sle i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %13
%23 = load i8**, i8*** %7
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %25)
store i32 2, i32* %5
br label %65
27: ; preds = %13
br label %64
28: ; preds = %4
%29 = load i32, i32* %6
%30 = icmp eq i32 %29, 3
br i1 %30, label %31, label %61
31: ; preds = %28
%32 = load i8**, i8*** %7
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = load i32*, i32** %8
store i32 %35, i32* %36
%37 = load i32*, i32** %8
%38 = load i32, i32* %37
%39 = icmp sle i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %31
%41 = load i8**, i8*** %7
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %43)
%45 = call i32 (...) @print_usage()
store i32 2, i32* %5
br label %65
46: ; preds = %31
%47 = load i8**, i8*** %7
%48 = getelementptr inbounds i8*, i8** %47, i64 2
%49 = load i8*, i8** %48
%50 = call i32 @strcmp(i8* %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%51 = icmp ne i32 %50, 0
br i1 %51, label %54, label %52
52: ; preds = %46
%53 = load i32*, i32** %9
store i32 1, i32* %53
br label %60
54: ; preds = %46
%55 = load i8**, i8*** %7
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %57)
%59 = call i32 (...) @print_usage()
store i32 3, i32* %5
br label %65
60: ; preds = %52
br label %63
61: ; preds = %28
%62 = call i32 (...) @print_usage()
store i32 1, i32* %5
br label %65
63: ; preds = %60
br label %64
64: ; preds = %63, %27
store i32 0, i32* %5
br label %65
65: ; preds = %64, %61, %54, %40, %22
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
@.str = [21 x i8] c"invalid argument %s\0A\00"
@.str.1 = [6 x i8] c"-auto\00"
define i32 @parse_opt(i32 %0, i8** nocapture %1, i32* nocapture writeonly %2, i32* nocapture writeonly %3) {
store i32 0, i32* %3
switch i32 %0, label %29 [
i32 2, label %5
i32 3, label %12
]
5: ; preds = %4
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
store i32 %8, i32* %2
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %31
10: ; preds = %5
%11 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %31
12: ; preds = %4
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
store i32 %15, i32* %2
%16 = icmp slt i32 %15, 1
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %14)
%19 = tail call i32 (...) @print_usage()
br label %31
20: ; preds = %12
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @strcmp(i8* dereferenceable(1) %22, i8* dereferenceable(6) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %3
br label %31
26: ; preds = %20
%27 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %22)
%28 = tail call i32 (...) @print_usage()
br label %31
29: ; preds = %4
%30 = tail call i32 (...) @print_usage()
br label %31
31: ; preds = %25, %5, %29, %26, %17, %10
%32 = phi i32 [ 2, %10 ], [ 2, %17 ], [ 3, %26 ], [ 1, %29 ], [ 0, %5 ], [ 0, %25 ]
ret i32 %32
}