#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 */
float atof(int /*<<< orphan*/);
int atoi(int /*<<< orphan*/);
int getopt(int, char **, char *);
int /*<<< orphan*/ help(char *);
int /*<<< orphan*/ optarg;
int optopt;
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char **argv) {
  int a = 42;
  char b = 0;
  float c = 0.0;
  char d = 0;
  int opt;
  printf("getopt() demo program.\n----------------------\n");
  if (argc == 1) {
    help(argv[0]);
    return 0;
  }
  while ((opt = getopt(argc, argv, ":a:bc:d")) != -1) {
    switch (opt) {
    case 'a':
      a = atoi(optarg);
      break;
    case 'b':
      b = 1;
      break;
    case 'c':
      c = atof(optarg);
      break;
    case 'd':
      d = 1;
      break;
    case ':':
      printf("Missing argument: option '-%c' requires one.\n", optopt);
      return 1;
      break;
    case '?':
      printf("Unknown option (-%c).\n", optopt);
      return 2;
      break;
    default:
      break;
    }
  }
  printf("User input is: \n");
  printf("    a = %d\n", a);
  printf("    b is %s set.\n", (b == 1) ? "" : "not");
  printf("    c = %f\n", c);
  printf("    d is %s set.\n", (d == 1) ? "" : "not");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2a,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
lea    0xf28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jne    11ad <main+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1315 <main+0x1c5>
jmp    11b2 <main+0x62>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xf1b(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     128a <main+0x13a>
mov    -0x24(%rbp),%eax
add    $0xffffffc6,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x2a,%eax
ja     1280 <main+0x130>
mov    -0x30(%rbp),%rax
lea    0xe0f(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
call   1070 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    1285 <main+0x135>
movb   $0x1,-0x15(%rbp)
jmp    1285 <main+0x135>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1030 <atof@plt>
movss  %xmm0,-0x1c(%rbp)
jmp    1285 <main+0x135>
movb   $0x1,-0x1d(%rbp)
jmp    1285 <main+0x135>
mov    0x2d9f(%rip),%rax
mov    (%rax),%esi
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1315 <main+0x1c5>
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1315 <main+0x1c5>
jmp    1285 <main+0x135>
jmp    11b2 <main+0x62>
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xe97(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x15(%rbp),%ecx
lea    0xea3(%rip),%rsi
lea    0xe7d(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
lea    0xe7c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x1c(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe7b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsbl -0x1d(%rbp),%ecx
lea    0xe65(%rip),%rsi
lea    0xe3f(%rip),%rax
cmp    $0x1,%ecx
cmove  %rax,%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xfc2(%rip),%rdi
call   1030 <puts@plt>
cmp    $0x1,%ebp
jne    1190 <main+0x30>
mov    (%rbx),%rdi
call   1070 <help@plt>
xor    %ebx,%ebx
jmp    12d2 <main+0x172>
xorps  %xmm0,%xmm0
movss  %xmm0,(%rsp)
mov    $0x2a,%r14d
movl   $0x0,0x4(%rsp)
lea    0xeff(%rip),%r15
lea    0xe4c(%rip),%r12
xor    %r13d,%r13d
jmp    11c9 <main+0x69>
nopl   0x0(%rax)
cmp    $0xffffffff,%eax
je     125b <main+0xfb>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <getopt@plt>
lea    -0x3a(%rax),%ecx
cmp    $0x2a,%ecx
ja     11c0 <main+0x60>
movslq (%r12,%rcx,4),%rax
add    %r12,%rax
jmp    *%rax
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,%r14d
jmp    11c9 <main+0x69>
mov    $0x1,%r13b
jmp    11c9 <main+0x69>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1040 <atof@plt>
movss  %xmm0,(%rsp)
jmp    11c9 <main+0x69>
mov    $0x1,%al
mov    %eax,0x4(%rsp)
jmp    11c9 <main+0x69>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ebx
jmp    12d2 <main+0x172>
mov    0x2d9c(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%ebx
jmp    12d2 <main+0x172>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
lea    0xe8b(%rip),%rdi
xor    %ebx,%ebx
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
cmp    $0x1,%r13b
lea    0xe73(%rip),%r14
lea    0xe8b(%rip),%rbp
mov    %rbp,%rsi
cmove  %r14,%rsi
lea    0xe6b(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
movss  (%rsp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe6a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
cmpb   $0x1,0x4(%rsp)
cmove  %r14,%rbp
lea    0xe5f(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"getopt() demo program.\0A----------------------\0A\00"
@.str.1 = [8 x i8] c":a:bc:d\00"
@optarg = global i32 0
@.str.2 = [46 x i8] c"Missing argument: option '-%c' requires one.\0A\00"
@optopt = global i32 0
@.str.3 = [23 x i8] c"Unknown option (-%c).\0A\00"
@.str.4 = [17 x i8] c"User input is: \0A\00"
@.str.5 = [12 x i8] c" a = %d\0A\00"
@.str.6 = [18 x i8] c" b is %s set.\0A\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [4 x i8] c"not\00"
@.str.9 = [12 x i8] c" c = %f\0A\00"
@.str.10 = [18 x i8] c" d is %s set.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8
%8 = alloca float
%9 = alloca i8
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 42, i32* %6
store i8 0, i8* %7
store float 0.000000e+00, float* %8
store i8 0, i8* %9
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @help(i8* %17)
store i32 0, i32* %3
br label %62
19: ; preds = %2
br label %20
20: ; preds = %42, %19
%21 = load i32, i32* %4
%22 = load i8**, i8*** %5
%23 = call i32 @getopt(i32 %21, i8** %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 %23, i32* %10
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = load i32, i32* %10
switch i32 %26, label %41 [
i32 97, label %27
i32 98, label %30
i32 99, label %31
i32 100, label %34
i32 58, label %35
i32 63, label %38
]
27: ; preds = %25
%28 = load i32, i32* @optarg
%29 = call i32 @atoi(i32 %28)
store i32 %29, i32* %6
br label %42
30: ; preds = %25
store i8 1, i8* %7
br label %42
31: ; preds = %25
%32 = load i32, i32* @optarg
%33 = call float @atof(i32 %32)
store float %33, float* %8
br label %42
34: ; preds = %25
store i8 1, i8* %9
br label %42
35: ; preds = %25
%36 = load i32, i32* @optopt
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %36)
store i32 1, i32* %3
br label %62
38: ; preds = %25
%39 = load i32, i32* @optopt
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %39)
store i32 2, i32* %3
br label %62
41: ; preds = %25
br label %42
42: ; preds = %41, %34, %31, %30, %27
br label %20
43: ; preds = %20
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %45)
%47 = load i8, i8* %7
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 1
%50 = zext i1 %49 to i64
%51 = select i1 %49, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %51)
%53 = load float, float* %8
%54 = fpext float %53 to double
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %54)
%56 = load i8, i8* %9
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 1
%59 = zext i1 %58 to i64
%60 = select i1 %58, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %60)
store i32 0, i32* %3
br label %62
62: ; preds = %43, %38, %35, %14
%63 = load i32, i32* %3
ret i32 %63
}

LLVM IR (-O2):
@.str.1 = [8 x i8] c":a:bc:d\00"
@optarg = global i32 0
@.str.2 = [46 x i8] c"Missing argument: option '-%c' requires one.\0A\00"
@optopt = global i32 0
@.str.3 = [23 x i8] c"Unknown option (-%c).\0A\00"
@.str.5 = [12 x i8] c" a = %d\0A\00"
@.str.6 = [18 x i8] c" b is %s set.\0A\00"
@.str.7 = [1 x i8] zeroinitializer
@.str.8 = [4 x i8] c"not\00"
@.str.9 = [12 x i8] c" c = %f\0A\00"
@.str.10 = [18 x i8] c" d is %s set.\0A\00"
@str = [46 x i8] c"getopt() demo program.\0A----------------------\00"
@str.11 = [16 x i8] c"User input is: \00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%4 = icmp eq i32 %0, 1
br i1 %4, label %5, label %13
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = tail call i32 @help(i8* %6)
br label %47
8: ; preds = %28, %8
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
switch i32 %9, label %8 [
i32 -1, label %36
i32 97, label %10
i32 98, label %18
i32 99, label %22
i32 100, label %28
i32 58, label %30
i32 63, label %33
]
10: ; preds = %8
%11 = load i32, i32* @optarg
%12 = tail call i32 @atoi(i32 %11)
br label %13
13: ; preds = %2, %10
%14 = phi i32 [ %12, %10 ], [ 42, %2 ]
%15 = phi i8 [ %19, %10 ], [ 0, %2 ]
%16 = phi float [ %26, %10 ], [ 0.000000e+00, %2 ]
%17 = phi i8 [ %29, %10 ], [ 0, %2 ]
br label %18
18: ; preds = %8, %13
%19 = phi i8 [ %15, %13 ], [ 1, %8 ]
%20 = phi float [ %16, %13 ], [ %26, %8 ]
%21 = phi i8 [ %17, %13 ], [ %29, %8 ]
br label %25
22: ; preds = %8
%23 = load i32, i32* @optarg
%24 = tail call float @atof(i32 %23)
br label %25
25: ; preds = %18, %22
%26 = phi float [ %20, %18 ], [ %24, %22 ]
%27 = phi i8 [ %21, %18 ], [ %29, %22 ]
br label %28
28: ; preds = %8, %25
%29 = phi i8 [ %27, %25 ], [ 1, %8 ]
br label %8
30: ; preds = %8
%31 = load i32, i32* @optopt
%32 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %47
33: ; preds = %8
%34 = load i32, i32* @optopt
%35 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32 %34)
br label %47
36: ; preds = %8
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
%38 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%39 = icmp eq i8 %19, 1
%40 = select i1 %39, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0)
%41 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %40)
%42 = fpext float %26 to double
%43 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %42)
%44 = icmp eq i8 %29, 1
%45 = select i1 %44, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0)
%46 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.10, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %36, %33, %30, %5
%48 = phi i32 [ 0, %5 ], [ 2, %33 ], [ 1, %30 ], [ 0, %36 ]
ret i32 %48
}