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

/* Variables and functions */
int getopt_long(int, char **, char *, struct option *, int *);
int /*<<< orphan*/ no_argument;
scalar_t__ optind;
int check_flag(const char *flag, int argc, char *argv[]) {
  int index = 0;
  int option;
  char short_flag[3] = {'+', ':', flag[0]};
  optind = 0;
  struct option long_options[2] = {{flag, no_argument, NULL, flag[0]},
                                   {0, 0, 0, 0}};
  while (1) {
    option = getopt_long(argc, argv, short_flag, long_options, &index);
    if (option == flag[0]) {
      return 1;
    } else if (option == -1) {
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movb   $0x2b,-0x2b(%rbp)
movb   $0x3a,-0x2a(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x29(%rbp)
mov    0x2e96(%rip),%rax
movq   $0x0,(%rax)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%eax
mov    %al,-0x68(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
lea    -0x2b(%rbp),%rdx
lea    -0x70(%rbp),%rcx
lea    -0x24(%rbp),%r8
call   1030 <getopt_long@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    -0x10(%rbp),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    11c0 <check_flag+0xa0>
movl   $0x1,-0x4(%rbp)
jmp    11e0 <check_flag+0xc0>
cmpl   $0xffffffff,-0x28(%rbp)
jne    11cf <check_flag+0xaf>
jmp    11d9 <check_flag+0xb9>
jmp    11d4 <check_flag+0xb4>
jmp    1187 <check_flag+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_flag>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movw   $0x3a2b,0x9(%rsp)
mov    (%rdi),%al
mov    %al,0xb(%rsp)
mov    0x2ea6(%rip),%rax
movq   $0x0,(%rax)
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
mov    %rdi,0x10(%rsp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%al
mov    %al,0x18(%rsp)
movsbl (%rdi),%eax
mov    %eax,0x28(%rsp)
lea    0x9(%rsp),%r15
lea    0x10(%rsp),%r12
lea    0xc(%rsp),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r13,%r8
call   1030 <getopt_long@plt>
movsbl (%rbx),%ecx
cmp    %ecx,%eax
je     11b3 <check_flag+0xa3>
cmp    $0xffffffff,%eax
jne    1190 <check_flag+0x80>
xor    %eax,%eax
jmp    11b8 <check_flag+0xa8>
mov    $0x1,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.option = type { i8*, i8, i32*, i32 }
@optind = global i64 0
@no_argument = global i32 0
define i32 @check_flag(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca [3 x i8]
%11 = alloca [2 x %struct.option]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
store i32 0, i32* %8
%12 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
store i8 43, i8* %12
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 58, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
store i8 %17, i8* %14
store i64 0, i64* @optind
%18 = bitcast [2 x %struct.option]* %11 to i8*
%19 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* %11, i64 0, i64 0
%20 = getelementptr inbounds %struct.option, %struct.option* %19, i32 0, i32 0
%21 = load i8*, i8** %5
store i8* %21, i8** %20
%22 = getelementptr inbounds %struct.option, %struct.option* %19, i32 0, i32 1
%23 = load i32, i32* @no_argument
%24 = trunc i32 %23 to i8
store i8 %24, i8* %22
%25 = getelementptr inbounds %struct.option, %struct.option* %19, i32 0, i32 3
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
store i32 %29, i32* %25
%30 = getelementptr inbounds %struct.option, %struct.option* %19, i64 1
br label %31
31: ; preds = %3, %49
%32 = load i32, i32* %6
%33 = load i8**, i8*** %7
%34 = getelementptr inbounds [3 x i8], [3 x i8]* %10, i64 0, i64 0
%35 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* %11, i64 0, i64 0
%36 = call i32 @getopt_long(i32 %32, i8** %33, i8* %34, %struct.option* %35, i32* %8)
store i32 %36, i32* %9
%37 = load i32, i32* %9
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %37, %41
br i1 %42, label %43, label %44
43: ; preds = %31
store i32 1, i32* %4
br label %51
44: ; preds = %31
%45 = load i32, i32* %9
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %48
47: ; preds = %44
br label %50
48: ; preds = %44
br label %49
49: ; preds = %48
br label %31
50: ; preds = %47
store i32 0, i32* %4
br label %51
51: ; preds = %50, %43
%52 = load i32, i32* %4
ret i32 %52
}

LLVM IR (-O2):
%struct.option = type { i8*, i8, i32*, i32 }
@optind = global i64 0
@no_argument = global i32 0
define i32 @check_flag(i8* %0, i32 %1, i8** %2) {
%4 = alloca i32
%5 = alloca [3 x i8]
%6 = alloca [2 x %struct.option]
%7 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
store i8 43, i8* %8
%9 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 1
store i8 58, i8* %9
%10 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 2
%11 = load i8, i8* %0
store i8 %11, i8* %10
store i64 0, i64* @optind
%12 = bitcast [2 x %struct.option]* %6 to i8*
%13 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* %6, i64 0, i64 0
%14 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* %6, i64 0, i64 0, i32 0
store i8* %0, i8** %14
%15 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* %6, i64 0, i64 0, i32 1
%16 = load i32, i32* @no_argument
%17 = trunc i32 %16 to i8
store i8 %17, i8* %15
%18 = getelementptr inbounds [2 x %struct.option], [2 x %struct.option]* %6, i64 0, i64 0, i32 3
%19 = load i8, i8* %0
%20 = sext i8 %19 to i32
store i32 %20, i32* %18
br label %21
21: ; preds = %26, %3
%22 = call i32 @getopt_long(i32 %1, i8** %2, i8* %8, %struct.option* %13, i32* %4)
%23 = load i8, i8* %0
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = icmp eq i32 %22, -1
br i1 %27, label %28, label %21
28: ; preds = %26, %21
%29 = phi i32 [ 1, %21 ], [ 0, %26 ]
ret i32 %29
}