#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(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getopt(int, char **, char *);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
void getopt_simple(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;
    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_simple>:
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     1212 <getopt_simple+0xc2>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x6e,%eax
je     11b8 <getopt_simple+0x68>
jmp    11a7 <getopt_simple+0x57>
mov    -0x24(%rbp),%eax
sub    $0x74,%eax
je     11c4 <getopt_simple+0x74>
jmp    11e1 <getopt_simple+0x91>
movl   $0x1,-0x14(%rbp)
jmp    120d <getopt_simple+0xbd>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
jmp    120d <getopt_simple+0xbd>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1174 <getopt_simple+0x24>
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    0x2dc1(%rip),%rax
mov    (%rax),%ecx
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%eax
cmp    -0x4(%rbp),%eax
jl     1266 <getopt_simple+0x116>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x2d6f(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getopt_simple>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
xor    %r14d,%r14d
lea    0xe96(%rip),%r12
mov    0x2e87(%rip),%r13
xor    %ebx,%ebx
jmp    118e <getopt_simple+0x3e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%edi
call   1060 <atoi@plt>
mov    $0x1,%ebx
mov    %ebp,%edi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
cmp    $0x74,%eax
je     1180 <getopt_simple+0x30>
cmp    $0xffffffff,%eax
je     11b2 <getopt_simple+0x62>
cmp    $0x6e,%eax
jne    11f8 <getopt_simple+0xa8>
mov    $0x1,%r14d
jmp    118e <getopt_simple+0x3e>
mov    0x2e27(%rip),%r12
mov    (%r12),%ecx
lea    0xe60(%rip),%rdi
mov    %r14d,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
movslq (%r12),%rax
cmp    %ebp,%eax
jge    1220 <getopt_simple+0xd0>
mov    (%r15,%rax,8),%rsi
lea    0xe80(%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    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1212 <getopt_simple+0xc2>

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

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