#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 scalar_t__ ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ die(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
char *tracecmd_get_tracing_file(char const *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
void show_file(const char *name) {
  char buf[BUFSIZ];
  char *path;
  FILE *fp;
  ssize_t n;
  path = tracecmd_get_tracing_file(name);
  fp = fopen(path, "r");
  if (!fp)
    die("reading %s", path);
  tracecmd_put_tracing_file(path);
  do {
    n = fread(buf, 1, BUFSIZ, fp);
    if (n > 0)
      fwrite(buf, 1, n, stdout);
  } while (n > 0);
  fclose(fp);
}


x86 assembly (clang, -O0):
<show_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe40(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11e4 <show_file+0x74>
mov    -0x20(%rbp),%rsi
lea    0xe23(%rip),%rdi
call   1080 <die@plt>
mov    -0x20(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    -0x38(%rbp),%rdi
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jle    1232 <show_file+0xc2>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    0x2db2(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   1090 <fwrite@plt>
jmp    1237 <show_file+0xc7>
cmpq   $0x0,-0x30(%rbp)
jg     11ed <show_file+0x7d>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    0x2e5e(%rip),%r12
mov    (%r12),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1060 <tracecmd_get_tracing_file@plt>
mov    %rax,%r15
lea    0xe5a(%rip),%rsi
mov    %rax,%rdi
call   1070 <fopen@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11c5 <show_file+0x55>
lea    0xe45(%rip),%rdi
mov    %r15,%rsi
call   1080 <die@plt>
mov    %r15,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jle    121c <show_file+0xac>
mov    0x2deb(%rip),%r15
nopl   (%rax)
mov    (%r15),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1090 <fwrite@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1040 <fread@plt>
test   %rax,%rax
jg     11f0 <show_file+0x80>
mov    %r14,%rdi
call   1050 <fclose@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"reading %s\00"
@stdout = global i32 0
define void @show_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
store i8* %0, i8** %2
%8 = load i32, i32* @BUFSIZ
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i8*, i8** %2
%13 = call i8* @tracecmd_get_tracing_file(i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp ne i32* %16, null
br i1 %17, label %21, label %18
18: ; preds = %1
%19 = load i8*, i8** %5
%20 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %18, %1
%22 = load i8*, i8** %5
%23 = call i32 @tracecmd_put_tracing_file(i8* %22)
br label %24
24: ; preds = %35, %21
%25 = load i32, i32* @BUFSIZ
%26 = load i32*, i32** %6
%27 = call i64 @fread(i8* %11, i32 1, i32 %25, i32* %26)
store i64 %27, i64* %7
%28 = load i64, i64* %7
%29 = icmp sgt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %24
%31 = load i64, i64* %7
%32 = load i32, i32* @stdout
%33 = call i32 @fwrite(i8* %11, i32 1, i64 %31, i32 %32)
br label %34
34: ; preds = %30, %24
br label %35
35: ; preds = %34
%36 = load i64, i64* %7
%37 = icmp sgt i64 %36, 0
br i1 %37, label %24, label %38
38: ; preds = %35
%39 = load i32*, i32** %6
%40 = call i32 @fclose(i32* %39)
%41 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"reading %s\00"
@stdout = global i32 0
define void @show_file(i8* %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i8* @tracecmd_get_tracing_file(i8* %0)
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %10
10: ; preds = %8, %1
%11 = tail call i32 @tracecmd_put_tracing_file(i8* %5)
%12 = load i32, i32* @BUFSIZ
%13 = call i64 @fread(i8* %4, i32 1, i32 %12, i32* %6)
%14 = icmp sgt i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %10, %15
%16 = phi i64 [ %20, %15 ], [ %13, %10 ]
%17 = load i32, i32* @stdout
%18 = call i32 @fwrite(i8* %4, i32 1, i64 %16, i32 %17)
%19 = load i32, i32* @BUFSIZ
%20 = call i64 @fread(i8* %4, i32 1, i32 %19, i32* %6)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %15, label %22
22: ; preds = %15, %10
%23 = call i32 @fclose(i32* %6)
ret void
}