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


x86 assembly (clang, -O0):
<get_symbol_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe7d(%rip),%rdi
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    $0xa,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <get_symbol_addr+0x59>
movq   $0x0,-0x8(%rbp)
jmp    126a <get_symbol_addr+0xfa>
cmpq   $0x0,-0x10(%rbp)
jne    11e1 <get_symbol_addr+0x71>
movq   $0x0,-0x8(%rbp)
jmp    126a <get_symbol_addr+0xfa>
jmp    11e6 <get_symbol_addr+0x76>
mov    -0x18(%rbp),%rdi
lea    -0x22(%rbp),%rdx
lea    0xe14(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rdx
lea    0xe00(%rip),%rsi
call   1050 <fscanf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x22(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    123b <get_symbol_addr+0xcb>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    126a <get_symbol_addr+0xfa>
jmp    1240 <get_symbol_addr+0xd0>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e6 <get_symbol_addr+0x76>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_symbol_addr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0xe88(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
movw   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0xa,%edi
call   1070 <malloc@plt>
xor    %r15d,%r15d
test   %r14,%r14
je     1205 <get_symbol_addr+0xa5>
test   %rbx,%rbx
je     1205 <get_symbol_addr+0xa5>
mov    %rax,%r12
lea    0xe51(%rip),%r13
lea    0x8(%rsp),%rbp
xor    %r15d,%r15d
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
call   1040 <fscanf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11fa <get_symbol_addr+0x9a>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11c0 <get_symbol_addr+0x60>
jmp    11fd <get_symbol_addr+0x9d>
mov    %r12,%r15
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rax
add    $0x18,%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 i8* @get_symbol_addr(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [10 x i8]
%6 = alloca i8*
store i8* %0, i8** %3
%7 = 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* %7, i32** %4
%8 = bitcast [10 x i8]* %5 to i8*
%9 = call i64 @malloc(i32 10)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %1
store i8* null, i8** %2
br label %43
14: ; preds = %1
%15 = load i8*, i8** %3
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14
store i8* null, i8** %2
br label %43
18: ; preds = %14
br label %19
19: ; preds = %35, %18
%20 = load i32*, i32** %4
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%22 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %21)
%23 = load i32*, i32** %4
%24 = load i8*, i8** %6
%25 = call i32 @fscanf(i32* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %24)
%26 = load i8*, i8** %3
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%28 = call i64 @strcmp(i8* %26, i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %19
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
%33 = load i8*, i8** %6
store i8* %33, i8** %2
br label %43
34: ; preds = %19
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 %19, label %40
40: ; preds = %35
%41 = load i32*, i32** %4
%42 = call i32 @fclose(i32* %41)
store i8* null, i8** %2
br label %43
43: ; preds = %40, %30, %17, %13
%44 = load i8*, i8** %2
ret i8* %44
}

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 i8* @get_symbol_addr(i8* %0) {
%2 = alloca [10 x i8]
%3 = 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))
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%5 = tail call i64 @malloc(i32 10)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i32* %3, 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* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%12 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%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* %3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %10, label %18
18: ; preds = %15, %10
%19 = phi i8* [ %6, %10 ], [ null, %15 ]
%20 = call i32 @fclose(i32* %3)
br label %21
21: ; preds = %18, %1
%22 = phi i8* [ null, %1 ], [ %19, %18 ]
ret i8* %22
}