#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 /*<<< orphan*/ off_t;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ print_error(char *, int, int /*<<< orphan*/, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int copy_file_bytes(int dest, int src, off_t offset, size_t sz) {
  char buf[32768];
  int res, ret_sz;
  if (lseek(src, offset, SEEK_SET) == -1) {
    print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                "heads/master/common.c",
                77 - 1, errno, "lseek");
    return -1;
  }
  if (sz % 32768 != 0) {
    if ((res = read(src, buf, sz % 32768)) == -1) {
      print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                  "heads/master/common.c",
                  83 - 1, errno, "read");
      return -1;
    } else if (res != sz % 32768) {
      fprintf(stderr, "[-] File is too small\n");
      return -1;
    }
    if ((res = write(dest, buf, sz % 32768)) == -1) {
      print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                  "heads/master/common.c",
                  91 - 1, errno, "write");
      return -1;
    }
    sz -= sz % 32768;
  }
  while (sz > 0) {
    if ((res = read(src, buf, 32768)) == -1) {
      print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                  "heads/master/common.c",
                  100 - 1, errno, "read");
      return -1;
    } else if (res != 32768) {
      fprintf(stderr, "[-] File is too small\n");
      return -1;
    }
    if ((res = write(dest, buf, 32768)) == -1) {
      print_error("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                  "outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/"
                  "heads/master/common.c",
                  108 - 1, errno, "write");
      return -1;
    }
    sz -= 32768;
  }
  return 0;
}


x86 assembly (clang, -O0):
<copy_file_bytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8030,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    0x2e5b(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
jne    11b2 <copy_file_bytes+0x62>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    0xe6b(%rip),%rdi
mov    $0x4c,%esi
lea    0xee9(%rip),%rcx
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
mov    -0x18(%rbp),%rax
and    $0x7fff,%rax
cmp    $0x0,%rax
je     12cb <copy_file_bytes+0x17b>
mov    -0xc(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    -0x18(%rbp),%rax
and    $0x7fff,%rax
mov    %eax,%edx
call   1060 <read@plt>
mov    %eax,-0x8024(%rbp)
cmp    $0xffffffff,%eax
jne    121d <copy_file_bytes+0xcd>
mov    0x2de1(%rip),%rax
mov    (%rax),%edx
lea    0xe00(%rip),%rdi
mov    $0x52,%esi
lea    0xe84(%rip),%rcx
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
movslq -0x8024(%rbp),%rax
mov    -0x18(%rbp),%rcx
and    $0x7fff,%rcx
cmp    %rcx,%rax
je     1259 <copy_file_bytes+0x109>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
jmp    125e <copy_file_bytes+0x10e>
mov    -0x8(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    -0x18(%rbp),%rax
and    $0x7fff,%rax
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x8024(%rbp)
cmp    $0xffffffff,%eax
jne    12b5 <copy_file_bytes+0x165>
mov    0x2d49(%rip),%rax
mov    (%rax),%edx
lea    0xd68(%rip),%rdi
mov    $0x5a,%esi
lea    0xe08(%rip),%rcx
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
mov    -0x18(%rbp),%rcx
and    $0x7fff,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
jmp    12d0 <copy_file_bytes+0x180>
cmpq   $0x0,-0x18(%rbp)
jbe    13c4 <copy_file_bytes+0x274>
mov    -0xc(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    $0x8000,%edx
call   1060 <read@plt>
mov    %eax,-0x8024(%rbp)
cmp    $0xffffffff,%eax
jne    132b <copy_file_bytes+0x1db>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edx
lea    0xcf2(%rip),%rdi
mov    $0x63,%esi
lea    0xd76(%rip),%rcx
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
cmpl   $0x8000,-0x8024(%rbp)
je     135c <copy_file_bytes+0x20c>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
jmp    1361 <copy_file_bytes+0x211>
mov    -0x8(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    $0x8000,%edx
call   1040 <write@plt>
mov    %eax,-0x8024(%rbp)
cmp    $0xffffffff,%eax
jne    13b1 <copy_file_bytes+0x261>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edx
lea    0xc6c(%rip),%rdi
mov    $0x6b,%esi
lea    0xd0c(%rip),%rcx
call   1030 <print_error@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13cb <copy_file_bytes+0x27b>
mov    -0x18(%rbp),%rax
sub    $0x8000,%rax
mov    %rax,-0x18(%rbp)
jmp    12d0 <copy_file_bytes+0x180>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file_bytes>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x8008,%rsp
mov    %rcx,%rbx
mov    %esi,%r13d
mov    %edi,%r14d
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %esi,%edi
mov    %edx,%esi
mov    %eax,%edx
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     121e <copy_file_bytes+0xce>
mov    %rbx,%rbp
and    $0x7fff,%rbp
je     11d1 <copy_file_bytes+0x81>
mov    %rsp,%rsi
mov    %r13d,%edi
mov    %ebp,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     123f <copy_file_bytes+0xef>
cltq
cmp    %rax,%rbp
jne    1280 <copy_file_bytes+0x130>
mov    %rsp,%rsi
mov    %r14d,%edi
mov    %ebp,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     1297 <copy_file_bytes+0x147>
and    $0xffffffffffff8000,%rbx
xor    %r15d,%r15d
test   %rbx,%rbx
je     12dc <copy_file_bytes+0x18c>
mov    %rsp,%r12
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0x8000,%edx
call   1060 <read@plt>
cmp    $0x8000,%eax
jne    125d <copy_file_bytes+0x10d>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x8000,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     12b5 <copy_file_bytes+0x165>
add    $0xffffffffffff8000,%rbx
jne    11e0 <copy_file_bytes+0x90>
jmp    12dc <copy_file_bytes+0x18c>
mov    0x2db3(%rip),%rax
mov    (%rax),%edx
lea    0xdd2(%rip),%rdi
lea    0xe55(%rip),%rcx
mov    $0x4c,%esi
jmp    12d1 <copy_file_bytes+0x181>
mov    0x2d92(%rip),%rax
mov    (%rax),%edx
lea    0xdb1(%rip),%rdi
lea    0xe3a(%rip),%rcx
mov    $0x52,%esi
jmp    12d1 <copy_file_bytes+0x181>
cmp    $0xffffffff,%eax
jne    1280 <copy_file_bytes+0x130>
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
lea    0xd8e(%rip),%rdi
lea    0xe17(%rip),%rcx
mov    $0x63,%esi
jmp    12d1 <copy_file_bytes+0x181>
mov    0x2d59(%rip),%rax
mov    (%rax),%edi
lea    0xe05(%rip),%rsi
call   1070 <fprintf@plt>
jmp    12d6 <copy_file_bytes+0x186>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edx
lea    0xd59(%rip),%rdi
lea    0xdfe(%rip),%rcx
mov    $0x5a,%esi
jmp    12d1 <copy_file_bytes+0x181>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edx
lea    0xd3b(%rip),%rdi
lea    0xde0(%rip),%rcx
mov    $0x6b,%esi
call   1030 <print_error@plt>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/heads/master/common.c\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"[-] File is too small\0A\00"
@.str.4 = [6 x i8] c"write\00"
define i32 @copy_file_bytes(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca [32768 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i64 %3, i64* %9
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = load i32, i32* @SEEK_SET
%16 = call i32 @lseek(i32 %13, i32 %14, i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i32, i32* @errno
%20 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 76, i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
21: ; preds = %4
%22 = load i64, i64* %9
%23 = urem i64 %22, 32768
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %62
25: ; preds = %21
%26 = load i32, i32* %7
%27 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%28 = load i64, i64* %9
%29 = urem i64 %28, 32768
%30 = trunc i64 %29 to i32
%31 = call i32 @read(i32 %26, i8* %27, i32 %30)
store i32 %31, i32* %11
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load i32, i32* @errno
%35 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 82, i32 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
36: ; preds = %25
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = load i64, i64* %9
%40 = urem i64 %39, 32768
%41 = icmp ne i64 %38, %40
br i1 %41, label %42, label %45
42: ; preds = %36
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
45: ; preds = %36
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%49 = load i64, i64* %9
%50 = urem i64 %49, 32768
%51 = trunc i64 %50 to i32
%52 = call i32 @write(i32 %47, i8* %48, i32 %51)
store i32 %52, i32* %11
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %46
%55 = load i32, i32* @errno
%56 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 90, i32 %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
57: ; preds = %46
%58 = load i64, i64* %9
%59 = urem i64 %58, 32768
%60 = load i64, i64* %9
%61 = sub i64 %60, %59
store i64 %61, i64* %9
br label %62
62: ; preds = %57, %21
br label %63
63: ; preds = %89, %62
%64 = load i64, i64* %9
%65 = icmp ugt i64 %64, 0
br i1 %65, label %66, label %92
66: ; preds = %63
%67 = load i32, i32* %7
%68 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%69 = call i32 @read(i32 %67, i8* %68, i32 32768)
store i32 %69, i32* %11
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %66
%72 = load i32, i32* @errno
%73 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 99, i32 %72, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
74: ; preds = %66
%75 = load i32, i32* %11
%76 = icmp ne i32 %75, 32768
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load i32, i32* @stderr
%79 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
80: ; preds = %74
br label %81
81: ; preds = %80
%82 = load i32, i32* %6
%83 = getelementptr inbounds [32768 x i8], [32768 x i8]* %10, i64 0, i64 0
%84 = call i32 @write(i32 %82, i8* %83, i32 32768)
store i32 %84, i32* %11
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %89
86: ; preds = %81
%87 = load i32, i32* @errno
%88 = call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 107, i32 %87, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %5
br label %93
89: ; preds = %81
%90 = load i64, i64* %9
%91 = sub i64 %90, 32768
store i64 %91, i64* %9
br label %63
92: ; preds = %63
store i32 0, i32* %5
br label %93
93: ; preds = %92, %86, %77, %71, %54, %42, %33, %18
%94 = load i32, i32* %5
ret i32 %94
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/oblique/elf-infector/refs/heads/master/common.c\00"
@errno = global i32 0
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.3 = [23 x i8] c"[-] File is too small\0A\00"
@.str.4 = [6 x i8] c"write\00"
define i32 @copy_file_bytes(i32 %0, i32 %1, i32 %2, i64 %3) {
%5 = alloca [32768 x i8]
%6 = getelementptr inbounds [32768 x i8], [32768 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @lseek(i32 %1, i32 %2, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = load i32, i32* @errno
%12 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 76, i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %58
13: ; preds = %4
%14 = and i64 %3, 32767
%15 = icmp eq i64 %14, 0
br i1 %15, label %37, label %16
16: ; preds = %13
%17 = trunc i64 %14 to i32
%18 = call i32 @read(i32 %1, i8* %6, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @errno
%22 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 82, i32 %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %58
23: ; preds = %16
%24 = sext i32 %18 to i64
%25 = icmp eq i64 %14, %24
br i1 %25, label %29, label %26
26: ; preds = %23
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %58
29: ; preds = %23
%30 = call i32 @write(i32 %0, i8* %6, i32 %17)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* @errno
%34 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 90, i32 %33, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %58
35: ; preds = %29
%36 = and i64 %3, -32768
br label %37
37: ; preds = %35, %13
%38 = phi i64 [ %36, %35 ], [ %3, %13 ]
%39 = icmp eq i64 %38, 0
br i1 %39, label %58, label %42
40: ; preds = %51
%41 = icmp eq i64 %54, 0
br i1 %41, label %58, label %42
42: ; preds = %37, %40
%43 = phi i64 [ %54, %40 ], [ %38, %37 ]
%44 = call i32 @read(i32 %1, i8* %6, i32 32768)
switch i32 %44, label %48 [
i32 -1, label %45
i32 32768, label %51
]
45: ; preds = %42
%46 = load i32, i32* @errno
%47 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 99, i32 %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %58
48: ; preds = %42
%49 = load i32, i32* @stderr
%50 = tail call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %58
51: ; preds = %42
%52 = call i32 @write(i32 %0, i8* %6, i32 32768)
%53 = icmp eq i32 %52, -1
%54 = add i64 %43, -32768
br i1 %53, label %55, label %40
55: ; preds = %51
%56 = load i32, i32* @errno
%57 = tail call i32 @print_error(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 107, i32 %56, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %58
58: ; preds = %40, %37, %55, %48, %45, %32, %26, %20, %10
%59 = phi i32 [ -1, %10 ], [ -1, %20 ], [ -1, %26 ], [ -1, %32 ], [ -1, %45 ], [ -1, %48 ], [ -1, %55 ], [ 0, %37 ], [ 0, %40 ]
ret i32 %59
}