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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int showfile(char *fname) {
  int fd, len;
  char buf[80];
  fd = open(fname, O_RDONLY);
  if (fd > 0) {
    do {
      len = read(fd, buf, 80);
      write(1, buf, len);
    } while (len > 0);
    close(fd);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<showfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e91(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b3 <showfile+0x73>
jmp    1170 <showfile+0x30>
mov    -0x14(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x50,%edx
call   1050 <read@plt>
mov    %eax,-0x18(%rbp)
lea    -0x70(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
cmpl   $0x0,-0x18(%rbp)
jg     1170 <showfile+0x30>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    11ba <showfile+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showfile>:
push   %rbp
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
jle    1194 <showfile+0x54>
mov    %eax,%r14d
mov    %rsp,%rbx
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
test   %ebp,%ebp
jg     1160 <showfile+0x20>
mov    %r14d,%edi
call   1040 <close@plt>
mov    $0x1,%eax
jmp    1196 <showfile+0x56>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @showfile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [80 x i8]
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %1
br label %13
13: ; preds = %20, %12
%14 = load i32, i32* %4
%15 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%16 = call i32 @read(i32 %14, i8* %15, i32 80)
store i32 %16, i32* %5
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* %5
%19 = call i32 @write(i32 1, i8* %17, i32 %18)
br label %20
20: ; preds = %13
%21 = load i32, i32* %5
%22 = icmp sgt i32 %21, 0
br i1 %22, label %13, label %23
23: ; preds = %20
%24 = load i32, i32* %4
%25 = call i32 @close(i32 %24)
store i32 1, i32* %2
br label %27
26: ; preds = %1
store i32 0, i32* %2
br label %27
27: ; preds = %26, %23
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @showfile(i8* nocapture %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %13
7: ; preds = %1, %7
%8 = call i32 @read(i32 %5, i8* %3, i32 80)
%9 = call i32 @write(i32 1, i8* %3, i32 %8)
%10 = icmp sgt i32 %8, 0
br i1 %10, label %7, label %11
11: ; preds = %7
%12 = tail call i32 @close(i32 %5)
br label %13
13: ; preds = %1, %11
%14 = phi i32 [ 1, %11 ], [ 0, %1 ]
ret i32 %14
}