#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*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, short *, int);
int /*<<< orphan*/ write(int, short *, int);
int deliver_file(char *path, int fdout) {
  int fd = 0, bytes = 0;
  short buf[320];
  if ((fd = open(path, O_RDONLY))) {
    while ((bytes = read(fd, buf, 320))) {
      write(fdout, buf, bytes);
    }
    if (fd)
      close(fd);
  } else
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<deliver_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7d(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
je     11d1 <deliver_file+0x91>
jmp    1183 <deliver_file+0x43>
mov    -0x18(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    $0x140,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11ba <deliver_file+0x7a>
mov    -0x14(%rbp),%edi
lea    -0x2a0(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
jmp    1183 <deliver_file+0x43>
cmpl   $0x0,-0x18(%rbp)
je     11cc <deliver_file+0x8c>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
jmp    11dd <deliver_file+0x9d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e4 <deliver_file+0xa4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<deliver_file>:
push   %rbp
push   %r14
push   %rbx
sub    $0x280,%rsp
mov    %esi,%r14d
mov    0x2e93(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
je     11ab <deliver_file+0x6b>
mov    %eax,%ebp
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x140,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11a0 <deliver_file+0x60>
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x140,%edx
call   1050 <read@plt>
test   %eax,%eax
jne    1180 <deliver_file+0x40>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
jmp    11b0 <deliver_file+0x70>
mov    $0xffffffff,%eax
add    $0x280,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
define i32 @deliver_file(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [320 x i16]
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %31
13: ; preds = %2
br label %14
14: ; preds = %19, %13
%15 = load i32, i32* %6
%16 = getelementptr inbounds [320 x i16], [320 x i16]* %8, i64 0, i64 0
%17 = call i32 @read(i32 %15, i16* %16, i32 320)
store i32 %17, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %14
%20 = load i32, i32* %5
%21 = getelementptr inbounds [320 x i16], [320 x i16]* %8, i64 0, i64 0
%22 = load i32, i32* %7
%23 = call i32 @write(i32 %20, i16* %21, i32 %22)
br label %14
24: ; preds = %14
%25 = load i32, i32* %6
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i32, i32* %6
%29 = call i32 @close(i32 %28)
br label %30
30: ; preds = %27, %24
br label %32
31: ; preds = %2
store i32 -1, i32* %3
br label %33
32: ; preds = %30
store i32 0, i32* %3
br label %33
33: ; preds = %32, %31
%34 = load i32, i32* %3
ret i32 %34
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
define i32 @deliver_file(i8* nocapture %0, i32 %1) {
%3 = alloca [320 x i16]
%4 = bitcast [320 x i16]* %3 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* %0, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %8
8: ; preds = %2
%9 = getelementptr inbounds [320 x i16], [320 x i16]* %3, i64 0, i64 0
%10 = call i32 @read(i32 %6, i16* %9, i32 320)
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %8, %12
%13 = phi i32 [ %15, %12 ], [ %10, %8 ]
%14 = call i32 @write(i32 %1, i16* %9, i32 %13)
%15 = call i32 @read(i32 %6, i16* %9, i32 320)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %12
17: ; preds = %12, %8
%18 = tail call i32 @close(i32 %6)
br label %19
19: ; preds = %2, %17
%20 = phi i32 [ 0, %17 ], [ -1, %2 ]
ret i32 %20
}