#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;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ Error_Quit(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int send(int, char *, int, int /*<<< orphan*/);
int strlen(char *);
int Return_Resource(int conn, FILE *resource, struct ReqInfo *reqinfo) {
  int i;
  int n = 0;
  char buf[10001] = {0};
  while (!feof(resource)) {
    memset(buf, 0, 10000);
    n = fread(buf, 10000, 1, resource);
    i = strlen(buf);
    printf(buf);
    if (i < 0) {
      Error_Quit("Error reading from file.");
    }
    if (send(conn, buf, i, 0) < 1) {
      Error_Quit("Error sending file.");
    }
  }
  fclose(resource);
  return 0;
}


x86 assembly (clang, -O0):
<Return_Resource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2740,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x2740(%rbp),%rdi
xor    %esi,%esi
mov    $0x2711,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11ce <Return_Resource+0x4e>
jmp    125d <Return_Resource+0xdd>
lea    -0x2740(%rbp),%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1080 <memset@plt>
lea    -0x2740(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x2710,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x20(%rbp)
lea    -0x2740(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x2740(%rbp),%rdi
call   1070 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    122f <Return_Resource+0xaf>
lea    0xdd6(%rip),%rdi
call   10a0 <Error_Quit@plt>
mov    -0x4(%rbp),%edi
lea    -0x2740(%rbp),%rsi
mov    -0x1c(%rbp),%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0x1,%eax
jge    1258 <Return_Resource+0xd8>
lea    0xdc6(%rip),%rdi
call   10a0 <Error_Quit@plt>
jmp    11b0 <Return_Resource+0x30>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2740,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Return_Resource>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2718,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x2711,%edx
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r13,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     11ce <Return_Resource+0x4e>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x2718,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%rbp
lea    0xe28(%rip),%r15
lea    0xe3a(%rip),%r12
jmp    11fc <Return_Resource+0x7c>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    11b2 <Return_Resource+0x32>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x2710,%edx
call   1080 <memset@plt>
mov    %rbp,%rdi
mov    $0x2710,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   1030 <fread@plt>
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1070 <printf@plt>
test   %ebx,%ebx
jns    123e <Return_Resource+0xbe>
mov    %r15,%rdi
call   10a0 <Error_Quit@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
test   %eax,%eax
jg     11f0 <Return_Resource+0x70>
mov    %r12,%rdi
call   10a0 <Error_Quit@plt>
jmp    11f0 <Return_Resource+0x70>

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 i32
%8 = alloca i32
%9 = alloca [10001 x i8]
store i32 %0, i32* %4
store i32* %1, i32** %5
store %struct.ReqInfo* %2, %struct.ReqInfo** %6
store i32 0, i32* %8
%10 = bitcast [10001 x i8]* %9 to i8*
br label %11
11: ; preds = %38, %3
%12 = load i32*, i32** %5
%13 = call i32 @feof(i32* %12)
%14 = icmp ne i32 %13, 0
%15 = xor i1 %14, true
br i1 %15, label %16, label %39
16: ; preds = %11
%17 = getelementptr inbounds [10001 x i8], [10001 x i8]* %9, i64 0, i64 0
%18 = call i32 @memset(i8* %17, i32 0, i32 10000)
%19 = getelementptr inbounds [10001 x i8], [10001 x i8]* %9, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i32 @fread(i8* %19, i32 10000, i32 1, i32* %20)
store i32 %21, i32* %8
%22 = getelementptr inbounds [10001 x i8], [10001 x i8]* %9, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
store i32 %23, i32* %7
%24 = getelementptr inbounds [10001 x i8], [10001 x i8]* %9, i64 0, i64 0
%25 = call i32 @printf(i8* %24)
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @Error_Quit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
%31 = load i32, i32* %4
%32 = getelementptr inbounds [10001 x i8], [10001 x i8]* %9, i64 0, i64 0
%33 = load i32, i32* %7
%34 = call i32 @send(i32 %31, i8* %32, i32 %33, i32 0)
%35 = icmp slt i32 %34, 1
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @Error_Quit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %30
br label %11
39: ; preds = %11
%40 = load i32*, i32** %5
%41 = call i32 @fclose(i32* %40)
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* nocapture %1, %struct.ReqInfo* nocapture readnone %2) {
%4 = alloca [10001 x i8]
%5 = getelementptr inbounds [10001 x i8], [10001 x i8]* %4, i64 0, i64 0
%6 = call i32 @feof(i32* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %3, %21
%9 = call i32 @memset(i8* %5, i32 0, i32 10000)
%10 = call i32 @fread(i8* %5, i32 10000, i32 1, i32* %1)
%11 = call i32 @strlen(i8* %5)
%12 = call i32 @printf(i8* %5)
%13 = icmp slt i32 %11, 0
br i1 %13, label %14, label %16
14: ; preds = %8
%15 = call i32 @Error_Quit(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %8
%17 = call i32 @send(i32 %0, i8* %5, i32 %11, i32 0)
%18 = icmp slt i32 %17, 1
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @Error_Quit(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = call i32 @feof(i32* %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %8, label %24
24: ; preds = %21, %3
%25 = call i32 @fclose(i32* %1)
ret i32 0
}