#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 atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
int optind;
int optopt;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
void parse_args(int argc, char **argv, char **address, int *port,
                char **mimetype, char **filename) {
  int ch;
  while ((ch = getopt(argc, argv, "h:p:m:")) != -1) {
    switch (ch) {
    case 'h':
      *address = optarg;
      break;
    case 'p':
      *port = atoi(optarg);
      break;
    case 'm':
      *mimetype = optarg;
      break;
    case '?':
      printf("USAGE: netshare [-h host] [-p port] [-m mime/type] <filename>\n");
      fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
    }
  }
  if (optind >= argc) {
    fprintf(stderr,
            "USAGE: netshare [-h host] [-p port] [-m mime/type] <filename>\n");
    exit(EXIT_FAILURE);
  }
  *filename = argv[optind];
}


x86 assembly (clang, -O0):
<parse_args>:
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    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe83(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     124e <parse_args+0xfe>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x3f,%eax
je     121d <parse_args+0xcd>
jmp    11a2 <parse_args+0x52>
mov    -0x38(%rbp),%eax
sub    $0x68,%eax
je     11d5 <parse_args+0x85>
jmp    11b3 <parse_args+0x63>
mov    -0x38(%rbp),%eax
sub    $0x6d,%eax
je     1207 <parse_args+0xb7>
jmp    11c4 <parse_args+0x74>
mov    -0x38(%rbp),%eax
sub    $0x70,%eax
je     11eb <parse_args+0x9b>
jmp    1249 <parse_args+0xf9>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1249 <parse_args+0xf9>
mov    0x2e06(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
jmp    1249 <parse_args+0xf9>
mov    0x2dea(%rip),%rax
mov    (%rax),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,(%rax)
jmp    1249 <parse_args+0xf9>
lea    0xde3(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    0x2da7(%rip),%rax
mov    (%rax),%edx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    116f <parse_args+0x1f>
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jl     1285 <parse_args+0x135>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d48(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x8(%rsp)
mov    %r8,0x10(%rsp)
mov    %rcx,%r12
mov    %rdx,%r13
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe86(%rip),%r14
mov    0x2e77(%rip),%r15
jmp    11b0 <parse_args+0x60>
lea    0xede(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
lea    0xe9e(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
cmp    $0x6c,%eax
jg     11e0 <parse_args+0x90>
cmp    $0x3f,%eax
je     1183 <parse_args+0x33>
cmp    $0x68,%eax
jne    1205 <parse_args+0xb5>
mov    (%r15),%rax
mov    %rax,0x0(%r13)
jmp    11b0 <parse_args+0x60>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0x6d,%eax
je     11f8 <parse_args+0xa8>
cmp    $0x70,%eax
jne    11b0 <parse_args+0x60>
mov    (%r15),%rdi
call   1060 <atoi@plt>
mov    %eax,(%r12)
jmp    11b0 <parse_args+0x60>
mov    (%r15),%rax
mov    0x10(%rsp),%rcx
mov    %rax,(%rcx)
jmp    11b0 <parse_args+0x60>
cmp    $0xffffffff,%eax
jne    11b0 <parse_args+0x60>
mov    0x2dc7(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    1233 <parse_args+0xe3>
mov    (%rbx,%rax,8),%rax
mov    0x8(%rsp),%rcx
mov    %rax,(%rcx)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"h:p:m:\00"
@optarg = global i8* null
@.str.1 = [63 x i8] c"USAGE: netshare [-h host] [-p port] [-m mime/type] <filename>\0A\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@optopt = global i32 0
@optind = global i32 0
@EXIT_FAILURE = global i32 0
define void @parse_args(i32 %0, i8** %1, i8** %2, i32* %3, i8** %4, i8** %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i8**
%10 = alloca i32*
%11 = alloca i8**
%12 = alloca i8**
%13 = alloca i32
store i32 %0, i32* %7
store i8** %1, i8*** %8
store i8** %2, i8*** %9
store i32* %3, i32** %10
store i8** %4, i8*** %11
store i8** %5, i8*** %12
br label %14
14: ; preds = %36, %6
%15 = load i32, i32* %7
%16 = load i8**, i8*** %8
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %17, i32* %13
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %37
19: ; preds = %14
%20 = load i32, i32* %13
switch i32 %20, label %36 [
i32 104, label %21
i32 112, label %24
i32 109, label %28
i32 63, label %31
]
21: ; preds = %19
%22 = load i8*, i8** @optarg
%23 = load i8**, i8*** %9
store i8* %22, i8** %23
br label %36
24: ; preds = %19
%25 = load i8*, i8** @optarg
%26 = call i32 @atoi(i8* %25)
%27 = load i32*, i32** %10
store i32 %26, i32* %27
br label %36
28: ; preds = %19
%29 = load i8*, i8** @optarg
%30 = load i8**, i8*** %11
store i8* %29, i8** %30
br label %36
31: ; preds = %19
%32 = call i32 @printf(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%33 = load i32, i32* @stderr
%34 = load i32, i32* @optopt
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %34)
br label %36
36: ; preds = %31, %19, %28, %24, %21
br label %14
37: ; preds = %14
%38 = load i32, i32* @optind
%39 = load i32, i32* %7
%40 = icmp sge i32 %38, %39
br i1 %40, label %41, label %46
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %37
%47 = load i8**, i8*** %8
%48 = load i32, i32* @optind
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %12
store i8* %51, i8** %52
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"h:p:m:\00"
@optarg = global i8* null
@.str.1 = [63 x i8] c"USAGE: netshare [-h host] [-p port] [-m mime/type] <filename>\0A\00"
@stderr = global i32 0
@.str.2 = [34 x i8] c"Unknown option character `\\x%x'.\0A\00"
@optopt = global i32 0
@optind = global i32 0
@EXIT_FAILURE = global i32 0
@str = [62 x i8] c"USAGE: netshare [-h host] [-p port] [-m mime/type] <filename>\00"
define void @parse_args(i32 %0, i8** %1, i8** nocapture writeonly %2, i32* nocapture writeonly %3, i8** nocapture writeonly %4, i8** nocapture writeonly %5) {
br label %7
7: ; preds = %9, %6
%8 = tail 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 %9 [
i32 -1, label %22
i32 104, label %10
i32 112, label %12
i32 109, label %15
i32 63, label %17
]
9: ; preds = %7, %17, %15, %12, %10
br label %7
10: ; preds = %7
%11 = load i8*, i8** @optarg
store i8* %11, i8** %2
br label %9
12: ; preds = %7
%13 = load i8*, i8** @optarg
%14 = tail call i32 @atoi(i8* %13)
store i32 %14, i32* %3
br label %9
15: ; preds = %7
%16 = load i8*, i8** @optarg
store i8* %16, i8** %4
br label %9
17: ; preds = %7
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([62 x i8], [62 x i8]* @str, i64 0, i64 0))
%19 = load i32, i32* @stderr
%20 = load i32, i32* @optopt
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %20)
br label %9
22: ; preds = %7
%23 = load i32, i32* @optind
%24 = icmp slt i32 %23, %0
br i1 %24, label %30, label %25
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %22
%31 = sext i32 %23 to i64
%32 = getelementptr inbounds i8*, i8** %1, i64 %31
%33 = load i8*, i8** %32
store i8* %33, i8** %5
ret void
}