#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 *);
scalar_t__ strcmp(char const *, char *);
int search_symtab(const char *symbol) {
  FILE *symtab;
  char sym[10] = "", addr[10] = "";
  symtab = fopen("symtab", "r");
  if (symtab == NULL)
    return -1;
  if (symbol == (char *)0) {
    return -1;
  }
  do {
    fscanf(symtab, "%s", sym);
    fscanf(symtab, "%s", addr);
    if (strcmp(symbol, sym) == 0) {
      fclose(symtab);
      return 0;
    }
  } while (!feof(symtab));
  fclose(symtab);
  return -1;
}


x86 assembly (clang, -O0):
<search_symtab>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    -0x2c(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    0xe6d(%rip),%rdi
lea    0xe6d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ba <search_symtab+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <search_symtab+0xf8>
cmpq   $0x0,-0x10(%rbp)
jne    11d1 <search_symtab+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1258 <search_symtab+0xf8>
jmp    11d6 <search_symtab+0x76>
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x2c(%rbp),%rdx
lea    0xe10(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    122a <search_symtab+0xca>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1258 <search_symtab+0xf8>
jmp    122f <search_symtab+0xcf>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d6 <search_symtab+0x76>
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_symtab>:
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    0xe78(%rip),%rdi
lea    0xe78(%rip),%rsi
call   1070 <fopen@plt>
mov    $0xffffffff,%ebp
test   %r14,%r14
je     1209 <search_symtab+0xb9>
mov    %rax,%rbx
test   %rax,%rax
je     1209 <search_symtab+0xb9>
lea    0xe5c(%rip),%r15
lea    0x18(%rsp),%r12
lea    0x8(%rsp),%r13
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r13,%rdx
call   1040 <fscanf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ff <search_symtab+0xaf>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11c0 <search_symtab+0x70>
mov    $0xffffffff,%ebp
jmp    1201 <search_symtab+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 = [7 x i8] c"symtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @search_symtab(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 ([7 x i8], [7 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 %41
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13
store i32 -1, i32* %2
br label %41
17: ; preds = %13
br label %18
18: ; preds = %33, %17
%19 = load i32*, i32** %4
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%21 = call i32 @fscanf(i32* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = load i32*, i32** %4
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%24 = call i32 @fscanf(i32* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %3
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%27 = call i64 @strcmp(i8* %25, i8* %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %18
%30 = load i32*, i32** %4
%31 = call i32 @fclose(i32* %30)
store i32 0, i32* %2
br label %41
32: ; preds = %18
br label %33
33: ; preds = %32
%34 = load i32*, i32** %4
%35 = call i32 @feof(i32* %34)
%36 = icmp ne i32 %35, 0
%37 = xor i1 %36, true
br i1 %37, label %18, label %38
38: ; preds = %33
%39 = load i32*, i32** %4
%40 = call i32 @fclose(i32* %39)
store i32 -1, i32* %2
br label %41
41: ; preds = %38, %29, %16, %12
%42 = load i32, i32* %2
ret i32 %42
}

LLVM IR (-O2):
@.str = [7 x i8] c"symtab\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
define i32 @search_symtab(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 ([7 x i8], [7 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
%8 = icmp eq i8* %0, null
%9 = or i1 %8, %7
br i1 %9, label %21, label %10
10: ; preds = %1, %15
%11 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = call i32 @fscanf(i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%13 = call i64 @strcmp(i8* %0, i8* %4)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %10
%16 = call i32 @feof(i32* %6)
%17 = icmp eq i32 %16, 0
br i1 %17, label %10, label %18
18: ; preds = %15, %10
%19 = phi i32 [ 0, %10 ], [ -1, %15 ]
%20 = call i32 @fclose(i32* %6)
br label %21
21: ; preds = %18, %1
%22 = phi i32 [ -1, %1 ], [ %19, %18 ]
ret i32 %22
}