#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 fallback_rw(int, int, char *, int);
int /*<<< orphan*/ perror(char *);
int copy(int from_fd, int to_fd, int chunk_size) {
  static int fallback = 0;
  char buf[chunk_size];
  int res = fallback_rw(from_fd, to_fd, buf, chunk_size);
  if (res < 0) {
    perror("Error in fallback_rw");
    return -1;
  }
  return res;
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%ecx
call   1030 <fallback_rw@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    118d <copy+0x6d>
lea    0xe8b(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
jmp    119a <copy+0x7a>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %rbp
mov    %rsp,%rbp
mov    %edx,%ecx
mov    %edx,%eax
mov    %rsp,%rdx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdx
mov    %rdx,%rsp
call   1030 <fallback_rw@plt>
test   %eax,%eax
js     1147 <copy+0x27>
mov    %rbp,%rsp
pop    %rbp
ret
lea    0xeb2(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%eax
jmp    1142 <copy+0x22>

LLVM IR (-O0):
@copy.fallback = internal global i32 0
@.str = [21 x i8] c"Error in fallback_rw\00"
define i32 @copy(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%12 = load i32, i32* %7
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %8
%15 = alloca i8, i64 %13
store i64 %13, i64* %9
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = call i32 @fallback_rw(i32 %16, i32 %17, i8* %15, i32 %18)
store i32 %19, i32* %10
%20 = load i32, i32* %10
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %3
%23 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
store i32 1, i32* %11
br label %26
24: ; preds = %3
%25 = load i32, i32* %10
store i32 %25, i32* %4
store i32 1, i32* %11
br label %26
26: ; preds = %24, %22
%27 = load i8*, i8** %8
%28 = load i32, i32* %4
ret i32 %28
}

LLVM IR (-O2):
@.str = [21 x i8] c"Error in fallback_rw\00"
define i32 @copy(i32 %0, i32 %1, i32 %2) {
%4 = zext i32 %2 to i64
%5 = alloca i8, i64 %4
%6 = call i32 @fallback_rw(i32 %0, i32 %1, i8* %5, i32 %2)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ -1, %8 ], [ %6, %3 ]
ret i32 %11
}