#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*/ buf;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char *, int);
void show_file(char *str) {
  int fd = open(str, O_RDONLY);
  char buf[128];
  while (read(fd, buf, sizeof(buf)) > 0)
    printf("%s", buf);
  close(fd);
}


x86 assembly (clang, -O0):
<show_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e8e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    119a <show_file+0x5a>
lea    -0x90(%rbp),%rsi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
jmp    1164 <show_file+0x24>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x80,%edx
call   1050 <read@plt>
test   %rax,%rax
jle    119f <show_file+0x5f>
lea    0xe8a(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1050 <read@plt>
test   %rax,%rax
jg     1180 <show_file+0x40>
mov    %ebp,%edi
call   1040 <close@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"%s\00"
define void @show_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [128 x i8]
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
br label %8
8: ; preds = %13, %1
%9 = load i32, i32* %3
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i64 @read(i32 %9, i8* %10, i32 128)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %8
16: ; preds = %8
%17 = load i32, i32* %3
%18 = call i32 @close(i32 %17)
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [3 x i8] c"%s\00"
define void @show_file(i8* nocapture %0) {
%2 = alloca [128 x i8]
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = call i64 @read(i32 %4, i8* %5, i32 128)
%7 = icmp sgt i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1, %8
%9 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
%10 = call i64 @read(i32 %4, i8* %5, i32 128)
%11 = icmp sgt i64 %10, 0
br i1 %11, label %8, label %12
12: ; preds = %8, %1
%13 = call i32 @close(i32 %4)
ret void
}