#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[], char *envp[]) {
  char buf[1024];
  size_t nread;
  char history_file_path[100];
  char c;
  FILE *history_file = NULL;
  int i;
  sprintf(history_file_path, "%s/.%s\0", getenv("HOME"), "ucysh_history");
  printf("%s\n", history_file_path);
  history_file = fopen(history_file_path, "r");
  if (!history_file) {
    printf("No history file \n");
    exit(-1);
  }
  while ((nread = fread(buf, 1, sizeof buf, history_file)) > 0)
    fwrite(buf, 1, nread, stdout);
  fclose(history_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x4a0(%rbp)
lea    -0x490(%rbp),%rax
mov    %rax,-0x4b0(%rbp)
lea    0xe4b(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x4b0(%rbp),%rdi
mov    %rax,%rdx
lea    0xe2d(%rip),%rsi
lea    0xe33(%rip),%rcx
call   1080 <sprintf@plt>
lea    -0x490(%rbp),%rsi
lea    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x490(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x4a0(%rbp)
cmpq   $0x0,-0x4a0(%rbp)
jne    1234 <main+0xb4>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jmp    1239 <main+0xb9>
lea    -0x420(%rbp),%rdi
mov    -0x4a0(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jbe    128d <main+0x10d>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    0x2d64(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10a0 <fwrite@plt>
jmp    1239 <main+0xb9>
mov    -0x4a0(%rbp),%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x4b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x470,%rsp
lea    0xe75(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe61(%rip),%rsi
lea    0xe67(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rax,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1070 <fopen@plt>
test   %rax,%rax
je     1244 <main+0xc4>
mov    %rax,%r14
lea    0x70(%rsp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %rax,%rax
je     122d <main+0xad>
mov    0x2dea(%rip),%r15
lea    0x70(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   10a0 <fwrite@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r14,%rcx
call   1050 <fread@plt>
test   %rax,%rax
jne    1200 <main+0x80>
mov    %r14,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x470,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdd2(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"%s/.%s\00\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [14 x i8] c"ucysh_history\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [18 x i8] c"No history file \0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8**
%7 = alloca i8**
%8 = alloca [1024 x i8]
%9 = alloca i64
%10 = alloca [100 x i8]
%11 = alloca i8
%12 = alloca i32*
%13 = alloca i32
store i32 0, i32* %4
store i32 %0, i32* %5
store i8** %1, i8*** %6
store i8** %2, i8*** %7
store i32* null, i32** %12
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%15 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %10, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %20, i32** %12
%21 = load i32*, i32** %12
%22 = icmp ne i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %3
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
%25 = call i32 @exit(i32 -1)
unreachable
26: ; preds = %3
br label %27
27: ; preds = %32, %26
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%29 = load i32*, i32** %12
%30 = call i64 @fread(i8* %28, i32 1, i32 1024, i32* %29)
store i64 %30, i64* %9
%31 = icmp ugt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %27
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = load i64, i64* %9
%35 = load i32, i32* @stdout
%36 = call i32 @fwrite(i8* %33, i32 1, i64 %34, i32 %35)
br label %27
37: ; preds = %27
%38 = load i32*, i32** %12
%39 = call i32 @fclose(i32* %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s/.%s\00\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [14 x i8] c"ucysh_history\00"
@.str.4 = [2 x i8] c"r\00"
@stdout = global i32 0
@str = [17 x i8] c"No history file \00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca [1024 x i8]
%5 = alloca [100 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%8 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @puts(i8* %7)
%11 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = call i64 @fread(i8* %6, i32 1, i32 1024, i32* %11)
%15 = icmp eq i64 %14, 0
br i1 %15, label %25, label %19
16: ; preds = %3
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%18 = tail call i32 @exit(i32 -1)
unreachable
19: ; preds = %13, %19
%20 = phi i64 [ %23, %19 ], [ %14, %13 ]
%21 = load i32, i32* @stdout
%22 = call i32 @fwrite(i8* %6, i32 1, i64 %20, i32 %21)
%23 = call i64 @fread(i8* %6, i32 1, i32 1024, i32* %11)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %19
25: ; preds = %19, %13
%26 = call i32 @fclose(i32* %11)
ret i32 0
}