#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*/ alloc_string(char **, int /*<<< orphan*/);
int /*<<< orphan*/ check_num_args(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
char *strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
scalar_t__ strncmp(char *, char *, int /*<<< orphan*/);
int check_option(int *count, int argc, char *arg1, char *arg2, char *name,
                 char **option, int nb) {
  char *stmp;
  char found = 0;
  *option = NULL;
  if (nb == 0) {
    if (strcmp(name, arg1) == 0)
      found = 1;
  } else {
    if (strcmp(name, arg1) == 0) {
      (*count)++;
      check_num_args(*count, argc);
      *option = arg2;
      found = 1;
    } else {
      alloc_string(&stmp, (strlen(name) + 2));
      sprintf(stmp, "%s=", name);
      if (strncmp(stmp, arg1, strlen(stmp)) == 0) {
        *option = strchr(arg1, '=') + 1;
        found = 1;
      }
      free(stmp);
    }
  }
  if (found)
    return 1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<check_option>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
movb   $0x0,-0x41(%rbp)
mov    -0x38(%rbp),%rax
movq   $0x0,(%rax)
cmpl   $0x0,0x10(%rbp)
jne    11db <check_option+0x5b>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    11d6 <check_option+0x56>
movb   $0x1,-0x41(%rbp)
jmp    12aa <check_option+0x12a>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    121f <check_option+0x9f>
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%esi
call   1070 <check_num_args@plt>
mov    -0x28(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x1,-0x41(%rbp)
jmp    12a5 <check_option+0x125>
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%esi
add    $0x2,%esi
lea    -0x40(%rbp),%rdi
call   1090 <alloc_string@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xdbb(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    129c <check_option+0x11c>
mov    -0x20(%rbp),%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
mov    %rax,%rcx
add    $0x1,%rcx
mov    -0x38(%rbp),%rax
mov    %rcx,(%rax)
movb   $0x1,-0x41(%rbp)
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    12aa <check_option+0x12a>
cmpb   $0x0,-0x41(%rbp)
je     12c0 <check_option+0x140>
movl   $0x1,-0x4(%rbp)
jmp    12c7 <check_option+0x147>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_option>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8,%rbx
mov    %rcx,%r12
mov    %rdx,%r15
mov    %esi,%r13d
mov    %rdi,%rbp
movq   $0x0,(%r9)
mov    %r8,%rdi
mov    %rdx,%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
cmpl   $0x0,0x40(%rsp)
je     120f <check_option+0x8f>
test   %rcx,%rcx
je     1218 <check_option+0x98>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x2(%rax),%esi
mov    %rsp,%rdi
call   1090 <alloc_string@plt>
mov    (%rsp),%rdi
lea    0xe24(%rip),%rsi
mov    %rbx,%rdx
call   10a0 <sprintf@plt>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     122e <check_option+0xae>
mov    (%rsp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
jmp    1250 <check_option+0xd0>
xor    %eax,%eax
test   %rcx,%rcx
jne    1250 <check_option+0xd0>
jmp    124b <check_option+0xcb>
mov    0x0(%rbp),%edi
add    $0x1,%edi
mov    %edi,0x0(%rbp)
mov    %r13d,%esi
call   1070 <check_num_args@plt>
mov    %r12,(%r14)
jmp    124b <check_option+0xcb>
mov    %r15,%rdi
mov    $0x3d,%esi
call   1060 <strchr@plt>
add    $0x1,%rax
mov    %rax,(%r14)
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s=\00"
define i32 @check_option(i32* %0, i32 %1, i8* %2, i8* %3, i8* %4, i8** %5, i32 %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8**
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8
store i32* %0, i32** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i8** %5, i8*** %14
store i32 %6, i32* %15
store i8 0, i8* %17
%18 = load i8**, i8*** %14
store i8* null, i8** %18
%19 = load i32, i32* %15
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %7
%22 = load i8*, i8** %13
%23 = load i8*, i8** %11
%24 = call i64 @strcmp(i8* %22, i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %21
store i8 1, i8* %17
br label %27
27: ; preds = %26, %21
br label %66
28: ; preds = %7
%29 = load i8*, i8** %13
%30 = load i8*, i8** %11
%31 = call i64 @strcmp(i8* %29, i8* %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %28
%34 = load i32*, i32** %9
%35 = load i32, i32* %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %34
%37 = load i32*, i32** %9
%38 = load i32, i32* %37
%39 = load i32, i32* %10
%40 = call i32 @check_num_args(i32 %38, i32 %39)
%41 = load i8*, i8** %12
%42 = load i8**, i8*** %14
store i8* %41, i8** %42
store i8 1, i8* %17
br label %65
43: ; preds = %28
%44 = load i8*, i8** %13
%45 = call i32 @strlen(i8* %44)
%46 = add nsw i32 %45, 2
%47 = call i32 @alloc_string(i8** %16, i32 %46)
%48 = load i8*, i8** %16
%49 = load i8*, i8** %13
%50 = call i32 @sprintf(i8* %48, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %49)
%51 = load i8*, i8** %16
%52 = load i8*, i8** %11
%53 = load i8*, i8** %16
%54 = call i32 @strlen(i8* %53)
%55 = call i64 @strncmp(i8* %51, i8* %52, i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %43
%58 = load i8*, i8** %11
%59 = call i8* @strchr(i8* %58, i8 signext 61)
%60 = getelementptr inbounds i8, i8* %59, i64 1
%61 = load i8**, i8*** %14
store i8* %60, i8** %61
store i8 1, i8* %17
br label %62
62: ; preds = %57, %43
%63 = load i8*, i8** %16
%64 = call i32 @free(i8* %63)
br label %65
65: ; preds = %62, %33
br label %66
66: ; preds = %65, %27
%67 = load i8, i8* %17
%68 = icmp ne i8 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %66
store i32 1, i32* %8
br label %71
70: ; preds = %66
store i32 0, i32* %8
br label %71
71: ; preds = %70, %69
%72 = load i32, i32* %8
ret i32 %72
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s=\00"
define i32 @check_option(i32* nocapture %0, i32 %1, i8* %2, i8* %3, i8* %4, i8** nocapture writeonly %5, i32 %6) {
%8 = alloca i8*
%9 = bitcast i8** %8 to i8*
store i8* null, i8** %5
%10 = icmp eq i32 %6, 0
%11 = tail call i64 @strcmp(i8* %4, i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %10, label %13, label %14
13: ; preds = %7
br i1 %12, label %32, label %38
14: ; preds = %7
br i1 %12, label %15, label %19
15: ; preds = %14
%16 = load i32, i32* %0
%17 = add nsw i32 %16, 1
store i32 %17, i32* %0
%18 = tail call i32 @check_num_args(i32 %17, i32 %1)
store i8* %3, i8** %5
br label %32
19: ; preds = %14
%20 = tail call i32 @strlen(i8* %4)
%21 = add nsw i32 %20, 2
%22 = call i32 @alloc_string(i8** %8, i32 %21)
%23 = load i8*, i8** %8
%24 = call i32 @sprintf(i8* dereferenceable(1) %23, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %4)
%25 = load i8*, i8** %8
%26 = call i32 @strlen(i8* %25)
%27 = call i64 @strncmp(i8* %25, i8* %2, i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %19
%30 = load i8*, i8** %8
%31 = call i32 @free(i8* %30)
br label %38
32: ; preds = %15, %13
br label %38
33: ; preds = %19
%34 = call i8* @strchr(i8* dereferenceable(1) %2, i8 signext 61)
%35 = getelementptr inbounds i8, i8* %34, i64 1
store i8* %35, i8** %5
%36 = load i8*, i8** %8
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %13, %29, %33, %32
%39 = phi i32 [ 1, %33 ], [ 1, %32 ], [ 0, %29 ], [ 0, %13 ]
ret i32 %39
}