#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_FAILURE;
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ strlen(int /*<<< orphan*/);
char *strndup(int /*<<< orphan*/, int /*<<< orphan*/);
unsigned int strtol(int /*<<< orphan*/, char **, int);
int /*<<< orphan*/ usage();
int /*<<< orphan*/ version();
void parse_options(int argc, char **argv, char **host, unsigned int *port) {
  int opt;
  while ((opt = getopt(argc, argv, "c:p:hv")) != -1) {
    switch (opt) {
    case 'c':
      *host = strndup(optarg, strlen(optarg));
      break;
    case 'p': {
      char *end;
      *port = strtol(optarg, &end, 10);
      if (*end) {
        free(*host);
        die("\"port\" requires a valid integer argument, "
            "but got \"%s\" instead\n",
            optarg);
      }
    } break;
    case '?':
      exit(EXIT_FAILURE);
    case 'v':
      version();
    case 'h':
    default:
      usage();
    }
  }
}


x86 assembly (clang, -O0):
<parse_options>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe4b(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     12c9 <parse_options+0x139>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x3f,%eax
je     12a3 <parse_options+0x113>
jmp    11da <parse_options+0x4a>
mov    -0x34(%rbp),%eax
sub    $0x63,%eax
je     121e <parse_options+0x8e>
jmp    11eb <parse_options+0x5b>
mov    -0x34(%rbp),%eax
sub    $0x68,%eax
je     12b8 <parse_options+0x128>
jmp    11fc <parse_options+0x6c>
mov    -0x34(%rbp),%eax
sub    $0x70,%eax
je     1251 <parse_options+0xc1>
jmp    120d <parse_options+0x7d>
mov    -0x34(%rbp),%eax
sub    $0x76,%eax
je     12b1 <parse_options+0x121>
jmp    12bd <parse_options+0x12d>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    12c4 <parse_options+0x134>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     129e <parse_options+0x10e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    0x2d68(%rip),%rax
mov    (%rax),%esi
lea    0xd6e(%rip),%rdi
call   1090 <die@plt>
jmp    12c4 <parse_options+0x134>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   1070 <version@plt>
jmp    12bd <parse_options+0x12d>
mov    $0x0,%al
call   1080 <usage@plt>
jmp    11a7 <parse_options+0x17>
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    %rcx,0x8(%rsp)
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe4e(%rip),%r12
mov    0x2e3f(%rip),%r14
jmp    11c7 <parse_options+0x37>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <usage@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10a0 <getopt@plt>
cmp    $0x6f,%eax
jle    11f0 <parse_options+0x60>
cmp    $0x70,%eax
je     1210 <parse_options+0x80>
cmp    $0x76,%eax
jne    11c0 <parse_options+0x30>
xor    %eax,%eax
call   1070 <version@plt>
jmp    11c0 <parse_options+0x30>
nopl   0x0(%rax)
cmp    $0x63,%eax
jne    124f <parse_options+0xbf>
mov    (%r14),%r13d
mov    %r13d,%edi
call   1040 <strlen@plt>
mov    %r13d,%edi
mov    %eax,%esi
call   1050 <strndup@plt>
mov    %rax,(%r15)
jmp    11c7 <parse_options+0x37>
nop
mov    (%r14),%edi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    0x8(%rsp),%rcx
mov    %eax,(%rcx)
mov    0x10(%rsp),%rax
cmpb   $0x0,(%rax)
je     11c7 <parse_options+0x37>
mov    (%r15),%rdi
call   1030 <free@plt>
mov    (%r14),%esi
lea    0xdc2(%rip),%rdi
call   1090 <die@plt>
jmp    11c7 <parse_options+0x37>
cmp    $0xffffffff,%eax
je     126b <parse_options+0xdb>
cmp    $0x3f,%eax
jne    11c0 <parse_options+0x30>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"c:p:hv\00"
@optarg = global i32 0
@.str.1 = [64 x i8] c"\22port\22 requires a valid integer argument, but got \22%s\22 instead\0A\00"
@EXIT_FAILURE = global i32 0
define void @parse_options(i32 %0, i8** %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32* %3, i32** %8
br label %11
11: ; preds = %46, %4
%12 = load i32, i32* %5
%13 = load i8**, i8*** %6
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %14, i32* %9
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %47
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %44 [
i32 99, label %18
i32 112, label %24
i32 63, label %38
i32 118, label %41
i32 104, label %43
]
18: ; preds = %16
%19 = load i32, i32* @optarg
%20 = load i32, i32* @optarg
%21 = call i32 @strlen(i32 %20)
%22 = call i8* @strndup(i32 %19, i32 %21)
%23 = load i8**, i8*** %7
store i8* %22, i8** %23
br label %46
24: ; preds = %16
%25 = load i32, i32* @optarg
%26 = call i32 @strtol(i32 %25, i8** %10, i32 10)
%27 = load i32*, i32** %8
store i32 %26, i32* %27
%28 = load i8*, i8** %10
%29 = load i8, i8* %28
%30 = icmp ne i8 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i8**, i8*** %7
%33 = load i8*, i8** %32
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* @optarg
%36 = call i32 @die(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31, %24
br label %46
38: ; preds = %16
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %16
%42 = call i32 (...) @version()
br label %43
43: ; preds = %16, %41
br label %44
44: ; preds = %16, %43
%45 = call i32 (...) @usage()
br label %46
46: ; preds = %44, %37, %18
br label %11
47: ; preds = %11
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"c:p:hv\00"
@optarg = global i32 0
@.str.1 = [64 x i8] c"\22port\22 requires a valid integer argument, but got \22%s\22 instead\0A\00"
@EXIT_FAILURE = global i32 0
define void @parse_options(i32 %0, i8** %1, i8** nocapture %2, i32* nocapture writeonly %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
br label %7
7: ; preds = %32, %4
%8 = call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
switch i32 %8, label %30 [
i32 -1, label %33
i32 99, label %9
i32 112, label %13
i32 63, label %25
i32 118, label %28
]
9: ; preds = %7
%10 = load i32, i32* @optarg
%11 = call i32 @strlen(i32 %10)
%12 = call i8* @strndup(i32 %10, i32 %11)
store i8* %12, i8** %2
br label %32
13: ; preds = %7
%14 = load i32, i32* @optarg
%15 = call i32 @strtol(i32 %14, i8** %5, i32 10)
store i32 %15, i32* %3
%16 = load i8*, i8** %5
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %13
%20 = load i8*, i8** %2
%21 = call i32 @free(i8* %20)
%22 = load i32, i32* @optarg
%23 = call i32 @die(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %19, %13
br label %32
25: ; preds = %7
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %7
%29 = call i32 (...) @version()
br label %30
30: ; preds = %7, %28
%31 = call i32 (...) @usage()
br label %32
32: ; preds = %30, %24, %9
br label %7
33: ; preds = %7
ret void
}