#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 *);
scalar_t__ getc(int /*<<< orphan*/ *);
int load_program(char *p, char *fname) {
  FILE *fp;
  int i;
  if ((((*(&fp)) = fopen((fname), ("rb"))) == NULL) != 0 || fp == NULL)
    return 0;
  i = 0;
  do {
    *p = (char)getc(fp);
    p++;
    i++;
  } while (!feof(fp) && i < 10000);
  if (*(p - 2) == 0x1a)
    *(p - 2) = '\0';
  else
    *(p - 1) = '\0';
  fclose(fp);
  return 1;
}


x86 assembly (clang, -O0):
<load_program>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
cmp    $0x0,%eax
jne    1184 <load_program+0x44>
cmpq   $0x0,-0x20(%rbp)
jne    1190 <load_program+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1224 <load_program+0xe4>
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <getc@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x25(%rbp)
jne    11e3 <load_program+0xa3>
cmpl   $0x2710,-0x24(%rbp)
setl   %al
mov    %al,-0x25(%rbp)
mov    -0x25(%rbp),%al
test   $0x1,%al
jne    1197 <load_program+0x57>
mov    -0x10(%rbp),%rax
movsbl -0x2(%rax),%eax
cmp    $0x1a,%eax
jne    120c <load_program+0xcc>
mov    -0x10(%rbp),%rax
movb   $0x0,-0x2(%rax)
jmp    1214 <load_program+0xd4>
mov    -0x10(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_program>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rax
mov    %rdi,%rbx
lea    0xeae(%rip),%rsi
mov    %rax,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b8 <load_program+0x78>
mov    %rax,%r14
add    $0xfffffffffffffffe,%rbx
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r14,%rdi
call   1060 <getc@plt>
mov    %al,0x2(%rbx)
mov    %r14,%rdi
call   1040 <feof@plt>
add    $0x1,%rbx
test   %eax,%eax
jne    119b <load_program+0x5b>
lea    0x1(%r15),%eax
cmp    $0x270f,%r15d
mov    %eax,%r15d
jb     1170 <load_program+0x30>
cmpb   $0x1a,(%rbx)
lea    0x1(%rbx),%rax
cmove  %rbx,%rax
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    $0x1,%eax
jmp    11ba <load_program+0x7a>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i32 @load_program(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
%11 = zext i1 %10 to i32
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store i32 0, i32* %3
br label %51
17: ; preds = %13
store i32 0, i32* %7
br label %18
18: ; preds = %34, %17
%19 = load i32*, i32** %6
%20 = call i64 @getc(i32* %19)
%21 = trunc i64 %20 to i8
%22 = load i8*, i8** %4
store i8 %21, i8* %22
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i32 1
store i8* %24, i8** %4
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %27
27: ; preds = %18
%28 = load i32*, i32** %6
%29 = call i32 @feof(i32* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %34, label %31
31: ; preds = %27
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 10000
br label %34
34: ; preds = %31, %27
%35 = phi i1 [ false, %27 ], [ %33, %31 ]
br i1 %35, label %18, label %36
36: ; preds = %34
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i64 -2
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 26
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 -2
store i8 0, i8* %44
br label %48
45: ; preds = %36
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 -1
store i8 0, i8* %47
br label %48
48: ; preds = %45, %42
%49 = load i32*, i32** %6
%50 = call i32 @fclose(i32* %49)
store i32 1, i32* %3
br label %51
51: ; preds = %48, %16
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i32 @load_program(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %22, label %5
5: ; preds = %2, %5
%6 = phi i8* [ %10, %5 ], [ %0, %2 ]
%7 = phi i32 [ %11, %5 ], [ 0, %2 ]
%8 = tail call i64 @getc(i32* %3)
%9 = trunc i64 %8 to i8
store i8 %9, i8* %6
%10 = getelementptr inbounds i8, i8* %6, i64 1
%11 = add nuw nsw i32 %7, 1
%12 = tail call i32 @feof(i32* %3)
%13 = icmp eq i32 %12, 0
%14 = icmp ult i32 %7, 9999
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %5, label %16
16: ; preds = %5
%17 = getelementptr inbounds i8, i8* %6, i64 -1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 26
%20 = select i1 %19, i8* %17, i8* %6
store i8 0, i8* %20
%21 = tail call i32 @fclose(i32* %3)
br label %22
22: ; preds = %2, %16
%23 = phi i32 [ 1, %16 ], [ 0, %2 ]
ret i32 %23
}