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

/* Variables and functions */
int EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, unsigned int, int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ stderr;
unsigned char *rd_24section(char *filename) {
  FILE *input;
  int i, c;
  unsigned char *string;
  unsigned int24;
  if ((input = fopen(filename, "rb")) == NULL) {
    fprintf(stderr, "could not open %s, returning NULL file\n", filename);
    return NULL;
  }
  for (int24 = i = 0; i < 3; i++) {
    c = getc(input);
    if (c == EOF)
      return NULL;
    int24 = (int24 << 8) + c;
  }
  if ((string = (unsigned char *)malloc((size_t)int24)) == NULL) {
    fprintf(stderr, "not allocate memory .. FATAL ERROR\n");
    exit(8);
  }
  string[0] = (int24 >> 16) & 255;
  string[1] = (int24 >> 8) & 255;
  string[2] = (int24)&255;
  i = fread(string + 3, sizeof(unsigned char), int24 - 3, input);
  fclose(input);
  if (i == int24 - 3)
    return string;
  fprintf(stderr, "could not read %s .. FATAL ERROR\n", filename);
  exit(8);
}


x86 assembly (clang, -O0):
<rd_24section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11c2 <rd_24section+0x52>
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    12fb <rd_24section+0x18b>
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    121f <rd_24section+0xaf>
mov    -0x18(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%eax
jne    1205 <rd_24section+0x95>
movq   $0x0,-0x8(%rbp)
jmp    12fb <rd_24section+0x18b>
mov    -0x2c(%rbp),%eax
shl    $0x8,%eax
add    -0x20(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d0 <rd_24section+0x60>
mov    -0x2c(%rbp),%eax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1258 <rd_24section+0xe8>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1080 <exit@plt>
mov    -0x2c(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x2c(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x28(%rbp),%rdi
add    $0x3,%rdi
mov    -0x2c(%rbp),%edx
sub    $0x3,%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    -0x2c(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jne    12d6 <rd_24section+0x166>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12fb <rd_24section+0x18b>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rd_24section>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xe7e(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c9 <rd_24section+0x59>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <getc@plt>
mov    0x2e4a(%rip),%r12
cmp    (%r12),%eax
je     11c5 <rd_24section+0x55>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r12),%eax
je     11c5 <rd_24section+0x55>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r12),%eax
jne    11f1 <rd_24section+0x81>
xor    %ebp,%ebp
jmp    11e5 <rd_24section+0x75>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe2a(%rip),%rsi
xor    %ebp,%ebp
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
shl    $0x8,%ebp
add    %ebp,%r15d
shl    $0x8,%r15d
add    %r15d,%eax
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     1270 <rd_24section+0x100>
mov    %rax,%rbp
mov    %r15,%rdx
mov    %edx,%eax
shr    $0x10,%eax
mov    %al,0x0(%rbp)
mov    %dh,0x1(%rbp)
mov    %dl,0x2(%rbp)
mov    %rbp,%rdi
add    $0x3,%rdi
add    $0xfffffffd,%edx
mov    $0x1,%esi
mov    %rdx,%r12
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    %r12d,%r15d
je     11e5 <rd_24section+0x75>
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1080 <exit@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x8,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"could not open %s, returning NULL file\0A\00"
@EOF = global i32 0
@.str.2 = [36 x i8] c"not allocate memory .. FATAL ERROR\0A\00"
@.str.3 = [34 x i8] c"could not read %s .. FATAL ERROR\0A\00"
define i8* @rd_24section(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i8* null, i8** %2
br label %82
16: ; preds = %1
store i32 0, i32* %5
store i32 0, i32* %8
br label %17
17: ; preds = %32, %16
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 3
br i1 %19, label %20, label %35
20: ; preds = %17
%21 = load i32*, i32** %4
%22 = call i32 @getc(i32* %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %20
store i8* null, i8** %2
br label %82
27: ; preds = %20
%28 = load i32, i32* %8
%29 = shl i32 %28, 8
%30 = load i32, i32* %6
%31 = add i32 %29, %30
store i32 %31, i32* %8
br label %32
32: ; preds = %27
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %17
35: ; preds = %17
%36 = load i32, i32* %8
%37 = zext i32 %36 to i64
%38 = call i64 @malloc(i64 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %7
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i32, i32* @stderr
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%44 = call i32 @exit(i32 8)
unreachable
45: ; preds = %35
%46 = load i32, i32* %8
%47 = lshr i32 %46, 16
%48 = and i32 %47, 255
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %7
%51 = getelementptr inbounds i8, i8* %50, i64 0
store i8 %49, i8* %51
%52 = load i32, i32* %8
%53 = lshr i32 %52, 8
%54 = and i32 %53, 255
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %7
%57 = getelementptr inbounds i8, i8* %56, i64 1
store i8 %55, i8* %57
%58 = load i32, i32* %8
%59 = and i32 %58, 255
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %7
%62 = getelementptr inbounds i8, i8* %61, i64 2
store i8 %60, i8* %62
%63 = load i8*, i8** %7
%64 = getelementptr inbounds i8, i8* %63, i64 3
%65 = load i32, i32* %8
%66 = sub i32 %65, 3
%67 = load i32*, i32** %4
%68 = call i32 @fread(i8* %64, i32 1, i32 %66, i32* %67)
store i32 %68, i32* %5
%69 = load i32*, i32** %4
%70 = call i32 @fclose(i32* %69)
%71 = load i32, i32* %5
%72 = load i32, i32* %8
%73 = sub i32 %72, 3
%74 = icmp eq i32 %71, %73
br i1 %74, label %75, label %77
75: ; preds = %45
%76 = load i8*, i8** %7
store i8* %76, i8** %2
br label %82
77: ; preds = %45
%78 = load i32, i32* @stderr
%79 = load i8*, i8** %3
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %79)
%81 = call i32 @exit(i32 8)
unreachable
82: ; preds = %75, %26, %12
%83 = load i8*, i8** %2
ret i8* %83
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [40 x i8] c"could not open %s, returning NULL file\0A\00"
@EOF = global i32 0
@.str.2 = [36 x i8] c"not allocate memory .. FATAL ERROR\0A\00"
@.str.3 = [34 x i8] c"could not read %s .. FATAL ERROR\0A\00"
define i8* @rd_24section(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = tail call i32 @getc(i32* %2)
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %49, label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %49
11: ; preds = %4
%12 = tail call i32 @getc(i32* %2)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %49, label %15
15: ; preds = %11
%16 = tail call i32 @getc(i32* %2)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %49, label %19
19: ; preds = %15
%20 = shl i32 %5, 8
%21 = add i32 %12, %20
%22 = shl i32 %21, 8
%23 = add i32 %16, %22
%24 = zext i32 %23 to i64
%25 = tail call i64 @malloc(i64 %24)
%26 = inttoptr i64 %25 to i8*
%27 = icmp eq i64 %25, 0
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 8)
unreachable
32: ; preds = %19
%33 = lshr i32 %23, 16
%34 = trunc i32 %33 to i8
store i8 %34, i8* %26
%35 = lshr i32 %23, 8
%36 = trunc i32 %35 to i8
%37 = getelementptr inbounds i8, i8* %26, i64 1
store i8 %36, i8* %37
%38 = trunc i32 %23 to i8
%39 = getelementptr inbounds i8, i8* %26, i64 2
store i8 %38, i8* %39
%40 = getelementptr inbounds i8, i8* %26, i64 3
%41 = add i32 %23, -3
%42 = tail call i32 @fread(i8* %40, i32 1, i32 %41, i32* %2)
%43 = tail call i32 @fclose(i32* %2)
%44 = icmp eq i32 %42, %41
br i1 %44, label %49, label %45
45: ; preds = %32
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%48 = tail call i32 @exit(i32 8)
unreachable
49: ; preds = %4, %11, %15, %32, %8
%50 = phi i8* [ null, %8 ], [ %26, %32 ], [ null, %15 ], [ null, %11 ], [ null, %4 ]
ret i8* %50
}