#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*/ errno;
int /*<<< orphan*/ printf(char *, char *);
int read(int, char *, int);
char *strerror(int /*<<< orphan*/);
void myhandler(int fd, void *data) {
  char buf[128];
  int size;
  if ((size = read(fd, buf, sizeof(buf))) < 0) {
    printf("fail to read.error[%s]\n", strerror(errno));
    return;
  }
  printf("data[%s]\n", buf);
  return;
}


x86 assembly (clang, -O0):
<myhandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x80,%edx
call   1040 <read@plt>
mov    %eax,-0x94(%rbp)
cmp    $0x0,%eax
jge    1187 <myhandler+0x57>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %rax,%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
jmp    119a <myhandler+0x6a>
lea    -0x90(%rbp),%rsi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myhandler>:
sub    $0x88,%rsp
mov    %rsp,%rsi
mov    $0x80,%edx
call   1040 <read@plt>
test   %eax,%eax
js     115f <myhandler+0x2f>
lea    0xec9(%rip),%rdi
mov    %rsp,%rsi
call   1030 <printf@plt>
add    $0x88,%rsp
ret
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe8c(%rip),%rdi
mov    %rax,%rsi
add    $0x88,%rsp
jmp    1030 <printf@plt>

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

LLVM IR (-O2):
@.str = [24 x i8] c"fail to read.error[%s]\0A\00"
@errno = global i32 0
@.str.1 = [10 x i8] c"data[%s]\0A\00"
define void @myhandler(i32 %0, i8* nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 %0, i8* %4, i32 128)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %13
13: ; preds = %11, %7
ret void
}