#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*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
scalar_t__ strcmp(char const *, char *);
int search_optab(const char *opcode) {
  FILE *optab;
  char op[10] = "", addr[10] = "";
  optab = fopen("optab.txt", "r");
  if (optab == (FILE *)0)
    return -1;
  rewind(optab);
  if (opcode == (char *)0) {
    return -1;
  }
  do {
    fscanf(optab, "%s", op);
    fscanf(optab, "%s", addr);
    if (strcmp(opcode, op) == 0) {
      fclose(optab);
      return 0;
    }
  } while (!feof(optab));
  fclose(optab);
  return -1;
}


x86 assembly (clang, -O0):
<search_optab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
lea    -0x2c(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <memset@plt>
lea    0xe5d(%rip),%rdi
lea    0xe60(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ca <search_optab+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <search_optab+0x101>
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11ea <search_optab+0x7a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <search_optab+0x101>
jmp    11ef <search_optab+0x7f>
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rdx
lea    0xe0e(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rdx
lea    0xdfa(%rip),%rsi
call   1060 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1243 <search_optab+0xd3>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1271 <search_optab+0x101>
jmp    1248 <search_optab+0xd8>
mov    -0x18(%rbp),%rdi
call   1080 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ef <search_optab+0x7f>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_optab>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
movw   $0x0,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0xe68(%rip),%rdi
lea    0xe6b(%rip),%rsi
call   1080 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1219 <search_optab+0xb9>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <rewind@plt>
test   %r14,%r14
je     1219 <search_optab+0xb9>
lea    0xe47(%rip),%r15
lea    0x18(%rsp),%r12
lea    0x8(%rsp),%r13
nop
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1050 <fscanf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     120f <search_optab+0xaf>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
je     11d0 <search_optab+0x70>
mov    $0xffffffff,%ebp
jmp    1211 <search_optab+0xb1>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"optab.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @search_optab(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [10 x i8]
%6 = alloca [10 x i8]
store i8* %0, i8** %3
%7 = bitcast [10 x i8]* %5 to i8*
%8 = bitcast [10 x i8]* %6 to i8*
%9 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %4
%10 = load i32*, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 -1, i32* %2
br label %43
13: ; preds = %1
%14 = load i32*, i32** %4
%15 = call i32 @rewind(i32* %14)
%16 = load i8*, i8** %3
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 -1, i32* %2
br label %43
19: ; preds = %13
br label %20
20: ; preds = %35, %19
%21 = load i32*, i32** %4
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%23 = call i32 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = load i32*, i32** %4
%25 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%26 = call i32 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%29 = call i64 @strcmp(i8* %27, i8* %28)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %34
31: ; preds = %20
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
store i32 0, i32* %2
br label %43
34: ; preds = %20
br label %35
35: ; preds = %34
%36 = load i32*, i32** %4
%37 = call i32 @feof(i32* %36)
%38 = icmp ne i32 %37, 0
%39 = xor i1 %38, true
br i1 %39, label %20, label %40
40: ; preds = %35
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
store i32 -1, i32* %2
br label %43
43: ; preds = %40, %31, %18, %12
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
@.str = [10 x i8] c"optab.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @search_optab(i8* %0) {
%2 = alloca [10 x i8]
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %22, label %8
8: ; preds = %1
%9 = tail call i32 @rewind(i32* %6)
%10 = icmp eq i8* %0, null
br i1 %10, label %22, label %11
11: ; preds = %8, %16
%12 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%13 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%14 = call i64 @strcmp(i8* %0, i8* %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11
%17 = call i32 @feof(i32* %6)
%18 = icmp eq i32 %17, 0
br i1 %18, label %11, label %19
19: ; preds = %16, %11
%20 = phi i32 [ 0, %11 ], [ -1, %16 ]
%21 = call i32 @fclose(i32* %6)
br label %22
22: ; preds = %19, %8, %1
%23 = phi i32 [ -1, %1 ], [ -1, %8 ], [ %20, %19 ]
ret i32 %23
}