#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*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sleep(int);
void read_event(int fd, short ev, void *data) {
  char buf[80];
  int n;
  int i;
  printf("Can read now .. give it a moment though\n");
  sleep(5);
  n = read(fd, buf, 80);
  if (n < 0)
    exit(1);
  for (i = 0; i < n; i++)
    printf(" %02x", buf[i] & 0xff);
  printf("\n");
}


x86 assembly (clang, -O0):
<read_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %si,%ax
mov    %edi,-0x4(%rbp)
mov    %ax,-0x6(%rbp)
mov    %rdx,-0x10(%rbp)
lea    0xea3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x5,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x50,%edx
call   1040 <read@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    1196 <read_event+0x56>
mov    $0x1,%edi
call   1050 <exit@plt>
movl   $0x0,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11d4 <read_event+0x94>
movslq -0x68(%rbp),%rax
movsbl -0x60(%rbp,%rax,1),%esi
and    $0xff,%esi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    119d <read_event+0x5d>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_event>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %edi,%ebx
lea    0xe94(%rip),%rdi
call   1040 <puts@plt>
mov    $0x5,%edi
call   1080 <sleep@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x50,%edx
call   1060 <read@plt>
test   %eax,%eax
js     11da <read_event+0x7a>
je     11c7 <read_event+0x67>
mov    %eax,%r15d
lea    0xe60(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl (%rsp,%rbx,1),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11b0 <read_event+0x50>
mov    $0xa,%edi
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <putchar@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [41 x i8] c"Can read now .. give it a moment though\0A\00"
@.str.1 = [6 x i8] c" %02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @read_event(i32 %0, i16 signext %1, i8* %2) {
%4 = alloca i32
%5 = alloca i16
%6 = alloca i8*
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %4
store i16 %1, i16* %5
store i8* %2, i8** %6
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @sleep(i32 5)
%12 = load i32, i32* %4
%13 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%14 = call i32 @read(i32 %12, i8* %13, i32 80)
store i32 %14, i32* %8
%15 = load i32, i32* %8
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %3
store i32 0, i32* %9
br label %20
20: ; preds = %32, %19
%21 = load i32, i32* %9
%22 = load i32, i32* %8
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %35
24: ; preds = %20
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = and i32 %29, 255
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %24
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %20
35: ; preds = %20
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [6 x i8] c" %02x\00"
@str = [40 x i8] c"Can read now .. give it a moment though\00"
define void @read_event(i32 %0, i16 signext %1, i8* nocapture readnone %2) {
%4 = alloca [80 x i8]
%5 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @sleep(i32 5)
%8 = call i32 @read(i32 %0, i8* %5, i32 80)
%9 = icmp slt i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %3
%11 = icmp eq i32 %8, 0
br i1 %11, label %24, label %12
12: ; preds = %10
%13 = zext i32 %8 to i64
br label %16
14: ; preds = %3
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %12, %16
%17 = phi i64 [ 0, %12 ], [ %22, %16 ]
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = add nuw nsw i64 %17, 1
%23 = icmp eq i64 %22, %13
br i1 %23, label %24, label %16
24: ; preds = %16, %10
%25 = tail call i32 @putchar(i32 10)
ret void
}