#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 void *off_t;
typedef int /*<<< orphan*/ in_size;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ S_IRWXU;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
char *malloc(int);
int open(char *, int, ...);
int pread(int, char *, size_t, void *);
int /*<<< orphan*/ pwrite(int, char *, int, void *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void *strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  char *buf;
  int in_fd, out_fd, nread;
  off_t in_offst, out_offst;
  size_t in_size, out_size;
  if (argc != 7) {
    fprintf(stderr,
            "Usage: %s <input file, offset, size>"
            " <output file, offset, size>",
            argv[0]);
    exit(EXIT_FAILURE);
  }
  in_fd = open(argv[1], O_RDONLY);
  if (in_fd < 0) {
    fprintf(stderr, "Unable to open %s: %s\n", argv[1], strerror(errno));
    exit(EXIT_FAILURE);
  }
  out_fd = open(argv[4], O_CREAT | O_WRONLY, S_IRWXU);
  if (out_fd < 0) {
    fprintf(stderr, "Unable to write %s: %s\n", argv[4], strerror(errno));
    exit(EXIT_FAILURE);
  }
  in_offst = strtol(argv[2], NULL, 10);
  out_offst = strtol(argv[5], NULL, 10);
  in_size = strtol(argv[3], NULL, 10);
  out_size = strtol(argv[6], NULL, 10);
  buf = malloc(sizeof(in_size));
  if (in_size < out_size)
    out_size = in_size;
  nread = pread(in_fd, buf, in_size, in_offst);
  pwrite(out_fd, buf, nread, out_offst);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x7,-0x8(%rbp)
je     11cc <main+0x4c>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123d <main+0xbd>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2d4b(%rip),%rax
or     (%rax),%esi
mov    0x2d82(%rip),%rax
mov    (%rax),%edx
mov    $0x0,%al
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    12c0 <main+0x140>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xdad(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x48(%rbp)
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x48(%rbp),%rax
jae    134c <main+0x1cc>
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1080 <pread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1060 <pwrite@plt>
mov    0x2c33(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x7,%edi
jne    1276 <main+0xf6>
mov    0x8(%rbx),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     1292 <main+0x112>
mov    %eax,%r14d
mov    0x20(%rbx),%rdi
mov    0x2e37(%rip),%rax
mov    0x2dd8(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
call   1070 <open@plt>
test   %eax,%eax
js     12b6 <main+0x136>
mov    %eax,%r13d
mov    0x10(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r15
mov    0x28(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%r12
mov    0x18(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,%rbp
mov    0x30(%rbx),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
mov    %rax,%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
call   1080 <pread@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r12,%rcx
call   1060 <pwrite@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd77(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    12e7 <main+0x167>
mov    0x2d2f(%rip),%rax
mov    (%rax),%ebp
mov    0x8(%rbx),%rbx
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd8d(%rip),%rsi
jmp    12d8 <main+0x158>
mov    0x2d0b(%rip),%rax
mov    (%rax),%ebp
mov    0x20(%rbx),%rbx
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
lea    0xd80(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [65 x i8] c"Usage: %s <input file, offset, size> <output file, offset, size>\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [24 x i8] c"Unable to write %s: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 7
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %2
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDONLY
%29 = call i32 (i8*, i32, ...) @open(i8* %27, i32 %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %24
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i32, i32* @errno
%38 = call i8* @strerror(i32 %37)
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %38)
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %24
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 4
%45 = load i8*, i8** %44
%46 = load i32, i32* @O_CREAT
%47 = load i32, i32* @O_WRONLY
%48 = or i32 %46, %47
%49 = load i32, i32* @S_IRWXU
%50 = call i32 (i8*, i32, ...) @open(i8* %45, i32 %48, i32 %49)
store i32 %50, i32* %8
%51 = load i32, i32* %8
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %42
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 4
%57 = load i8*, i8** %56
%58 = load i32, i32* @errno
%59 = call i8* @strerror(i32 %58)
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %57, i8* %59)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %42
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = call i8* @strtol(i8* %66, i32* null, i32 10)
store i8* %67, i8** %10
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 5
%70 = load i8*, i8** %69
%71 = call i8* @strtol(i8* %70, i32* null, i32 10)
store i8* %71, i8** %11
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 3
%74 = load i8*, i8** %73
%75 = call i8* @strtol(i8* %74, i32* null, i32 10)
%76 = ptrtoint i8* %75 to i64
store i64 %76, i64* %12
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 6
%79 = load i8*, i8** %78
%80 = call i8* @strtol(i8* %79, i32* null, i32 10)
%81 = ptrtoint i8* %80 to i64
store i64 %81, i64* %13
%82 = call i8* @malloc(i32 8)
store i8* %82, i8** %6
%83 = load i64, i64* %12
%84 = load i64, i64* %13
%85 = icmp ult i64 %83, %84
br i1 %85, label %86, label %88
86: ; preds = %63
%87 = load i64, i64* %12
store i64 %87, i64* %13
br label %88
88: ; preds = %86, %63
%89 = load i32, i32* %7
%90 = load i8*, i8** %6
%91 = load i64, i64* %12
%92 = load i8*, i8** %10
%93 = call i32 @pread(i32 %89, i8* %90, i64 %91, i8* %92)
store i32 %93, i32* %9
%94 = load i32, i32* %8
%95 = load i8*, i8** %6
%96 = load i32, i32* %9
%97 = load i8*, i8** %11
%98 = call i32 @pwrite(i32 %94, i8* %95, i32 %96, i8* %97)
%99 = load i32, i32* @EXIT_SUCCESS
ret i32 %99
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [65 x i8] c"Usage: %s <input file, offset, size> <output file, offset, size>\00"
@EXIT_FAILURE = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@S_IRWXU = global i32 0
@.str.2 = [24 x i8] c"Unable to write %s: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 7
br i1 %3, label %10, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDONLY
%14 = tail call i32 (i8*, i32, ...) @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %24
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %11
%19 = load i32, i32* @errno
%20 = tail call i8* @strerror(i32 %19)
%21 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %10
%25 = getelementptr inbounds i8*, i8** %1, i64 4
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_CREAT
%28 = load i32, i32* @O_WRONLY
%29 = or i32 %28, %27
%30 = load i32, i32* @S_IRWXU
%31 = tail call i32 (i8*, i32, ...) @open(i8* %26, i32 %29, i32 %30)
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %24
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %25
%36 = load i32, i32* @errno
%37 = tail call i8* @strerror(i32 %36)
%38 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %37)
%39 = load i32, i32* @EXIT_FAILURE
%40 = tail call i32 @exit(i32 %39)
unreachable
41: ; preds = %24
%42 = getelementptr inbounds i8*, i8** %1, i64 2
%43 = load i8*, i8** %42
%44 = tail call i8* @strtol(i8* nocapture %43, i32* null, i32 10)
%45 = getelementptr inbounds i8*, i8** %1, i64 5
%46 = load i8*, i8** %45
%47 = tail call i8* @strtol(i8* nocapture %46, i32* null, i32 10)
%48 = getelementptr inbounds i8*, i8** %1, i64 3
%49 = load i8*, i8** %48
%50 = tail call i8* @strtol(i8* nocapture %49, i32* null, i32 10)
%51 = getelementptr inbounds i8*, i8** %1, i64 6
%52 = load i8*, i8** %51
%53 = tail call i8* @strtol(i8* nocapture %52, i32* null, i32 10)
%54 = tail call dereferenceable_or_null(8) i8* @malloc(i32 8)
%55 = ptrtoint i8* %50 to i64
%56 = tail call i32 @pread(i32 %14, i8* %54, i64 %55, i8* %44)
%57 = tail call i32 @pwrite(i32 %31, i8* %54, i32 %56, i8* %47)
%58 = load i32, i32* @EXIT_SUCCESS
ret i32 %58
}