#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int getopt(int, char **, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int c;
  char buffer[10];
  while ((c = getopt(argc, argv, "hV")) != -1) {
    switch (c) {
    case 'h':
      usage(argv[0]);
      return 0;
    case 'V':
      printf("%s\n", "Using getopt example v0.1");
      return EXIT_SUCCESS;
    default:
      usage(argv[0]);
      return EXIT_FAILURE;
    }
  }
  printf("Say something: ");
  scanf("%s", buffer);
  printf("You said \"%s\"\n", buffer);
  return EXIT_SUCCESS;
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe9c(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     11f5 <main+0xb5>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x56,%eax
je     11b2 <main+0x72>
jmp    1189 <main+0x49>
mov    -0x24(%rbp),%eax
sub    $0x68,%eax
jne    11d8 <main+0x98>
jmp    119a <main+0x5a>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    1231 <main+0xf1>
lea    0xe4a(%rip),%rdi
lea    0xe47(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1231 <main+0xf1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
mov    0x2df5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1231 <main+0xf1>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x1e(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x1e(%rbp),%rsi
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0xea1(%rip),%rdx
call   1070 <getopt@plt>
cmp    $0xffffffff,%eax
je     117f <main+0x2f>
cmp    $0x56,%eax
je     11b4 <main+0x64>
cmp    $0x68,%eax
jne    11c9 <main+0x79>
mov    (%rbx),%rdi
call   1050 <usage@plt>
xor    %eax,%eax
jmp    11da <main+0x8a>
lea    0xe97(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
lea    0x6(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xe88(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c0 <main+0x70>
lea    0xe48(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e11(%rip),%rax
jmp    11d8 <main+0x88>
mov    (%rbx),%rdi
call   1050 <usage@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"hV\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [26 x i8] c"Using getopt example v0.1\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"Say something: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [15 x i8] c"You said \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [10 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %8
8: ; preds = %2
%9 = load i32, i32* %4
%10 = load i8**, i8*** %5
%11 = call i32 @getopt(i32 %9, i8** %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 %11, i32* %6
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %29
13: ; preds = %8
%14 = load i32, i32* %6
switch i32 %14, label %23 [
i32 104, label %15
i32 86, label %20
]
15: ; preds = %13
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @usage(i8* %18)
store i32 0, i32* %3
br label %36
20: ; preds = %13
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_SUCCESS
store i32 %22, i32* %3
br label %36
23: ; preds = %13
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
%27 = call i32 @usage(i8* %26)
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %36
29: ; preds = %8
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%32 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %33)
%35 = load i32, i32* @EXIT_SUCCESS
store i32 %35, i32* %3
br label %36
36: ; preds = %29, %23, %20, %15
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [3 x i8] c"hV\00"
@.str.2 = [26 x i8] c"Using getopt example v0.1\00"
@EXIT_SUCCESS = global i32 0
@EXIT_FAILURE = global i32 0
@.str.3 = [16 x i8] c"Say something: \00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [15 x i8] c"You said \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %12 [
i32 -1, label %16
i32 104, label %6
i32 86, label %9
]
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
br label %21
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%11 = load i32, i32* @EXIT_SUCCESS
br label %21
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @usage(i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
br label %21
16: ; preds = %2
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %4)
%20 = load i32, i32* @EXIT_SUCCESS
br label %21
21: ; preds = %16, %12, %9, %6
%22 = phi i32 [ %15, %12 ], [ %11, %9 ], [ 0, %6 ], [ %20, %16 ]
ret i32 %22
}