#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcmp(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
char *strstr(char *, char *);
int option_match(char *optname, char *optfile) {
  FILE *opt_fp;
  char buf[255];
  char *p;
  if ((opt_fp = fopen(optfile, "r")) == NULL) {
    fprintf(stderr, "Can't open file: %s\n", optfile);
    return -1;
  }
  while (fgets(buf, 255, opt_fp)) {
    if ((p = strstr(buf, optname)) == NULL)
      continue;
    if (!memcmp(buf, "#define", strlen("#define"))) {
      fclose(opt_fp);
      return 1;
    }
  }
  fclose(opt_fp);
  return 0;
}


x86 assembly (clang, -O0):
<option_match>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe72(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11c6 <option_match+0x56>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1272 <option_match+0x102>
jmp    11cb <option_match+0x5b>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0xff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1262 <option_match+0xf2>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strstr@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    1210 <option_match+0xa0>
jmp    11cb <option_match+0x5b>
lea    -0x120(%rbp),%rax
mov    %rax,-0x130(%rbp)
lea    0xdf2(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%edx
lea    0xddd(%rip),%rsi
call   1050 <memcmp@plt>
cmp    $0x0,%eax
jne    125d <option_match+0xed>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <option_match+0x102>
jmp    11cb <option_match+0x5b>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<option_match>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xe75(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1219 <option_match+0xa9>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0xff,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120d <option_match+0x9d>
mov    %rsp,%rbx
lea    0xe59(%rip),%r12
jmp    11d5 <option_match+0x65>
mov    %rbx,%rdi
mov    $0xff,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     120d <option_match+0x9d>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strstr@plt>
test   %rax,%rax
je     11c0 <option_match+0x50>
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <memcmp@plt>
test   %eax,%eax
jne    11c0 <option_match+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    1236 <option_match+0xc6>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    1236 <option_match+0xc6>
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xdd9(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open file: %s\0A\00"
@.str.2 = [8 x i8] c"#define\00"
define i32 @option_match(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [255 x i8]
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %5
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %40
16: ; preds = %2
br label %17
17: ; preds = %36, %27, %16
%18 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%19 = load i32*, i32** %6
%20 = call i64 @fgets(i8* %18, i32 255, i32* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %37
22: ; preds = %17
%23 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%24 = load i8*, i8** %4
%25 = call i8* @strstr(i8* %23, i8* %24)
store i8* %25, i8** %8
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %28
27: ; preds = %22
br label %17
28: ; preds = %22
%29 = getelementptr inbounds [255 x i8], [255 x i8]* %7, i64 0, i64 0
%30 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @memcmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %30)
%32 = icmp ne i32 %31, 0
br i1 %32, label %36, label %33
33: ; preds = %28
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
store i32 1, i32* %3
br label %40
36: ; preds = %28
br label %17
37: ; preds = %17
%38 = load i32*, i32** %6
%39 = call i32 @fclose(i32* %38)
store i32 0, i32* %3
br label %40
40: ; preds = %37, %33, %12
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Can't open file: %s\0A\00"
@.str.2 = [8 x i8] c"#define\00"
define i32 @option_match(i8* nocapture %0, i8* %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = call i64 @fgets(i8* %4, i32 255, i32* %5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %25, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %27
13: ; preds = %7, %16
%14 = call i8* @strstr(i8* %4, i8* dereferenceable(1) %0)
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13, %19
%17 = call i64 @fgets(i8* %4, i32 255, i32* %5)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %13
19: ; preds = %13
%20 = call i32 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @memcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %16
23: ; preds = %19
%24 = call i32 @fclose(i32* %5)
br label %27
25: ; preds = %16, %7
%26 = call i32 @fclose(i32* %5)
br label %27
27: ; preds = %25, %23, %10
%28 = phi i32 [ -1, %10 ], [ 1, %23 ], [ 0, %25 ]
ret i32 %28
}