#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 */
struct ReqInfo {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ Error_Quit(char *);
int read(int, char *, int);
int write(int, char *, int);
int Return_Resource(int conn, int resource, struct ReqInfo *reqinfo) {
  char c;
  int i;
  while ((i = read(resource, &c, 1))) {
    if (i < 0)
      Error_Quit("Error reading from file.");
    if (write(conn, &c, 1) < 1)
      Error_Quit("Error sending file.");
  }
  return 0;
}


x86 assembly (clang, -O0):
<Return_Resource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11a0 <Return_Resource+0x70>
cmpl   $0x0,-0x18(%rbp)
jge    1175 <Return_Resource+0x45>
lea    0xe90(%rip),%rdi
call   1050 <Error_Quit@plt>
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jge    119b <Return_Resource+0x6b>
lea    0xe83(%rip),%rdi
call   1050 <Error_Quit@plt>
jmp    1142 <Return_Resource+0x12>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Return_Resource>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%r15d
lea    0xf(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11ad <Return_Resource+0x7d>
lea    0xea3(%rip),%r14
lea    0xf(%rsp),%rbp
lea    0xeb0(%rip),%r12
jmp    1183 <Return_Resource+0x53>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %eax,%eax
je     11ad <Return_Resource+0x7d>
test   %eax,%eax
jns    118f <Return_Resource+0x5f>
mov    %r14,%rdi
call   1050 <Error_Quit@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
test   %eax,%eax
jg     1170 <Return_Resource+0x40>
mov    %r12,%rdi
call   1050 <Error_Quit@plt>
jmp    1170 <Return_Resource+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ReqInfo = type { i32 }
@.str = [25 x i8] c"Error reading from file.\00"
@.str.1 = [20 x i8] c"Error sending file.\00"
define i32 @Return_Resource(i32 %0, i32 %1, %struct.ReqInfo* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.ReqInfo*
%7 = alloca i8
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store %struct.ReqInfo* %2, %struct.ReqInfo** %6
br label %9
9: ; preds = %24, %3
%10 = load i32, i32* %5
%11 = call i32 @read(i32 %10, i8* %7, i32 1)
store i32 %11, i32* %8
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %25
13: ; preds = %9
%14 = load i32, i32* %8
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @Error_Quit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %13
%19 = load i32, i32* %4
%20 = call i32 @write(i32 %19, i8* %7, i32 1)
%21 = icmp slt i32 %20, 1
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @Error_Quit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
br label %9
25: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
%struct.ReqInfo = type { i32 }
@.str = [25 x i8] c"Error reading from file.\00"
@.str.1 = [20 x i8] c"Error sending file.\00"
define i32 @Return_Resource(i32 %0, i32 %1, %struct.ReqInfo* nocapture readnone %2) {
%4 = alloca i8
%5 = call i32 @read(i32 %1, i8* %4, i32 1)
%6 = icmp eq i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %3, %17
%8 = phi i32 [ %18, %17 ], [ %5, %3 ]
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @Error_Quit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = call i32 @write(i32 %0, i8* %4, i32 1)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = tail call i32 @Error_Quit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %12
%18 = call i32 @read(i32 %1, i8* %4, i32 1)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %7
20: ; preds = %17, %3
ret i32 0
}