#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 *, ...);
scalar_t__ read(int, char *, int);
void show_file(char *str) {
  int fd = open(str, O_RDONLY);
  char buf[128];
  printf("=================\n");
  while (read(fd, buf, sizeof(buf)) > 0)
    printf("%s", buf);
  close(fd);
  printf("\n=================\n");
}


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)
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jle    11aa <show_file+0x6a>
lea    -0x90(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1172 <show_file+0x32>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
lea    0xe4a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebp
lea    0xe92(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x80,%edx
call   1060 <read@plt>
test   %rax,%rax
jle    11c1 <show_file+0x71>
lea    0xe6e(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1060 <read@plt>
test   %rax,%rax
jg     11a0 <show_file+0x50>
mov    %ebp,%edi
call   1050 <close@plt>
lea    0xe34(%rip),%rdi
call   1030 <puts@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [19 x i8] c"=================\0A\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [20 x i8] c"\0A=================\0A\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
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %14, %1
%10 = load i32, i32* %3
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%12 = call i64 @read(i32 %10, i8* %11, i32 128)
%13 = icmp sgt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %9
17: ; preds = %9
%18 = load i32, i32* %3
%19 = call i32 @close(i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@str = [18 x i8] c"=================\00"
@str.3 = [19 x i8] c"\0A=================\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 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%7 = call i64 @read(i32 %4, i8* %5, i32 128)
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %1, %9
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%11 = call i64 @read(i32 %4, i8* %5, i32 128)
%12 = icmp sgt i64 %11, 0
br i1 %12, label %9, label %13
13: ; preds = %9, %1
%14 = call i32 @close(i32 %4)
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0))
ret void
}