#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*/ STDOUT_FILENO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ get_input_line(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ xfer_hex_file(int /*<<< orphan*/ *);
void load_text_file(void) {
  char buf[2000];
  char *label = "  Enter file name : ";
  FILE *fp;
  buf[0] = 0;
  write(STDOUT_FILENO, label, strlen(label));
  if (get_input_line(buf, 1999) == 0) {
    if ((fp = fopen(buf, "r")) != NULL) {
      printf("\nopened file \"%s\"\n", buf);
      xfer_hex_file(fp);
      fclose(fp);
      return;
    } else {
      printf("error opening file \"%s\"\n", buf);
    }
  }
  printf("error on input file \"%s\"\n", buf);
}


x86 assembly (clang, -O0):
<load_text_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x7f0,%rsp
lea    0xe7e(%rip),%rax
mov    %rax,-0x7d8(%rbp)
movb   $0x0,-0x7d0(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7ec(%rbp)
mov    -0x7d8(%rbp),%rax
mov    %rax,-0x7e8(%rbp)
mov    -0x7d8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x7ec(%rbp),%edi
mov    -0x7e8(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    -0x7d0(%rbp),%rdi
mov    $0x7cf,%esi
call   1080 <get_input_line@plt>
cmp    $0x0,%rax
jne    1254 <load_text_file+0xe4>
lea    -0x7d0(%rbp),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x7e0(%rbp)
cmp    $0x0,%rax
je     123c <load_text_file+0xcc>
lea    -0x7d0(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1060 <printf@plt>
mov    -0x7e0(%rbp),%rdi
call   1070 <xfer_hex_file@plt>
mov    -0x7e0(%rbp),%rdi
call   1040 <fclose@plt>
jmp    1267 <load_text_file+0xf7>
lea    -0x7d0(%rbp),%rsi
lea    0xde0(%rip),%rdi
call   1060 <printf@plt>
jmp    1254 <load_text_file+0xe4>
lea    -0x7d0(%rbp),%rsi
lea    0xde1(%rip),%rdi
call   1060 <printf@plt>
add    $0x7f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_text_file>:
push   %r14
push   %rbx
sub    $0x7d8,%rsp
movb   $0x0,(%rsp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%ebx
lea    0xe72(%rip),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rsp,%rdi
mov    $0x7cf,%esi
call   1080 <get_input_line@plt>
test   %rax,%rax
je     11c5 <load_text_file+0x55>
lea    0xe88(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
jmp    11fb <load_text_file+0x8b>
lea    0xe49(%rip),%rsi
mov    %rsp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1206 <load_text_file+0x96>
mov    %rax,%rbx
lea    0xe34(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1070 <xfer_hex_file@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x7d8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1d(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
jmp    11b4 <load_text_file+0x44>

LLVM IR (-O0):
@.str = [21 x i8] c" Enter file name : \00"
@STDOUT_FILENO = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"\0Aopened file \22%s\22\0A\00"
@.str.3 = [25 x i8] c"error opening file \22%s\22\0A\00"
@.str.4 = [26 x i8] c"error on input file \22%s\22\0A\00"
define void @load_text_file() {
%1 = alloca [2000 x i8]
%2 = alloca i8*
%3 = alloca i32*
store i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8** %2
%4 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
store i8 0, i8* %4
%5 = load i32, i32* @STDOUT_FILENO
%6 = load i8*, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
%9 = call i32 @write(i32 %5, i8* %6, i32 %8)
%10 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%11 = call i64 @get_input_line(i8* %10, i32 1999)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %28
13: ; preds = %0
%14 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %3
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = load i32*, i32** %3
%21 = call i32 @xfer_hex_file(i32* %20)
%22 = load i32*, i32** %3
%23 = call i32 @fclose(i32* %22)
br label %31
24: ; preds = %13
%25 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %25)
br label %27
27: ; preds = %24
br label %28
28: ; preds = %27, %0
%29 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %17
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c" Enter file name : \00"
@STDOUT_FILENO = global i32 0
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"\0Aopened file \22%s\22\0A\00"
@.str.3 = [25 x i8] c"error opening file \22%s\22\0A\00"
@.str.4 = [26 x i8] c"error on input file \22%s\22\0A\00"
define void @load_text_file() {
%1 = alloca [2000 x i8]
%2 = getelementptr inbounds [2000 x i8], [2000 x i8]* %1, i64 0, i64 0
store i8 0, i8* %2
%3 = load i32, i32* @STDOUT_FILENO
%4 = tail call i32 @strlen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @write(i32 %3, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i64 @get_input_line(i8* %2, i32 1999)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %0
%9 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%13 = call i32 @xfer_hex_file(i32* %9)
%14 = call i32 @fclose(i32* %9)
br label %19
15: ; preds = %8
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %17
17: ; preds = %15, %0
%18 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %19
19: ; preds = %17, %11
ret void
}