#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 ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, char *);
int read(int, char *, int);
void do_use_fd(int fd) {
  char buf[64];
  bzero(buf, sizeof(buf));
  ssize_t i = read(fd, buf, sizeof(buf));
  if (i == -1) {
    perror("read");
    return;
  }
  if (i > 0) {
    printf("read from client#%d%s\n", fd, buf);
  }
}


x86 assembly (clang, -O0):
<do_use_fd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
mov    $0x40,%esi
call   1060 <bzero@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x40,%edx
call   1040 <read@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1188 <do_use_fd+0x48>
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
jmp    11a5 <do_use_fd+0x65>
cmpl   $0x0,-0x54(%rbp)
jle    11a5 <do_use_fd+0x65>
mov    -0x4(%rbp),%esi
lea    -0x50(%rbp),%rdx
lea    0xe65(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_use_fd>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x40,%esi
call   1060 <bzero@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <read@plt>
cmp    $0xffffffff,%eax
je     118a <do_use_fd+0x4a>
test   %eax,%eax
jle    1182 <do_use_fd+0x42>
lea    0xe8d(%rip),%rdi
mov    %rsp,%rdx
mov    %ebx,%esi
call   1030 <printf@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6f(%rip),%rdi
add    $0x48,%rsp
pop    %rbx
pop    %r14
jmp    1050 <perror@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"read\00"
@.str.1 = [23 x i8] c"read from client#%d%s\0A\00"
define void @do_use_fd(i32 %0) {
%2 = alloca i32
%3 = alloca [64 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%6 = call i32 @bzero(i8* %5, i32 64)
%7 = load i32, i32* %2
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%9 = call i32 @read(i32 %7, i8* %8, i32 64)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %21
14: ; preds = %1
%15 = load i32, i32* %4
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %2
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %19)
br label %21
21: ; preds = %12, %17, %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"read\00"
@.str.1 = [23 x i8] c"read from client#%d%s\0A\00"
define void @do_use_fd(i32 %0) {
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%4 = call i32 @bzero(i8* %3, i32 64)
%5 = call i32 @read(i32 %0, i8* %3, i32 64)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %13
9: ; preds = %1
%10 = icmp sgt i32 %5, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %0, i8* %3)
br label %13
13: ; preds = %9, %11, %7
ret void
}