#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 O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
scalar_t__ copy(int, int);
scalar_t__ lseek(int, long, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
long strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int in, out;
  long offset;
  if (argc < 3) {
    usage();
    return 1;
  }
  in = open(argv[1], 0 | O_RDONLY);
  out = open(argv[2], 0 | O_WRONLY);
  if (in < 0 || out < 0) {
    perror("bm");
    return 1;
  }
  if (4 <= argc) {
    offset = strtoul(argv[3], NULL, 0);
    if (lseek(out, offset, SEEK_SET) < 0) {
      perror("bm");
      return 1;
    }
  }
  if (copy(in, out) < 0) {
    perror("bm");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1193 <main+0x33>
mov    $0x0,%al
call   1050 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x12c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11df <main+0x7f>
cmpl   $0x0,-0x18(%rbp)
jge    11f7 <main+0x97>
lea    0xe1a(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x12c>
mov    $0x4,%eax
cmp    -0x8(%rbp),%eax
jg     1258 <main+0xf8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2dae(%rip),%rax
mov    (%rax),%edx
call   1030 <lseek@plt>
cmp    $0x0,%rax
jge    1253 <main+0xf3>
lea    0xdbe(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x12c>
jmp    1258 <main+0xf8>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   1040 <copy@plt>
cmp    $0x0,%rax
jge    1285 <main+0x125>
lea    0xd8c(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    128c <main+0x12c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jg     117a <main+0x1a>
xor    %eax,%eax
call   1050 <usage@plt>
mov    $0x1,%eax
jmp    11ee <main+0x8e>
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
mov    0x2e5e(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    0x2e29(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%r15d
or     %r14d,%eax
js     11f9 <main+0x99>
cmp    $0x4,%ebp
jb     11d9 <main+0x79>
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtoul@plt>
mov    0x2e11(%rip),%rcx
mov    (%rcx),%edx
mov    %r15d,%edi
mov    %rax,%rsi
call   1030 <lseek@plt>
test   %rax,%rax
js     11f9 <main+0x99>
mov    %r14d,%edi
mov    %r15d,%esi
call   1040 <copy@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
js     11f9 <main+0x99>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe00(%rip),%rdi
call   1070 <perror@plt>
jmp    1173 <main+0x13>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str = [3 x i8] c"bm\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 (...) @usage()
store i32 1, i32* %3
br label %57
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDONLY
%18 = or i32 0, %17
%19 = call i32 @open(i8* %16, i32 %18)
store i32 %19, i32* %6
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_WRONLY
%24 = or i32 0, %23
%25 = call i32 @open(i8* %22, i32 %24)
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %13
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28, %13
%32 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %57
33: ; preds = %28
%34 = load i32, i32* %4
%35 = icmp sle i32 4, %34
br i1 %35, label %36, label %49
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 3
%39 = load i8*, i8** %38
%40 = call i64 @strtoul(i8* %39, i32* null, i32 0)
store i64 %40, i64* %8
%41 = load i32, i32* %7
%42 = load i64, i64* %8
%43 = load i32, i32* @SEEK_SET
%44 = call i64 @lseek(i32 %41, i64 %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %36
%47 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %57
48: ; preds = %36
br label %49
49: ; preds = %48, %33
%50 = load i32, i32* %6
%51 = load i32, i32* %7
%52 = call i64 @copy(i32 %50, i32 %51)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %56
54: ; preds = %49
%55 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %57
56: ; preds = %49
store i32 0, i32* %3
br label %57
57: ; preds = %56, %54, %46, %31, %11
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@.str = [3 x i8] c"bm\00"
@SEEK_SET = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %35
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i8* %8, i32 %9)
%11 = getelementptr inbounds i8*, i8** %1, i64 2
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_WRONLY
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = or i32 %14, %10
%16 = icmp sgt i32 %15, -1
br i1 %16, label %19, label %17
17: ; preds = %6
%18 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %35
19: ; preds = %6
%20 = icmp ugt i32 %0, 3
br i1 %20, label %21, label %30
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = tail call i64 @strtoul(i8* nocapture %23, i32* null, i32 0)
%25 = load i32, i32* @SEEK_SET
%26 = tail call i64 @lseek(i32 %14, i64 %24, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %21
%29 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %35
30: ; preds = %21, %19
%31 = tail call i64 @copy(i32 %10, i32 %14)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %30, %33, %28, %17, %4
%36 = phi i32 [ 1, %4 ], [ 1, %17 ], [ 1, %28 ], [ 1, %33 ], [ 0, %30 ]
ret i32 %36
}