#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 getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ printf(char *, char *, int);
int test_getopt2(void) {
  int r;
  char *t2[] = {"prog", "-t", "foo", NULL};
  do {
    if (!(optind == 1)) {
      printf("expression '%s' untrue at %d\n", "optind == 1", 49);
      return 0;
    }
  } while (0);
  r = getopt(3, t2, "nt:");
  do {
    if (!(r == 't')) {
      printf("expression '%s' untrue at %d\n", "r == 't'", 52);
      return 0;
    }
  } while (0);
  do {
    if (!(optarg == t2[2])) {
      printf("expression '%s' untrue at %d\n", "optarg == t2[2]", 54);
      return 0;
    }
  } while (0);
  do {
    if (!(optind == 3)) {
      printf("expression '%s' untrue at %d\n", "optind == 3", 55);
      return 0;
    }
  } while (0);
  r = getopt(3, t2, "nt:");
  do {
    if (!(r == -1)) {
      printf("expression '%s' untrue at %d\n", "r == -1", 58);
      return 0;
    }
  } while (0);
  do {
    if (!(optarg == NULL)) {
      printf("expression '%s' untrue at %d\n", "optarg == NULL", 59);
      return 0;
    }
  } while (0);
  return 1;
}


x86 assembly (clang, -O0):
<test_getopt2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2cc1(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2cbe(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2cbb(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2cb8(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e85(%rip),%rax
cmpl   $0x1,(%rax)
je     1188 <test_getopt2+0x68>
lea    0xea1(%rip),%rdi
lea    0xeb8(%rip),%rsi
mov    $0x31,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <test_getopt2+0x1c9>
jmp    118d <test_getopt2+0x6d>
lea    -0x30(%rbp),%rsi
mov    $0x3,%edi
lea    0xe99(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x74,-0x8(%rbp)
je     11d3 <test_getopt2+0xb3>
lea    0xe56(%rip),%rdi
lea    0xe7d(%rip),%rsi
mov    $0x34,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <test_getopt2+0x1c9>
jmp    11d8 <test_getopt2+0xb8>
jmp    11dd <test_getopt2+0xbd>
mov    0x2e14(%rip),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
je     1215 <test_getopt2+0xf5>
lea    0xe14(%rip),%rdi
lea    0xe44(%rip),%rsi
mov    $0x36,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <test_getopt2+0x1c9>
jmp    121a <test_getopt2+0xfa>
jmp    121f <test_getopt2+0xff>
mov    0x2dba(%rip),%rax
cmpl   $0x3,(%rax)
je     1253 <test_getopt2+0x133>
lea    0xdd6(%rip),%rdi
lea    0xe16(%rip),%rsi
mov    $0x37,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <test_getopt2+0x1c9>
jmp    1258 <test_getopt2+0x138>
lea    -0x30(%rbp),%rsi
mov    $0x3,%edi
lea    0xdce(%rip),%rdx
call   1040 <getopt@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     129e <test_getopt2+0x17e>
lea    0xd8b(%rip),%rdi
lea    0xdd7(%rip),%rsi
mov    $0x3a,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <test_getopt2+0x1c9>
jmp    12a3 <test_getopt2+0x183>
jmp    12a8 <test_getopt2+0x188>
mov    0x2d49(%rip),%rax
cmpq   $0x0,(%rax)
je     12dd <test_getopt2+0x1bd>
lea    0xd4c(%rip),%rdi
lea    0xda0(%rip),%rsi
mov    $0x3b,%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12e9 <test_getopt2+0x1c9>
jmp    12e2 <test_getopt2+0x1c2>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getopt2>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0x2cd2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0x2cb6(%rip),%xmm0
movaps %xmm0,(%rsp)
mov    0x2e9b(%rip),%rbx
cmpl   $0x1,(%rbx)
jne    1189 <test_getopt2+0x69>
lea    0xee5(%rip),%rdx
mov    %rsp,%rsi
mov    $0x3,%edi
call   1040 <getopt@plt>
cmp    $0x74,%eax
jne    119e <test_getopt2+0x7e>
mov    0x2e8e(%rip),%r14
mov    (%r14),%rax
cmp    0x10(%rsp),%rax
je     11c0 <test_getopt2+0xa0>
lea    0xe91(%rip),%rdi
lea    0xec1(%rip),%rsi
mov    $0x36,%edx
jmp    11b1 <test_getopt2+0x91>
lea    0xe7c(%rip),%rdi
lea    0xe93(%rip),%rsi
mov    $0x31,%edx
jmp    11b1 <test_getopt2+0x91>
lea    0xe67(%rip),%rdi
lea    0xe8e(%rip),%rsi
mov    $0x34,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret
cmpl   $0x3,(%rbx)
jne    11f3 <test_getopt2+0xd3>
lea    0xe6a(%rip),%rdx
mov    %rsp,%rsi
mov    $0x3,%edi
call   1040 <getopt@plt>
cmp    $0xffffffff,%eax
je     1208 <test_getopt2+0xe8>
lea    0xe27(%rip),%rdi
lea    0xe73(%rip),%rsi
mov    $0x3a,%edx
jmp    11b1 <test_getopt2+0x91>
lea    0xe12(%rip),%rdi
lea    0xe52(%rip),%rsi
mov    $0x37,%edx
jmp    11b1 <test_getopt2+0x91>
cmpq   $0x0,(%r14)
je     1223 <test_getopt2+0x103>
lea    0xdf7(%rip),%rdi
lea    0xe4b(%rip),%rsi
mov    $0x3b,%edx
jmp    11b1 <test_getopt2+0x91>
mov    $0x1,%eax
jmp    11b8 <test_getopt2+0x98>

LLVM IR (-O0):
@.str = [5 x i8] c"prog\00"
@.str.1 = [3 x i8] c"-t\00"
@.str.2 = [4 x i8] c"foo\00"
@__const.test_getopt2.t2 = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* null]
@optind = global i32 0
@.str.3 = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.4 = [12 x i8] c"optind == 1\00"
@.str.5 = [4 x i8] c"nt:\00"
@.str.6 = [9 x i8] c"r == 't'\00"
@optarg = global i8* null
@.str.7 = [16 x i8] c"optarg == t2[2]\00"
@.str.8 = [12 x i8] c"optind == 3\00"
@.str.9 = [8 x i8] c"r == -1\00"
@.str.10 = [15 x i8] c"optarg == NULL\00"
define i32 @test_getopt2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8*]
%4 = bitcast [4 x i8*]* %3 to i8*
br label %5
5: ; preds = %0
%6 = load i32, i32* @optind
%7 = icmp eq i32 %6, 1
br i1 %7, label %10, label %8
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 49)
store i32 0, i32* %1
br label %53
10: ; preds = %5
br label %11
11: ; preds = %10
%12 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%13 = call i32 @getopt(i32 3, i8** %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 %13, i32* %2
br label %14
14: ; preds = %11
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 116
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 52)
store i32 0, i32* %1
br label %53
19: ; preds = %14
br label %20
20: ; preds = %19
br label %21
21: ; preds = %20
%22 = load i8*, i8** @optarg
%23 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 2
%24 = load i8*, i8** %23
%25 = icmp eq i8* %22, %24
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 54)
store i32 0, i32* %1
br label %53
28: ; preds = %21
br label %29
29: ; preds = %28
br label %30
30: ; preds = %29
%31 = load i32, i32* @optind
%32 = icmp eq i32 %31, 3
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 55)
store i32 0, i32* %1
br label %53
35: ; preds = %30
br label %36
36: ; preds = %35
%37 = getelementptr inbounds [4 x i8*], [4 x i8*]* %3, i64 0, i64 0
%38 = call i32 @getopt(i32 3, i8** %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
store i32 %38, i32* %2
br label %39
39: ; preds = %36
%40 = load i32, i32* %2
%41 = icmp eq i32 %40, -1
br i1 %41, label %44, label %42
42: ; preds = %39
%43 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 58)
store i32 0, i32* %1
br label %53
44: ; preds = %39
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45
%47 = load i8*, i8** @optarg
%48 = icmp eq i8* %47, null
br i1 %48, label %51, label %49
49: ; preds = %46
%50 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 59)
store i32 0, i32* %1
br label %53
51: ; preds = %46
br label %52
52: ; preds = %51
store i32 1, i32* %1
br label %53
53: ; preds = %52, %49, %42, %33, %26, %17, %8
%54 = load i32, i32* %1
ret i32 %54
}

LLVM IR (-O2):
@.str = [5 x i8] c"prog\00"
@.str.1 = [3 x i8] c"-t\00"
@.str.2 = [4 x i8] c"foo\00"
@__const.test_getopt2.t2 = [4 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* null]
@optind = global i32 0
@.str.3 = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.4 = [12 x i8] c"optind == 1\00"
@.str.5 = [4 x i8] c"nt:\00"
@.str.6 = [9 x i8] c"r == 't'\00"
@optarg = global i8* null
@.str.7 = [16 x i8] c"optarg == t2[2]\00"
@.str.8 = [12 x i8] c"optind == 3\00"
@.str.9 = [8 x i8] c"r == -1\00"
@.str.10 = [15 x i8] c"optarg == NULL\00"
define i32 @test_getopt2() {
%1 = alloca [4 x i8*]
%2 = bitcast [4 x i8*]* %1 to i8*
%3 = load i32, i32* @optind
%4 = icmp eq i32 %3, 1
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 49)
br label %35
7: ; preds = %0
%8 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 0
%9 = call i32 @getopt(i32 3, i8** %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%10 = icmp eq i32 %9, 116
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 52)
br label %35
13: ; preds = %7
%14 = load i8*, i8** @optarg
%15 = getelementptr inbounds [4 x i8*], [4 x i8*]* %1, i64 0, i64 2
%16 = load i8*, i8** %15
%17 = icmp eq i8* %14, %16
br i1 %17, label %20, label %18
18: ; preds = %13
%19 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i32 54)
br label %35
20: ; preds = %13
%21 = load i32, i32* @optind
%22 = icmp eq i32 %21, 3
br i1 %22, label %25, label %23
23: ; preds = %20
%24 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 55)
br label %35
25: ; preds = %20
%26 = call i32 @getopt(i32 3, i8** %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%27 = icmp eq i32 %26, -1
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i32 58)
br label %35
30: ; preds = %25
%31 = load i8*, i8** @optarg
%32 = icmp eq i8* %31, null
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i32 59)
br label %35
35: ; preds = %30, %33, %28, %23, %18, %11, %5
%36 = phi i32 [ 0, %33 ], [ 0, %28 ], [ 0, %23 ], [ 0, %18 ], [ 0, %11 ], [ 0, %5 ], [ 1, %30 ]
ret i32 %36
}