#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*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ write(int, char *, int);
void showdata(char *fname, int fd) {
  char buf[1024];
  int n;
  printf("%s: ", fname);
  fflush(stdout);
  n = read(fd, buf, 1024);
  if (n == -1) {
    perror("read() failed");
    exit(5);
  };
  write(1, buf, n);
  write(1, "\n", 1);
}


x86 assembly (clang, -O0):
<showdata>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1050 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    11cd <showdata+0x6d>
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
mov    $0x5,%edi
call   1080 <exit@plt>
lea    -0x410(%rbp),%rsi
mov    -0x414(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    $0x1,%edx
lea    0xe23(%rip),%rsi
mov    %edx,%edi
call   1030 <write@plt>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<showdata>:
push   %rbx
sub    $0x400,%rsp
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x400,%edx
call   1050 <read@plt>
cmp    $0xffffffff,%eax
je     11c8 <showdata+0x68>
mov    %rsp,%rsi
mov    $0x1,%edi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe62(%rip),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
add    $0x400,%rsp
pop    %rbx
jmp    1030 <write@plt>
lea    0xe36(%rip),%rdi
call   1070 <perror@plt>
mov    $0x5,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s: \00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"read() failed\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @showdata(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32, i32* @stdout
%10 = call i32 @fflush(i32 %9)
%11 = load i32, i32* %4
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 1024)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 @exit(i32 5)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%21 = load i32, i32* %6
%22 = call i32 @write(i32 1, i8* %20, i32 %21)
%23 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s: \00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"read() failed\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @showdata(i8* %0, i32 %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @stdout
%7 = tail call i32 @fflush(i32 %6)
%8 = call i32 @read(i32 %1, i8* %4, i32 1024)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 5)
unreachable
13: ; preds = %2
%14 = call i32 @write(i32 1, i8* %4, i32 %8)
%15 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret void
}