#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*/ EXIT_FAILURE;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void getopt_gnu(int argc, char *argv[]) {
  int flags, opt;
  int nsecs, tfnd;
  nsecs = 0;
  tfnd = 0;
  flags = 0;
  while ((opt = getopt(argc, argv, "-nt:")) != -1) {
    switch (opt) {
    case 'n':
      flags = 1;
      break;
    case 't':
      nsecs = atoi(optarg);
      tfnd = 1;
      break;
    case 1:
      printf("1 %s\n", optarg);
      break;
    default:
      fprintf(stderr, "Usage: %s [-t nsecs] [-n] name\n", argv[0]);
      exit(EXIT_FAILURE);
    }
  }
  printf("flags=%d; tfnd=%d; optind=%d\n", flags, tfnd, optind);
  if (optind >= argc) {
    fprintf(stderr, "Expected argument after options\n");
    exit(EXIT_FAILURE);
  }
  printf("name argument = %s\n", argv[optind]);
}


x86 assembly (clang, -O0):
<getopt_gnu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe7e(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1241 <getopt_gnu+0xf1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x1,%eax
je     11f3 <getopt_gnu+0xa3>
jmp    11a7 <getopt_gnu+0x57>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
je     11c9 <getopt_gnu+0x79>
jmp    11b8 <getopt_gnu+0x68>
mov    -0x24(%rbp),%eax
sub    $0x74,%eax
je     11d5 <getopt_gnu+0x85>
jmp    1210 <getopt_gnu+0xc0>
movl   $0x1,-0x14(%rbp)
jmp    123c <getopt_gnu+0xec>
mov    0x2e1c(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    123c <getopt_gnu+0xec>
mov    0x2dfe(%rip),%rax
mov    (%rax),%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    123c <getopt_gnu+0xec>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1174 <getopt_gnu+0x24>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    0x2d92(%rip),%rax
mov    (%rax),%ecx
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jl     1295 <getopt_gnu+0x145>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d40(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xdbc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getopt_gnu>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xea9(%rip),%r12
mov    0x2e9a(%rip),%r14
lea    0xea0(%rip),%r13
movl   $0x0,0x4(%rsp)
xor    %r15d,%r15d
jmp    118d <getopt_gnu+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%rsi
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
cmp    $0x1,%eax
je     1180 <getopt_gnu+0x40>
cmp    $0xffffffff,%eax
je     11c0 <getopt_gnu+0x80>
cmp    $0x6e,%eax
je     11b6 <getopt_gnu+0x76>
cmp    $0x74,%eax
jne    1206 <getopt_gnu+0xc6>
mov    $0x1,%r15d
jmp    118d <getopt_gnu+0x4d>
movl   $0x1,0x4(%rsp)
jmp    118d <getopt_gnu+0x4d>
mov    0x2e19(%rip),%r14
mov    (%r14),%ecx
lea    0xe5a(%rip),%rdi
mov    0x4(%rsp),%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
movslq (%r14),%rax
cmp    %ebp,%eax
jge    122e <getopt_gnu+0xee>
mov    (%rbx,%rax,8),%rsi
lea    0xe79(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <printf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdf2(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1220 <getopt_gnu+0xe0>

LLVM IR (-O0):
@.str = [5 x i8] c"-nt:\00"
@optarg = global i8* null
@.str.1 = [6 x i8] c"1 %s\0A\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Usage: %s [-t nsecs] [-n] name\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [30 x i8] c"flags=%d; tfnd=%d; optind=%d\0A\00"
@optind = global i32 0
@.str.4 = [33 x i8] c"Expected argument after options\0A\00"
@.str.5 = [20 x i8] c"name argument = %s\0A\00"
define void @getopt_gnu(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %5
br label %9
9: ; preds = %31, %2
%10 = load i32, i32* %3
%11 = load i8**, i8*** %4
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %6
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %32
14: ; preds = %9
%15 = load i32, i32* %6
switch i32 %15, label %23 [
i32 110, label %16
i32 116, label %17
i32 1, label %20
]
16: ; preds = %14
store i32 1, i32* %5
br label %31
17: ; preds = %14
%18 = load i8*, i8** @optarg
%19 = call i32 @atoi(i8* %18)
store i32 %19, i32* %7
store i32 1, i32* %8
br label %31
20: ; preds = %14
%21 = load i8*, i8** @optarg
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %31
23: ; preds = %14
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %20, %17, %16
br label %9
32: ; preds = %9
%33 = load i32, i32* %5
%34 = load i32, i32* %8
%35 = load i32, i32* @optind
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %33, i32 %34, i32 %35)
%37 = load i32, i32* @optind
%38 = load i32, i32* %3
%39 = icmp sge i32 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %32
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
%44 = call i32 @exit(i32 %43)
unreachable
45: ; preds = %32
%46 = load i8**, i8*** %4
%47 = load i32, i32* @optind
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %50)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"-nt:\00"
@optarg = global i8* null
@.str.1 = [6 x i8] c"1 %s\0A\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Usage: %s [-t nsecs] [-n] name\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [30 x i8] c"flags=%d; tfnd=%d; optind=%d\0A\00"
@optind = global i32 0
@.str.4 = [33 x i8] c"Expected argument after options\0A\00"
@.str.5 = [20 x i8] c"name argument = %s\0A\00"
define void @getopt_gnu(i32 %0, i8** %1) {
br label %3
3: ; preds = %8, %2
%4 = phi i32 [ 0, %2 ], [ 1, %8 ]
%5 = phi i32 [ 0, %2 ], [ %7, %8 ]
br label %6
6: ; preds = %8, %3
%7 = phi i32 [ %5, %3 ], [ 1, %8 ]
br label %8
8: ; preds = %6, %10
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %9, label %13 [
i32 -1, label %19
i32 110, label %3
i32 116, label %6
i32 1, label %10
]
10: ; preds = %8
%11 = load i8*, i8** @optarg
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %8
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %1
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
%20 = load i32, i32* @optind
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 %7, i32 %20)
%22 = load i32, i32* @optind
%23 = icmp slt i32 %22, %0
br i1 %23, label %29, label %24
24: ; preds = %19
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = tail call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
%30 = sext i32 %22 to i64
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i8* %32)
ret void
}