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

/* Variables and functions */
int /*<<< orphan*/ addSym(int, int, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ rstrip(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int sscanf(char *, char *, int *, int *, char *);
char *strchr(char *, char);
void readsym(const char *sname) {
  char line[128], name[128], *c;
  int addr, flag;
  FILE *fp;
  snprintf(line, sizeof(line), "%s.dat", sname);
  if ((fp = fopen(line, "r")) == NULL)
    return;
  while (fgets(line, sizeof(line), fp) != NULL) {
    if ((c = strchr(line, ';')) != NULL) {
      *c = 0;
    }
    rstrip(line);
    if (sscanf(line, "%x:%x:%s", &addr, &flag, name) == 3) {
      addSym(addr, flag, NULL, name);
    }
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<readsym>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x80,%esi
lea    0xe5a(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
jne    11d4 <readsym+0x54>
jmp    1291 <readsym+0x111>
jmp    11d9 <readsym+0x59>
lea    -0x90(%rbp),%rdi
mov    -0x128(%rbp),%rdx
mov    $0x80,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1285 <readsym+0x105>
lea    -0x90(%rbp),%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x118(%rbp)
cmp    $0x0,%rax
je     1227 <readsym+0xa7>
mov    -0x118(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
call   1030 <rstrip@plt>
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%r8
lea    0xdc1(%rip),%rsi
lea    -0x11c(%rbp),%rdx
lea    -0x120(%rbp),%rcx
call   1080 <sscanf@plt>
cmp    $0x3,%eax
jne    1280 <readsym+0x100>
mov    -0x11c(%rbp),%edi
mov    -0x120(%rbp),%esi
lea    -0x110(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edx
call   1090 <addSym@plt>
jmp    11d9 <readsym+0x59>
mov    -0x128(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readsym>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rcx
lea    0xe65(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1060 <snprintf@plt>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1277 <readsym+0xf7>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
mov    $0x80,%esi
mov    %rax,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     126f <readsym+0xef>
lea    0x10(%rsp),%rbx
lea    0xe1a(%rip),%r15
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r13
lea    0x90(%rsp),%rbp
jmp    1225 <readsym+0xa5>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     126f <readsym+0xef>
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     123a <readsym+0xba>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1030 <rstrip@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1080 <sscanf@plt>
cmp    $0x3,%eax
jne    1210 <readsym+0x90>
mov    0xc(%rsp),%edi
mov    0x8(%rsp),%esi
xor    %edx,%edx
mov    %rbp,%rcx
call   1090 <addSym@plt>
jmp    1210 <readsym+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%s.dat\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [9 x i8] c"%x:%x:%s\00"
define void @readsym(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = bitcast i32* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @snprintf(i8* %6, i32 128, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%11 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %33, label %13
13: ; preds = %1
%14 = call i32* @fgets(i8* %6, i32 128, i32* %11)
%15 = icmp eq i32* %14, null
br i1 %15, label %31, label %16
16: ; preds = %13, %28
%17 = call i8* @strchr(i8* %6, i8 signext 59)
%18 = icmp eq i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %16
store i8 0, i8* %17
br label %20
20: ; preds = %19, %16
%21 = call i32 @rstrip(i8* %6)
%22 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32* %4, i32* %5, i8* %7)
%23 = icmp eq i32 %22, 3
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 @addSym(i32 %25, i32 %26, i32* null, i8* %7)
br label %28
28: ; preds = %24, %20
%29 = call i32* @fgets(i8* %6, i32 128, i32* %11)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %16
31: ; preds = %28, %13
%32 = call i32 @fclose(i32* %11)
br label %33
33: ; preds = %1, %31
ret void
}