#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*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stdout;
void psh_history() {
  int row = 1;
  char temp[1024 + 1];
  FILE *history = fopen(".history", "r");
  while (fgets(temp, 1024 + 1, history) != NULL) {
    fprintf(stdout, "%d %s", row, temp);
    row++;
  }
  fclose(history);
}


x86 assembly (clang, -O0):
<psh_history>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x1,-0x4(%rbp)
lea    0xea7(%rip),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x418(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x418(%rbp),%rdx
mov    $0x401,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11bb <psh_history+0x7b>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    -0x410(%rbp),%rcx
lea    0xe63(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116c <psh_history+0x2c>
mov    -0x418(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psh_history>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x410,%rsp
lea    0xeaa(%rip),%rdi
lea    0xeac(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r15
mov    %rsp,%rdi
mov    $0x401,%esi
mov    %rax,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11b9 <psh_history+0x79>
mov    $0x1,%ebp
mov    0x2e5a(%rip),%r12
lea    0xe7e(%rip),%r14
mov    %rsp,%rbx
mov    (%r12),%edi
mov    %r14,%rsi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1050 <fprintf@plt>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    $0x401,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
jne    1190 <psh_history+0x50>
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c".history\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [6 x i8] c"%d %s\00"
define void @psh_history() {
%1 = alloca i32
%2 = alloca [1025 x i8]
%3 = alloca i32*
store i32 1, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %3
br label %5
5: ; preds = %10, %0
%6 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%7 = load i32*, i32** %3
%8 = call i32* @fgets(i8* %6, i32 1025, i32* %7)
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %17
10: ; preds = %5
%11 = load i32, i32* @stdout
%12 = load i32, i32* %1
%13 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %12, i8* %13)
%15 = load i32, i32* %1
%16 = add nsw i32 %15, 1
store i32 %16, i32* %1
br label %5
17: ; preds = %5
%18 = load i32*, i32** %3
%19 = call i32 @fclose(i32* %18)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c".history\00"
@.str.1 = [2 x i8] c"r\00"
@stdout = global i32 0
@.str.2 = [6 x i8] c"%d %s\00"
define void @psh_history() {
%1 = alloca [1025 x i8]
%2 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 0
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32* @fgets(i8* %2, i32 1025, i32* %3)
%5 = icmp eq i32* %4, null
br i1 %5, label %13, label %6
6: ; preds = %0, %6
%7 = phi i32 [ %10, %6 ], [ 1, %0 ]
%8 = load i32, i32* @stdout
%9 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %7, i8* %2)
%10 = add nuw nsw i32 %7, 1
%11 = call i32* @fgets(i8* %2, i32 1025, i32* %3)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %6
13: ; preds = %6, %0
%14 = call i32 @fclose(i32* %3)
ret void
}