#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 *member_0;
  int member_1;
  int *member_2;
  char member_3;
};

/* Variables and functions */
int getopt_long(int, char **, char *, struct option *, int /*<<< orphan*/ *);
char *optarg;
int optind;
scalar_t__ optopt;
int test_getopt_long2(void) {
  int r;
  char *t2[] = {"prog", "--bar", "--foo", "xyz", NULL};
  int var = 0;
  struct option lo2[] = {
      {"bar", 0, 0, 'y'},
      {"foo", 1, &var, 'x'},
      {0, 0, 0, 0},
  };
  if (optind != 1)
    return 0;
  r = getopt_long(4, t2, "", lo2, NULL);
  if (r != 'y')
    return 0;
  if (optind != 2)
    return 0;
  r = getopt_long(4, t2, "", lo2, NULL);
  if (r != 0)
    return 0;
  if (optopt != 0)
    return 0;
  if (optarg != t2[3])
    return 0;
  if (optind != 4)
    return 0;
  r = getopt_long(4, t2, "", lo2, NULL);
  if (r != -1)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<test_getopt_long2>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1040 <memset@plt>
lea    0xebe(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xeb8(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xeb3(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xeae(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xe8b(%rip),%rax
mov    %rax,-0xa0(%rbp)
movl   $0x0,-0x98(%rbp)
movq   $0x0,-0x90(%rbp)
movb   $0x79,-0x88(%rbp)
add    $0x20,%rdi
lea    0xe63(%rip),%rax
mov    %rax,-0x80(%rbp)
movl   $0x1,-0x78(%rbp)
lea    -0x34(%rbp),%rax
mov    %rax,-0x70(%rbp)
movb   $0x78,-0x68(%rbp)
add    $0x20,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0x2e00(%rip),%rax
cmpl   $0x1,(%rax)
je     11ed <test_getopt_long2+0xcd>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
lea    -0x30(%rbp),%rsi
lea    -0xa0(%rbp),%rcx
mov    $0x4,%edi
lea    0xe00(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <getopt_long@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x79,-0x8(%rbp)
je     1227 <test_getopt_long2+0x107>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
mov    0x2daa(%rip),%rax
cmpl   $0x2,(%rax)
je     1243 <test_getopt_long2+0x123>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
lea    -0x30(%rbp),%rsi
lea    -0xa0(%rbp),%rcx
mov    $0x4,%edi
lea    0xdaa(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <getopt_long@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     127d <test_getopt_long2+0x15d>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
mov    0x2d5c(%rip),%rax
cmpq   $0x0,(%rax)
je     129a <test_getopt_long2+0x17a>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
mov    0x2d57(%rip),%rax
mov    (%rax),%rax
cmp    -0x18(%rbp),%rax
je     12ba <test_getopt_long2+0x19a>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
mov    0x2d17(%rip),%rax
cmpl   $0x4,(%rax)
je     12d6 <test_getopt_long2+0x1b6>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
lea    -0x30(%rbp),%rsi
lea    -0xa0(%rbp),%rcx
mov    $0x4,%edi
lea    0xd17(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1030 <getopt_long@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
je     1310 <test_getopt_long2+0x1f0>
movl   $0x0,-0x4(%rbp)
jmp    1317 <test_getopt_long2+0x1f7>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getopt_long2>:
push   %r14
push   %rbx
sub    $0xa8,%rsp
movq   $0x0,0x30(%rsp)
lea    0xed6(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xecf(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xec9(%rip),%rax
mov    %rax,0x20(%rsp)
lea    0xec3(%rip),%rax
mov    %rax,0x28(%rsp)
movl   $0x0,0xc(%rsp)
lea    0xea5(%rip),%rax
mov    %rax,0x40(%rsp)
movl   $0x0,0x48(%rsp)
movq   $0x0,0x50(%rsp)
movb   $0x79,0x58(%rsp)
lea    0xe89(%rip),%rax
mov    %rax,0x60(%rsp)
movl   $0x1,0x68(%rsp)
lea    0xc(%rsp),%rax
mov    %rax,0x70(%rsp)
movb   $0x78,0x78(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
mov    0x2e1e(%rip),%r14
xor    %ebx,%ebx
cmpl   $0x1,(%r14)
jne    125f <test_getopt_long2+0x14f>
lea    0xe37(%rip),%rdx
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
lea    0x40(%rsp),%rcx
mov    $0x4,%edi
xor    %r8d,%r8d
call   1030 <getopt_long@plt>
cmp    $0x79,%eax
jne    125f <test_getopt_long2+0x14f>
cmpl   $0x2,(%r14)
jne    125f <test_getopt_long2+0x14f>
lea    0xe0c(%rip),%rdx
xor    %ebx,%ebx
lea    0x10(%rsp),%rsi
lea    0x40(%rsp),%rcx
mov    $0x4,%edi
xor    %r8d,%r8d
call   1030 <getopt_long@plt>
test   %eax,%eax
jne    125f <test_getopt_long2+0x14f>
mov    0x2dc4(%rip),%rax
cmpq   $0x0,(%rax)
jne    125f <test_getopt_long2+0x14f>
mov    0x2dcf(%rip),%rax
mov    (%rax),%rax
cmp    0x28(%rsp),%rax
jne    125f <test_getopt_long2+0x14f>
cmpl   $0x4,(%r14)
jne    125f <test_getopt_long2+0x14f>
lea    0xdc4(%rip),%rdx
lea    0x10(%rsp),%rsi
lea    0x40(%rsp),%rcx
mov    $0x4,%edi
xor    %r8d,%r8d
call   1030 <getopt_long@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
mov    %ebx,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.option = type { i8*, i32, i32*, i8 }
@.str = [5 x i8] c"prog\00"
@.str.1 = [6 x i8] c"--bar\00"
@.str.2 = [6 x i8] c"--foo\00"
@.str.3 = [4 x i8] c"xyz\00"
@.str.4 = [4 x i8] c"bar\00"
@.str.5 = [4 x i8] c"foo\00"
@optind = global i32 0
@.str.6 = [1 x i8] zeroinitializer
@optopt = global i64 0
@optarg = global i8* null
define i32 @test_getopt_long2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [5 x i8*]
%4 = alloca i32
%5 = alloca [3 x %struct.option]
%6 = bitcast [5 x i8*]* %3 to i8*
%7 = bitcast i8* %6 to [5 x i8*]*
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8** %10
%11 = getelementptr inbounds [5 x i8*], [5 x i8*]* %7, i32 0, i32 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8** %11
store i32 0, i32* %4
%12 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0
%13 = getelementptr inbounds %struct.option, %struct.option* %12, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds %struct.option, %struct.option* %12, i32 0, i32 1
store i32 0, i32* %14
%15 = getelementptr inbounds %struct.option, %struct.option* %12, i32 0, i32 2
store i32* null, i32** %15
%16 = getelementptr inbounds %struct.option, %struct.option* %12, i32 0, i32 3
store i8 121, i8* %16
%17 = getelementptr inbounds %struct.option, %struct.option* %12, i64 1
%18 = getelementptr inbounds %struct.option, %struct.option* %17, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds %struct.option, %struct.option* %17, i32 0, i32 1
store i32 1, i32* %19
%20 = getelementptr inbounds %struct.option, %struct.option* %17, i32 0, i32 2
store i32* %4, i32** %20
%21 = getelementptr inbounds %struct.option, %struct.option* %17, i32 0, i32 3
store i8 120, i8* %21
%22 = getelementptr inbounds %struct.option, %struct.option* %17, i64 1
%23 = bitcast %struct.option* %22 to i8*
%24 = load i32, i32* @optind
%25 = icmp ne i32 %24, 1
br i1 %25, label %26, label %27
26: ; preds = %0
store i32 0, i32* %1
br label %67
27: ; preds = %0
%28 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
%29 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0
%30 = call i32 @getopt_long(i32 4, i8** %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %struct.option* %29, i32* null)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = icmp ne i32 %31, 121
br i1 %32, label %33, label %34
33: ; preds = %27
store i32 0, i32* %1
br label %67
34: ; preds = %27
%35 = load i32, i32* @optind
%36 = icmp ne i32 %35, 2
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* %1
br label %67
38: ; preds = %34
%39 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
%40 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0
%41 = call i32 @getopt_long(i32 4, i8** %39, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %struct.option* %40, i32* null)
store i32 %41, i32* %2
%42 = load i32, i32* %2
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 0, i32* %1
br label %67
45: ; preds = %38
%46 = load i64, i64* @optopt
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45
store i32 0, i32* %1
br label %67
49: ; preds = %45
%50 = load i8*, i8** @optarg
%51 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 3
%52 = load i8*, i8** %51
%53 = icmp ne i8* %50, %52
br i1 %53, label %54, label %55
54: ; preds = %49
store i32 0, i32* %1
br label %67
55: ; preds = %49
%56 = load i32, i32* @optind
%57 = icmp ne i32 %56, 4
br i1 %57, label %58, label %59
58: ; preds = %55
store i32 0, i32* %1
br label %67
59: ; preds = %55
%60 = getelementptr inbounds [5 x i8*], [5 x i8*]* %3, i64 0, i64 0
%61 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %5, i64 0, i64 0
%62 = call i32 @getopt_long(i32 4, i8** %60, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %struct.option* %61, i32* null)
store i32 %62, i32* %2
%63 = load i32, i32* %2
%64 = icmp ne i32 %63, -1
br i1 %64, label %65, label %66
65: ; preds = %59
store i32 0, i32* %1
br label %67
66: ; preds = %59
store i32 1, i32* %1
br label %67
67: ; preds = %66, %65, %58, %54, %48, %44, %37, %33, %26
%68 = load i32, i32* %1
ret i32 %68
}

LLVM IR (-O2):
%struct.option = type { i8*, i32, i32*, i8 }
@.str = [5 x i8] c"prog\00"
@.str.1 = [6 x i8] c"--bar\00"
@.str.2 = [6 x i8] c"--foo\00"
@.str.3 = [4 x i8] c"xyz\00"
@.str.4 = [4 x i8] c"bar\00"
@.str.5 = [4 x i8] c"foo\00"
@optind = global i32 0
@.str.6 = [1 x i8] zeroinitializer
@optopt = global i64 0
@optarg = global i8* null
define i32 @test_getopt_long2() {
%1 = alloca [5 x i8*]
%2 = alloca i32
%3 = alloca [3 x %struct.option]
%4 = bitcast [5 x i8*]* %1 to i8*
%5 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 4
%6 = bitcast i8** %5 to i64*
store i64 0, i64* %6
%7 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %8
%9 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %10
%11 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%12 = bitcast [3 x %struct.option]* %3 to i8*
%13 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0
%14 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 1
store i32 0, i32* %15
%16 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 2
store i32* null, i32** %16
%17 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 0, i32 3
store i8 121, i8* %17
%18 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 1
store i32 1, i32* %19
%20 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 2
store i32* %2, i32** %20
%21 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 1, i32 3
store i8 120, i8* %21
%22 = getelementptr inbounds [3 x %struct.option], [3 x %struct.option]* %3, i64 0, i64 2
%23 = bitcast %struct.option* %22 to i8*
%24 = load i32, i32* @optind
%25 = icmp eq i32 %24, 1
br i1 %25, label %26, label %49
26: ; preds = %0
%27 = call i32 @getopt_long(i32 4, i8** %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %struct.option* %13, i32* null)
%28 = icmp eq i32 %27, 121
%29 = load i32, i32* @optind
%30 = icmp eq i32 %29, 2
%31 = select i1 %28, i1 %30, i1 false
br i1 %31, label %32, label %49
32: ; preds = %26
%33 = call i32 @getopt_long(i32 4, i8** %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %struct.option* %13, i32* null)
%34 = icmp eq i32 %33, 0
%35 = load i64, i64* @optopt
%36 = icmp eq i64 %35, 0
%37 = select i1 %34, i1 %36, i1 false
br i1 %37, label %38, label %49
38: ; preds = %32
%39 = load i8*, i8** @optarg
%40 = load i8*, i8** %10
%41 = icmp eq i8* %39, %40
%42 = load i32, i32* @optind
%43 = icmp eq i32 %42, 4
%44 = select i1 %41, i1 %43, i1 false
br i1 %44, label %45, label %49
45: ; preds = %38
%46 = call i32 @getopt_long(i32 4, i8** %7, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.6, i64 0, i64 0), %struct.option* %13, i32* null)
%47 = icmp eq i32 %46, -1
%48 = zext i1 %47 to i32
br label %49
49: ; preds = %45, %38, %32, %26, %0
%50 = phi i32 [ 0, %0 ], [ 0, %26 ], [ 0, %32 ], [ 0, %38 ], [ %48, %45 ]
ret i32 %50
}