#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 getopt(int, char **, char *);
void parse_cmdline(int argc, char **argv, int *ip_version) {
  int opt;
  *ip_version = 4;
  while ((opt = getopt(argc, argv, "46")) != -1) {
    if (opt == '4') {
      *ip_version = 4;
    }
    if (opt == '6') {
      *ip_version = 6;
    }
  }
}


x86 assembly (clang, -O0):
<parse_cmdline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xec5(%rip),%rdx
call   1030 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     1179 <parse_cmdline+0x69>
cmpl   $0x34,-0x1c(%rbp)
jne    1160 <parse_cmdline+0x50>
mov    -0x18(%rbp),%rax
movl   $0x4,(%rax)
cmpl   $0x36,-0x1c(%rbp)
jne    1174 <parse_cmdline+0x64>
mov    -0x18(%rbp),%rax
movl   $0x6,(%rax)
jmp    112d <parse_cmdline+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_cmdline>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x4,%eax
lea    0xed5(%rip),%r15
mov    %eax,(%r14)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <getopt@plt>
cmp    $0xffffffff,%eax
je     1167 <parse_cmdline+0x57>
cmp    $0x34,%eax
je     1160 <parse_cmdline+0x50>
cmp    $0x36,%eax
jne    1130 <parse_cmdline+0x20>
mov    $0x6,%eax
jmp    112b <parse_cmdline+0x1b>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    $0x4,%eax
jmp    112b <parse_cmdline+0x1b>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"46\00"
define void @parse_cmdline(i32 %0, i8** %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%8 = load i32*, i32** %6
store i32 4, i32* %8
br label %9
9: ; preds = %24, %3
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %25
14: ; preds = %9
%15 = load i32, i32* %7
%16 = icmp eq i32 %15, 52
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = load i32*, i32** %6
store i32 4, i32* %18
br label %19
19: ; preds = %17, %14
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 54
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = load i32*, i32** %6
store i32 6, i32* %23
br label %24
24: ; preds = %22, %19
br label %9
25: ; preds = %9
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"46\00"
define void @parse_cmdline(i32 %0, i8** %1, i32* nocapture writeonly %2) {
br label %4
4: ; preds = %9, %3
%5 = phi i32 [ 4, %3 ], [ %10, %9 ]
store i32 %5, i32* %2
br label %6
6: ; preds = %4, %6
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %7, label %6 [
i32 -1, label %11
i32 52, label %9
i32 54, label %8
]
8: ; preds = %6
br label %9
9: ; preds = %6, %8
%10 = phi i32 [ 6, %8 ], [ 4, %6 ]
br label %4
11: ; preds = %6
ret void
}