#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*/ freopen(char *, char *, int /*<<< orphan*/);
char getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
void parse_args(int argc, char *argv[]) {
  char *in = NULL, *out = NULL, c;
  while ((c = getopt(argc, argv, "i:o:")) != -1) {
    switch (c) {
    case 'i':
      in = optarg;
      break;
    case 'o':
      out = optarg;
      break;
    }
  }
  if (optind < argc)
    in = argv[optind];
  if (in)
    freopen(in, "rt", stdin);
  if (out)
    freopen(out, "w+t", stdout);
}


x86 assembly (clang, -O0):
<parse_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeb3(%rip),%rdx
call   1040 <getopt@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     11ad <parse_args+0x8d>
movsbl -0x21(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0x69,%eax
je     1187 <parse_args+0x67>
jmp    1176 <parse_args+0x56>
mov    -0x28(%rbp),%eax
sub    $0x6f,%eax
je     119a <parse_args+0x7a>
jmp    11a8 <parse_args+0x88>
mov    0x2e6a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11a8 <parse_args+0x88>
mov    0x2e57(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    113f <parse_args+0x1f>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jge    11d5 <parse_args+0xb5>
mov    -0x10(%rbp),%rax
mov    0x2e0e(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f9 <parse_args+0xd9>
mov    -0x18(%rbp),%rdi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
lea    0xe11(%rip),%rsi
call   1030 <freopen@plt>
cmpq   $0x0,-0x20(%rbp)
je     121d <parse_args+0xfd>
mov    -0x20(%rbp),%rdi
mov    0x2db9(%rip),%rax
mov    (%rax),%edx
lea    0xdf0(%rip),%rsi
call   1030 <freopen@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec9(%rip),%rdx
call   1040 <getopt@plt>
cmp    $0xff,%al
je     1188 <parse_args+0x68>
xor    %r15d,%r15d
mov    0x2eae(%rip),%r13
lea    0xeaf(%rip),%r12
xor    %r14d,%r14d
jmp    1175 <parse_args+0x55>
cs nopw 0x0(%rax,%rax,1)
mov    0x0(%r13),%r14
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <getopt@plt>
cmp    $0xff,%al
je     118e <parse_args+0x6e>
movsbl %al,%eax
cmp    $0x6f,%eax
je     1160 <parse_args+0x40>
cmp    $0x69,%eax
jne    1164 <parse_args+0x44>
mov    0x0(%r13),%r15
jmp    1164 <parse_args+0x44>
xor    %r14d,%r14d
xor    %r15d,%r15d
mov    0x2e43(%rip),%rax
movslq (%rax),%rax
cmp    %ebp,%eax
jge    11a0 <parse_args+0x80>
mov    (%rbx,%rax,8),%r15
test   %r15,%r15
je     11bd <parse_args+0x9d>
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
lea    0xe50(%rip),%rsi
mov    %r15,%rdi
call   1030 <freopen@plt>
test   %r14,%r14
je     11e8 <parse_args+0xc8>
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <freopen@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"i:o:\00"
@optarg = global i8* null
@optind = global i32 0
@.str.1 = [3 x i8] c"rt\00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"w+t\00"
@stdout = global i32 0
define void @parse_args(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i8* null, i8** %5
store i8* null, i8** %6
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %3
%10 = load i8**, i8*** %4
%11 = call signext i8 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8 %11, i8* %7
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = load i8, i8* %7
%16 = sext i8 %15 to i32
switch i32 %16, label %21 [
i32 105, label %17
i32 111, label %19
]
17: ; preds = %14
%18 = load i8*, i8** @optarg
store i8* %18, i8** %5
br label %21
19: ; preds = %14
%20 = load i8*, i8** @optarg
store i8* %20, i8** %6
br label %21
21: ; preds = %14, %19, %17
br label %8
22: ; preds = %8
%23 = load i32, i32* @optind
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %22
%27 = load i8**, i8*** %4
%28 = load i32, i32* @optind
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
store i8* %31, i8** %5
br label %32
32: ; preds = %26, %22
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %39
35: ; preds = %32
%36 = load i8*, i8** %5
%37 = load i32, i32* @stdin
%38 = call i32 @freopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %35, %32
%40 = load i8*, i8** %6
%41 = icmp ne i8* %40, null
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = load i8*, i8** %6
%44 = load i32, i32* @stdout
%45 = call i32 @freopen(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %42, %39
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"i:o:\00"
@optarg = global i8* null
@optind = global i32 0
@.str.1 = [3 x i8] c"rt\00"
@stdin = global i32 0
@.str.2 = [4 x i8] c"w+t\00"
@stdout = global i32 0
define void @parse_args(i32 %0, i8** %1) {
%3 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i8 %3, -1
br i1 %4, label %19, label %5
5: ; preds = %2, %14
%6 = phi i8 [ %17, %14 ], [ %3, %2 ]
%7 = phi i8* [ %16, %14 ], [ null, %2 ]
%8 = phi i8* [ %15, %14 ], [ null, %2 ]
%9 = sext i8 %6 to i32
switch i32 %9, label %14 [
i32 105, label %10
i32 111, label %12
]
10: ; preds = %5
%11 = load i8*, i8** @optarg
br label %14
12: ; preds = %5
%13 = load i8*, i8** @optarg
br label %14
14: ; preds = %5, %12, %10
%15 = phi i8* [ %8, %5 ], [ %13, %12 ], [ %8, %10 ]
%16 = phi i8* [ %7, %5 ], [ %7, %12 ], [ %11, %10 ]
%17 = tail call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i8 %17, -1
br i1 %18, label %19, label %5
19: ; preds = %14, %2
%20 = phi i8* [ null, %2 ], [ %15, %14 ]
%21 = phi i8* [ null, %2 ], [ %16, %14 ]
%22 = load i32, i32* @optind
%23 = icmp slt i32 %22, %0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = sext i32 %22 to i64
%26 = getelementptr inbounds i8*, i8** %1, i64 %25
%27 = load i8*, i8** %26
br label %28
28: ; preds = %24, %19
%29 = phi i8* [ %27, %24 ], [ %21, %19 ]
%30 = icmp eq i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %28
%32 = load i32, i32* @stdin
%33 = tail call i32 @freopen(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %32)
br label %34
34: ; preds = %31, %28
%35 = icmp eq i8* %20, null
br i1 %35, label %39, label %36
36: ; preds = %34
%37 = load i32, i32* @stdout
%38 = tail call i32 @freopen(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %34
ret void
}