#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*/ bad(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ new_symbol(char *, unsigned int, unsigned int, char);
int sscanf(char *, char *, unsigned int *);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
char *strtok(char *, char *);
void load_symbols(FILE *fp) {
  char buf[256];
  char err[256];
  while (fgets(buf, 255, stdin)) {
    char *a, *s, *t, *n;
    unsigned int addr, seg;
    strcpy(err, buf);
    a = strtok(buf, " \t\n");
    if (a == NULL)
      bad(err);
    s = strtok(NULL, " \t\n");
    if (s == NULL)
      bad(err);
    t = strtok(NULL, " \t\n");
    if (t == NULL)
      bad(err);
    n = strtok(NULL, " \t\n");
    if (n == NULL)
      bad(err);
    if (*s == 'A')
      continue;
    if (*t != '-' && *t != 'E' && *t != 'S' && *t != 'A')
      bad(err);
    if (sscanf(a, "%x", &addr) != 1)
      bad(err);
    seg = 255;
    if (sscanf(s, "%d", &seg) != 1 || seg < 0 || seg > 15)
      bad(err);
    new_symbol(n, addr, seg, *t);
  }
}


x86 assembly (clang, -O0):
<load_symbols>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1386 <load_symbols+0x226>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11da <load_symbols+0x7a>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xe1b(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    120b <load_symbols+0xab>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdea(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x228(%rbp)
cmpq   $0x0,-0x228(%rbp)
jne    123c <load_symbols+0xdc>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb9(%rip),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x230(%rbp)
cmpq   $0x0,-0x230(%rbp)
jne    126d <load_symbols+0x10d>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
mov    -0x220(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
jne    1285 <load_symbols+0x125>
jmp    116f <load_symbols+0xf>
mov    -0x228(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     12dd <load_symbols+0x17d>
mov    -0x228(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x45,%eax
je     12dd <load_symbols+0x17d>
mov    -0x228(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x53,%eax
je     12dd <load_symbols+0x17d>
mov    -0x228(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x41,%eax
je     12dd <load_symbols+0x17d>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
mov    -0x218(%rbp),%rdi
lea    0xd19(%rip),%rsi
lea    -0x234(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     130c <load_symbols+0x1ac>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
movl   $0xff,-0x238(%rbp)
mov    -0x220(%rbp),%rdi
lea    0xce3(%rip),%rsi
lea    -0x238(%rbp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    1353 <load_symbols+0x1f3>
cmpl   $0x0,-0x238(%rbp)
jb     1353 <load_symbols+0x1f3>
cmpl   $0xf,-0x238(%rbp)
jbe    135f <load_symbols+0x1ff>
lea    -0x210(%rbp),%rdi
call   1040 <bad@plt>
mov    -0x230(%rbp),%rdi
mov    -0x234(%rbp),%esi
mov    -0x238(%rbp),%edx
mov    -0x228(%rbp),%rax
movsbl (%rax),%ecx
call   1060 <new_symbol@plt>
jmp    116f <load_symbols+0xf>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_symbols>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    0x2e70(%rip),%rax
mov    (%rax),%edx
lea    0x110(%rsp),%rdi
mov    $0xff,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1308 <load_symbols+0x1a8>
lea    0x110(%rsp),%rbx
lea    0xe5c(%rip),%r15
jmp    11ee <load_symbols+0x8e>
cs nopw 0x0(%rax,%rax,1)
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%esi
movsbl 0x0(%r13),%ecx
mov    %r14,%rdi
call   1060 <new_symbol@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xff,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1308 <load_symbols+0x1a8>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1218 <load_symbols+0xb8>
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    1234 <load_symbols+0xd4>
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1250 <load_symbols+0xf0>
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1080 <strtok@plt>
mov    %rax,%r14
test   %rax,%rax
je     1270 <load_symbols+0x110>
cmpb   $0x41,0x0(%rbp)
je     11cf <load_symbols+0x6f>
jmp    1284 <load_symbols+0x124>
xchg   %ax,%ax
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
cmpb   $0x41,0x0(%rbp)
je     11cf <load_symbols+0x6f>
movzbl 0x0(%r13),%eax
add    $0xd3,%al
cmp    $0x26,%al
ja     12fc <load_symbols+0x19c>
movzbl %al,%eax
movabs $0x4001100001,%rcx
bt     %rax,%rcx
jae    12fc <load_symbols+0x19c>
mov    %r12,%rdi
lea    0xd58(%rip),%rsi
lea    0xc(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
je     12c5 <load_symbols+0x165>
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
movl   $0xff,0x8(%rsp)
mov    %rbp,%rdi
lea    0xd30(%rip),%rsi
lea    0x8(%rsp),%rdx
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11b0 <load_symbols+0x50>
mov    0x8(%rsp),%edx
cmp    $0x10,%edx
jb     11be <load_symbols+0x5e>
jmp    11b0 <load_symbols+0x50>
lea    0x10(%rsp),%rdi
call   1040 <bad@plt>
jmp    12a2 <load_symbols+0x142>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%d\00"
define void @load_symbols(i32* %0) {
%2 = alloca i32*
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %2
br label %11
11: ; preds = %97, %53, %1
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i64 @fgets(i8* %12, i32 255, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %104
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%19 = call i32 @strcpy(i8* %17, i8* %18)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%21 = call i8* @strtok(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp eq i8* %22, null
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%26 = call i32 @bad(i8* %25)
br label %27
27: ; preds = %24, %16
%28 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %6
%29 = load i8*, i8** %6
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %34
31: ; preds = %27
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%33 = call i32 @bad(i8* %32)
br label %34
34: ; preds = %31, %27
%35 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %35, i8** %7
%36 = load i8*, i8** %7
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %41
38: ; preds = %34
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%40 = call i32 @bad(i8* %39)
br label %41
41: ; preds = %38, %34
%42 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i8* %42, i8** %8
%43 = load i8*, i8** %8
%44 = icmp eq i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%47 = call i32 @bad(i8* %46)
br label %48
48: ; preds = %45, %41
%49 = load i8*, i8** %6
%50 = load i8, i8* %49
%51 = sext i8 %50 to i32
%52 = icmp eq i32 %51, 65
br i1 %52, label %53, label %54
53: ; preds = %48
br label %11
54: ; preds = %48
%55 = load i8*, i8** %7
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %57, 45
br i1 %58, label %59, label %77
59: ; preds = %54
%60 = load i8*, i8** %7
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp ne i32 %62, 69
br i1 %63, label %64, label %77
64: ; preds = %59
%65 = load i8*, i8** %7
%66 = load i8, i8* %65
%67 = sext i8 %66 to i32
%68 = icmp ne i32 %67, 83
br i1 %68, label %69, label %77
69: ; preds = %64
%70 = load i8*, i8** %7
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 65
br i1 %73, label %74, label %77
74: ; preds = %69
%75 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%76 = call i32 @bad(i8* %75)
br label %77
77: ; preds = %74, %69, %64, %59, %54
%78 = load i8*, i8** %5
%79 = call i32 @sscanf(i8* %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %9)
%80 = icmp ne i32 %79, 1
br i1 %80, label %81, label %84
81: ; preds = %77
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%83 = call i32 @bad(i8* %82)
br label %84
84: ; preds = %81, %77
store i32 255, i32* %10
%85 = load i8*, i8** %6
%86 = call i32 @sscanf(i8* %85, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %10)
%87 = icmp ne i32 %86, 1
br i1 %87, label %94, label %88
88: ; preds = %84
%89 = load i32, i32* %10
%90 = icmp ult i32 %89, 0
br i1 %90, label %94, label %91
91: ; preds = %88
%92 = load i32, i32* %10
%93 = icmp ugt i32 %92, 15
br i1 %93, label %94, label %97
94: ; preds = %91, %88, %84
%95 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%96 = call i32 @bad(i8* %95)
br label %97
97: ; preds = %94, %91
%98 = load i8*, i8** %8
%99 = load i32, i32* %9
%100 = load i32, i32* %10
%101 = load i8*, i8** %7
%102 = load i8, i8* %101
%103 = call i32 @new_symbol(i8* %98, i32 %99, i32 %100, i8 signext %102)
br label %11
104: ; preds = %11
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c" \09\0A\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [3 x i8] c"%d\00"
define void @load_symbols(i32* nocapture readnone %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i64 @fgets(i8* %6, i32 255, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %65, label %11
11: ; preds = %1
%12 = bitcast i32* %4 to i8*
%13 = bitcast i32* %5 to i8*
br label %14
14: ; preds = %11, %61
%15 = call i32 @strcpy(i8* %7, i8* %6)
%16 = call i8* @strtok(i8* %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 @bad(i8* %7)
br label %20
20: ; preds = %18, %14
%21 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i32 @bad(i8* %7)
br label %25
25: ; preds = %23, %20
%26 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @bad(i8* %7)
br label %30
30: ; preds = %28, %25
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @bad(i8* %7)
br label %35
35: ; preds = %33, %30
%36 = load i8, i8* %21
%37 = icmp eq i8 %36, 65
br i1 %37, label %61, label %38
38: ; preds = %35
%39 = load i8, i8* %26
switch i8 %39, label %40 [
i8 45, label %42
i8 69, label %42
i8 83, label %42
i8 65, label %42
]
40: ; preds = %38
%41 = call i32 @bad(i8* %7)
br label %42
42: ; preds = %38, %38, %38, %38, %40
%43 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%44 = icmp eq i32 %43, 1
br i1 %44, label %47, label %45
45: ; preds = %42
%46 = call i32 @bad(i8* %7)
br label %47
47: ; preds = %45, %42
store i32 255, i32* %5
%48 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %5)
%49 = icmp ne i32 %48, 1
%50 = load i32, i32* %5
%51 = icmp ugt i32 %50, 15
%52 = select i1 %49, i1 true, i1 %51
br i1 %52, label %53, label %56
53: ; preds = %47
%54 = call i32 @bad(i8* %7)
%55 = load i32, i32* %5
br label %56
56: ; preds = %47, %53
%57 = phi i32 [ %50, %47 ], [ %55, %53 ]
%58 = load i32, i32* %4
%59 = load i8, i8* %26
%60 = call i32 @new_symbol(i8* %31, i32 %58, i32 %57, i8 signext %59)
br label %61
61: ; preds = %35, %56
%62 = load i32, i32* @stdin
%63 = call i64 @fgets(i8* %6, i32 255, i32 %62)
%64 = icmp eq i64 %63, 0
br i1 %64, label %65, label %14
65: ; preds = %61, %1
ret void
}