#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int parse_options(int argc, char **argv, int *max_cores, char **exe_name,
                  char **core_dir, char **email) {
  int c;
  *max_cores = 10;
  *exe_name = NULL;
  *core_dir = "/var/core";
  *email = NULL;
  while ((c = getopt(argc, argv, "d:e:hm:s:")) != -1) {
    switch (c) {
    case 'd':
      *core_dir = optarg;
      break;
    case 'e':
      *exe_name = optarg;
      break;
    case 'h':
      usage();
      exit(0);
      break;
    case 'm':
      *max_cores = atoi(optarg);
      if (*max_cores == 0) {
        fprintf(stderr,
                "handle_core: invalid argument "
                "for max_cores: %s. Please give a number "
                "greater than 0.\n",
                optarg);
        return 1;
      }
      break;
    case 's':
      *email = optarg;
      break;
    default:
      fprintf(stderr, "handle_core: invalid usage\n\n");
      return 1;
      break;
    }
  }
  if (*exe_name == NULL) {
    fprintf(stderr, "handle_core: you must supply the executable "
                    "name with -e. Try -h for help.\n");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x18(%rbp),%rax
movl   $0xa,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x28(%rbp),%rax
lea    0xeb1(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x30(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe9f(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     12b3 <parse_options+0x163>
mov    -0x34(%rbp),%eax
add    $0xffffff9c,%eax
mov    %eax,%ecx
mov    %rcx,-0x40(%rbp)
sub    $0xf,%eax
ja     128b <parse_options+0x13b>
mov    -0x40(%rbp),%rax
lea    0xe24(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2e0c(%rip),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    12ae <parse_options+0x15e>
mov    0x2df6(%rip),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
jmp    12ae <parse_options+0x15e>
mov    $0x0,%al
call   1040 <usage@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1270 <parse_options+0x120>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%rdx
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <parse_options+0x19b>
jmp    12ae <parse_options+0x15e>
mov    0x2d7c(%rip),%rax
mov    (%rax),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
jmp    12ae <parse_options+0x15e>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <parse_options+0x19b>
jmp    119d <parse_options+0x4d>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12e4 <parse_options+0x194>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xdf7(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12eb <parse_options+0x19b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_options>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rdx,0x8(%rsp)
movl   $0xa,(%rdx)
mov    %rcx,(%rsp)
movq   $0x0,(%rcx)
lea    0xebd(%rip),%rax
mov    %rax,(%r8)
mov    %r9,0x10(%rsp)
movq   $0x0,(%r9)
lea    0xe67(%rip),%r12
mov    0x2e58(%rip),%r14
jmp    11ba <parse_options+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rsp),%rax
mov    (%r14),%rcx
mov    %rcx,(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0xe84(%rip),%rdx
call   1050 <getopt@plt>
lea    -0x64(%rax),%ecx
cmp    $0xf,%ecx
ja     1207 <parse_options+0xb7>
movslq (%r12,%rcx,4),%rcx
add    %r12,%rcx
mov    %r13,%rax
jmp    *%rcx
mov    (%r14),%r15
mov    %r15,%rdi
call   1060 <atoi@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
test   %eax,%eax
jne    11ba <parse_options+0x6a>
jmp    1243 <parse_options+0xf3>
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%rax
jmp    11b4 <parse_options+0x64>
cmp    $0xffffffff,%eax
jne    122a <parse_options+0xda>
xor    %eax,%eax
mov    (%rsp),%rcx
cmpq   $0x0,(%rcx)
jne    1262 <parse_options+0x112>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
jmp    123a <parse_options+0xea>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xe71(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    125d <parse_options+0x10d>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1040 <usage@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/var/core\00"
@.str.1 = [10 x i8] c"d:e:hm:s:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [87 x i8] c"handle_core: invalid argument for max_cores: %s. Please give a number greater than 0.\0A\00"
@.str.3 = [29 x i8] c"handle_core: invalid usage\0A\0A\00"
@.str.4 = [76 x i8] c"handle_core: you must supply the executable name with -e. Try -h for help.\0A\00"
define i32 @parse_options(i32 %0, i8** %1, i32* %2, i8** %3, i8** %4, i8** %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i8**
%13 = alloca i8**
%14 = alloca i32
store i32 %0, i32* %8
store i8** %1, i8*** %9
store i32* %2, i32** %10
store i8** %3, i8*** %11
store i8** %4, i8*** %12
store i8** %5, i8*** %13
%15 = load i32*, i32** %10
store i32 10, i32* %15
%16 = load i8**, i8*** %11
store i8* null, i8** %16
%17 = load i8**, i8*** %12
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %17
%18 = load i8**, i8*** %13
store i8* null, i8** %18
br label %19
19: ; preds = %53, %6
%20 = load i32, i32* %8
%21 = load i8**, i8*** %9
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 %22, i32* %14
%23 = icmp ne i32 %22, -1
br i1 %23, label %24, label %54
24: ; preds = %19
%25 = load i32, i32* %14
switch i32 %25, label %50 [
i32 100, label %26
i32 101, label %29
i32 104, label %32
i32 109, label %35
i32 115, label %47
]
26: ; preds = %24
%27 = load i8*, i8** @optarg
%28 = load i8**, i8*** %12
store i8* %27, i8** %28
br label %53
29: ; preds = %24
%30 = load i8*, i8** @optarg
%31 = load i8**, i8*** %11
store i8* %30, i8** %31
br label %53
32: ; preds = %24
%33 = call i32 (...) @usage()
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %24
%36 = load i8*, i8** @optarg
%37 = call i32 @atoi(i8* %36)
%38 = load i32*, i32** %10
store i32 %37, i32* %38
%39 = load i32*, i32** %10
%40 = load i32, i32* %39
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %35
%43 = load i32, i32* @stderr
%44 = load i8*, i8** @optarg
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8* %44)
store i32 1, i32* %7
br label %62
46: ; preds = %35
br label %53
47: ; preds = %24
%48 = load i8*, i8** @optarg
%49 = load i8**, i8*** %13
store i8* %48, i8** %49
br label %53
50: ; preds = %24
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %7
br label %62
53: ; preds = %47, %46, %29, %26
br label %19
54: ; preds = %19
%55 = load i8**, i8*** %11
%56 = load i8*, i8** %55
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %61
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %7
br label %62
61: ; preds = %54
store i32 0, i32* %7
br label %62
62: ; preds = %61, %58, %50, %42
%63 = load i32, i32* %7
ret i32 %63
}

LLVM IR (-O2):
@.str = [10 x i8] c"/var/core\00"
@.str.1 = [10 x i8] c"d:e:hm:s:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.2 = [87 x i8] c"handle_core: invalid argument for max_cores: %s. Please give a number greater than 0.\0A\00"
@.str.3 = [29 x i8] c"handle_core: invalid usage\0A\0A\00"
@.str.4 = [76 x i8] c"handle_core: you must supply the executable name with -e. Try -h for help.\0A\00"
define i32 @parse_options(i32 %0, i8** %1, i32* nocapture writeonly %2, i8** nocapture %3, i8** nocapture writeonly %4, i8** nocapture writeonly %5) {
store i32 10, i32* %2
store i8* null, i8** %3
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %4
store i8* null, i8** %5
br label %7
7: ; preds = %27, %6
%8 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
switch i32 %8, label %21 [
i32 -1, label %28
i32 100, label %24
i32 101, label %9
i32 104, label %10
i32 109, label %13
i32 115, label %20
]
9: ; preds = %7
br label %24
10: ; preds = %7
%11 = tail call i32 (...) @usage()
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %7
%14 = load i8*, i8** @optarg
%15 = tail call i32 @atoi(i8* %14)
store i32 %15, i32* %2
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %27
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %34
20: ; preds = %7
br label %24
21: ; preds = %7
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
br label %34
24: ; preds = %7, %9, %20
%25 = phi i8** [ %5, %20 ], [ %3, %9 ], [ %4, %7 ]
%26 = load i8*, i8** @optarg
store i8* %26, i8** %25
br label %27
27: ; preds = %24, %13
br label %7
28: ; preds = %7
%29 = load i8*, i8** %3
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %28, %31, %21, %17
%35 = phi i32 [ 1, %21 ], [ 1, %17 ], [ 1, %31 ], [ 0, %28 ]
ret i32 %35
}