#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 */
struct option {
  char *name;
  int has_arg;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
#define no_argument 130
#define optional_argument 129
int /*<<< orphan*/ printf(char *, ...);
#define required_argument 128
void usage(const char *name, struct option *options, unsigned num_options) {
  int i;
  printf("Usage: %s [options] <binary>\n", name);
  printf("Options:\n");
  for (i = 0; i < num_options; ++i) {
    printf(" --%s", options[i].name);
    switch (options[i].has_arg) {
    default:
    case no_argument:
      break;
    case optional_argument:
      printf("[=arg]");
      break;
    case required_argument:
      printf("=arg");
      break;
    }
    printf("\n");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<usage>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xed2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1214 <usage+0xf4>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
shl    $0x4,%rcx
mov    (%rax,%rcx,1),%rsi
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
shl    $0x4,%rcx
mov    0x8(%rax,%rcx,1),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     11ea <usage+0xca>
jmp    11a7 <usage+0x87>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
je     11d7 <usage+0xb7>
jmp    11ba <usage+0x9a>
mov    -0x1c(%rbp),%eax
sub    $0x82,%eax
je     11d2 <usage+0xb2>
jmp    11cd <usage+0xad>
jmp    11d2 <usage+0xb2>
jmp    11f8 <usage+0xd8>
lea    0xe50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11f8 <usage+0xd8>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115a <usage+0x3a>
xor    %edi,%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<usage>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec8(%rip),%rdi
call   1040 <puts@plt>
test   %ebp,%ebp
jne    1178 <usage+0x38>
xor    %edi,%edi
call   1060 <exit@plt>
mov    %ebp,%r13d
shl    $0x4,%r13
lea    0xe98(%rip),%r14
lea    0xe97(%rip),%r15
lea    0xe97(%rip),%r12
xor    %ebp,%ebp
jmp    11ba <usage+0x7a>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x10,%rbp
cmp    %rbp,%r13
je     1171 <usage+0x31>
mov    (%rbx,%rbp,1),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x8(%rbx,%rbp,1),%eax
mov    %r15,%rdi
cmp    $0x81,%eax
je     11a0 <usage+0x60>
cmp    $0x80,%eax
jne    11a7 <usage+0x67>
mov    %r12,%rdi
jmp    11a0 <usage+0x60>

LLVM IR (-O0):
%struct.option = type { i8*, i32 }
@.str = [30 x i8] c"Usage: %s [options] <binary>\0A\00"
@.str.1 = [10 x i8] c"Options:\0A\00"
@.str.2 = [6 x i8] c" --%s\00"
@.str.3 = [7 x i8] c"[=arg]\00"
@.str.4 = [5 x i8] c"=arg\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @usage(i8* %0, %struct.option* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca %struct.option*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store %struct.option* %1, %struct.option** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %7
br label %11
11: ; preds = %37, %3
%12 = load i32, i32* %7
%13 = load i32, i32* %6
%14 = icmp ult i32 %12, %13
br i1 %14, label %15, label %40
15: ; preds = %11
%16 = load %struct.option*, %struct.option** %5
%17 = load i32, i32* %7
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds %struct.option, %struct.option* %16, i64 %18
%20 = getelementptr inbounds %struct.option, %struct.option* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load %struct.option*, %struct.option** %5
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds %struct.option, %struct.option* %23, i64 %25
%27 = getelementptr inbounds %struct.option, %struct.option* %26, i32 0, i32 1
%28 = load i32, i32* %27
switch i32 %28, label %29 [
i32 130, label %30
i32 129, label %31
i32 128, label %33
]
29: ; preds = %15
br label %30
30: ; preds = %15, %29
br label %35
31: ; preds = %15
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %35
33: ; preds = %15
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %30
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
br label %11
40: ; preds = %11
%41 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.option = type { i8*, i32 }
@.str = [30 x i8] c"Usage: %s [options] <binary>\0A\00"
@.str.2 = [6 x i8] c" --%s\00"
@.str.3 = [7 x i8] c"[=arg]\00"
@.str.4 = [5 x i8] c"=arg\00"
@str = [9 x i8] c"Options:\00"
define void @usage(i8* %0, %struct.option* nocapture %1, i32 %2) {
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%6 = icmp eq i32 %2, 0
br i1 %6, label %24, label %7
7: ; preds = %3
%8 = zext i32 %2 to i64
br label %9
9: ; preds = %7, %20
%10 = phi i64 [ 0, %7 ], [ %22, %20 ]
%11 = getelementptr inbounds %struct.option, %struct.option* %1, i64 %10, i32 0
%12 = load i8*, i8** %11
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds %struct.option, %struct.option* %1, i64 %10, i32 1
%15 = load i32, i32* %14
switch i32 %15, label %20 [
i32 128, label %16
i32 129, label %17
]
16: ; preds = %9
br label %17
17: ; preds = %9, %16
%18 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), %16 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %9 ]
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %18)
br label %20
20: ; preds = %17, %9
%21 = tail call i32 @putchar(i32 10)
%22 = add nuw nsw i64 %10, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %24, label %9
24: ; preds = %20, %3
%25 = tail call i32 @exit(i32 0)
unreachable
}