#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*/ O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
long long atoll(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long long);
long long lseek64(int, long long, int /*<<< orphan*/);
int /*<<< orphan*/ memset(unsigned char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int read(int, unsigned char *, int);
int /*<<< orphan*/ stderr;
int write(int, unsigned char *, int);
int main(int argc, char **argv) {
  unsigned char buf[512];
  long long int position = atoll(argv[1]);
  long long int ret;
  int fd1 = open("sdc4_b.1.img", O_RDONLY);
  if (fd1 < 0) {
    fprintf(stderr, "line %d:%m\n", 45);
    exit(10);
  };
  ret = lseek64(fd1, position * 512, SEEK_SET);
  if (ret != position * 512) {
    fprintf(stderr, "line %d:%m\n", 46);
    exit(15);
  };
  int fd2 = open("sdc4_b.3.img", O_WRONLY);
  if (fd2 < 0) {
    fprintf(stderr, "line %d:%m\n", 48);
    exit(10);
  };
  ret = lseek64(fd2, position * 512, SEEK_SET);
  if (ret != position * 512) {
    fprintf(stderr, "line %d:%m\n", 49);
    exit(15);
  };
  memset(buf, 0, 512);
  if (read(fd1, buf, 512) != 512) {
    fprintf(stderr, "read error %m at position %lld\n", position);
    exit(13);
  };
  if (write(fd2, buf, 512) != 512) {
    fprintf(stderr, "write error %m at position %lld\n", position);
    exit(13);
  };
  close(fd1);
  close(fd2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atoll@plt>
mov    %rax,-0x218(%rbp)
mov    0x2e24(%rip),%rax
mov    (%rax),%esi
lea    0xe33(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0x0,-0x224(%rbp)
jge    1209 <main+0x79>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
mov    $0x2d,%edx
call   1080 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
mov    -0x224(%rbp),%edi
mov    -0x218(%rbp),%rsi
shl    $0x9,%rsi
mov    0x2daf(%rip),%rax
mov    (%rax),%edx
call   10b0 <lseek64@plt>
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    -0x218(%rbp),%rcx
shl    $0x9,%rcx
cmp    %rcx,%rax
je     126e <main+0xde>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
lea    0xdb3(%rip),%rsi
mov    $0x2e,%edx
call   1080 <fprintf@plt>
mov    $0xf,%edi
call   10a0 <exit@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%esi
lea    0xd9b(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x228(%rbp)
cmpl   $0x0,-0x228(%rbp)
jge    12ba <main+0x12a>
mov    0x2d3b(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    $0x30,%edx
call   1080 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
mov    -0x228(%rbp),%edi
mov    -0x218(%rbp),%rsi
shl    $0x9,%rsi
mov    0x2cfe(%rip),%rax
mov    (%rax),%edx
call   10b0 <lseek64@plt>
mov    %rax,-0x220(%rbp)
mov    -0x220(%rbp),%rax
mov    -0x218(%rbp),%rcx
shl    $0x9,%rcx
cmp    %rcx,%rax
je     131f <main+0x18f>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
mov    $0x31,%edx
call   1080 <fprintf@plt>
mov    $0xf,%edi
call   10a0 <exit@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    -0x224(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1060 <read@plt>
cmp    $0x200,%eax
je     137a <main+0x1ea>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
mov    -0x218(%rbp),%rdx
lea    0xcbb(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xd,%edi
call   10a0 <exit@plt>
mov    -0x228(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0x200,%eax
je     13c2 <main+0x232>
mov    0x2c35(%rip),%rax
mov    (%rax),%edi
mov    -0x218(%rbp),%rdx
lea    0xc93(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0xd,%edi
call   10a0 <exit@plt>
mov    -0x224(%rbp),%edi
call   1050 <close@plt>
mov    -0x228(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    0x8(%rsi),%rdi
call   1070 <atoll@plt>
mov    %rax,%r14
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    0xe45(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     128e <main+0xfe>
mov    %eax,%r15d
mov    %r14,%rbp
shl    $0x9,%rbp
mov    0x2df7(%rip),%r12
mov    (%r12),%edx
mov    %eax,%edi
mov    %rbp,%rsi
call   10b0 <lseek64@plt>
cmp    %rbp,%rax
jne    12a5 <main+0x115>
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
lea    0xe19(%rip),%rdi
call   1090 <open@plt>
test   %eax,%eax
js     12bc <main+0x12c>
mov    %eax,%ebx
mov    (%r12),%edx
mov    %eax,%edi
mov    %rbp,%rsi
call   10b0 <lseek64@plt>
cmp    %rbp,%rax
jne    12e0 <main+0x150>
mov    %rsp,%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
call   1060 <read@plt>
cmp    $0x200,%eax
jne    1304 <main+0x174>
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0x200,%eax
jne    1316 <main+0x186>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    $0x2d,%edx
jmp    12d1 <main+0x141>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
lea    0xd58(%rip),%rsi
mov    $0x2e,%edx
jmp    12f5 <main+0x165>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
mov    $0x30,%edx
call   1080 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <exit@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
lea    0xd1d(%rip),%rsi
mov    $0x31,%edx
call   1080 <fprintf@plt>
mov    $0xf,%edi
call   10a0 <exit@plt>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
jmp    1326 <main+0x196>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
lea    0xd20(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
mov    $0xd,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"sdc4_b.1.img\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"line %d:%m\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [13 x i8] c"sdc4_b.3.img\00"
@O_WRONLY = global i32 0
@.str.3 = [32 x i8] c"read error %m at position %lld\0A\00"
@.str.4 = [33 x i8] c"write error %m at position %lld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @atoll(i8* %13)
store i64 %14, i64* %7
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %9
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 45)
%22 = call i32 @exit(i32 10)
unreachable
23: ; preds = %2
%24 = load i32, i32* %9
%25 = load i64, i64* %7
%26 = mul nsw i64 %25, 512
%27 = load i32, i32* @SEEK_SET
%28 = call i64 @lseek64(i32 %24, i64 %26, i32 %27)
store i64 %28, i64* %8
%29 = load i64, i64* %8
%30 = load i64, i64* %7
%31 = mul nsw i64 %30, 512
%32 = icmp ne i64 %29, %31
br i1 %32, label %33, label %37
33: ; preds = %23
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 46)
%36 = call i32 @exit(i32 15)
unreachable
37: ; preds = %23
%38 = load i32, i32* @O_WRONLY
%39 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %38)
store i32 %39, i32* %10
%40 = load i32, i32* %10
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = call i32 @fprintf(i32 %43, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 48)
%45 = call i32 @exit(i32 10)
unreachable
46: ; preds = %37
%47 = load i32, i32* %10
%48 = load i64, i64* %7
%49 = mul nsw i64 %48, 512
%50 = load i32, i32* @SEEK_SET
%51 = call i64 @lseek64(i32 %47, i64 %49, i32 %50)
store i64 %51, i64* %8
%52 = load i64, i64* %8
%53 = load i64, i64* %7
%54 = mul nsw i64 %53, 512
%55 = icmp ne i64 %52, %54
br i1 %55, label %56, label %60
56: ; preds = %46
%57 = load i32, i32* @stderr
%58 = call i32 @fprintf(i32 %57, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 49)
%59 = call i32 @exit(i32 15)
unreachable
60: ; preds = %46
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%62 = call i32 @memset(i8* %61, i32 0, i32 512)
%63 = load i32, i32* %9
%64 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%65 = call i32 @read(i32 %63, i8* %64, i32 512)
%66 = icmp ne i32 %65, 512
br i1 %66, label %67, label %72
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = load i64, i64* %7
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %69)
%71 = call i32 @exit(i32 13)
unreachable
72: ; preds = %60
%73 = load i32, i32* %10
%74 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%75 = call i32 @write(i32 %73, i8* %74, i32 512)
%76 = icmp ne i32 %75, 512
br i1 %76, label %77, label %82
77: ; preds = %72
%78 = load i32, i32* @stderr
%79 = load i64, i64* %7
%80 = call i32 @fprintf(i32 %78, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i64 %79)
%81 = call i32 @exit(i32 13)
unreachable
82: ; preds = %72
%83 = load i32, i32* %9
%84 = call i32 @close(i32 %83)
%85 = load i32, i32* %10
%86 = call i32 @close(i32 %85)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"sdc4_b.1.img\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.1 = [12 x i8] c"line %d:%m\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [13 x i8] c"sdc4_b.3.img\00"
@O_WRONLY = global i32 0
@.str.3 = [32 x i8] c"read error %m at position %lld\0A\00"
@.str.4 = [33 x i8] c"write error %m at position %lld\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @atoll(i8* %6)
%8 = load i32, i32* @O_RDONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 45)
%14 = tail call i32 @exit(i32 10)
unreachable
15: ; preds = %2
%16 = shl nsw i64 %7, 9
%17 = load i32, i32* @SEEK_SET
%18 = tail call i64 @lseek64(i32 %9, i64 %16, i32 %17)
%19 = icmp eq i64 %18, %16
br i1 %19, label %24, label %20
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = tail call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 46)
%23 = tail call i32 @exit(i32 15)
unreachable
24: ; preds = %15
%25 = load i32, i32* @O_WRONLY
%26 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 48)
%31 = tail call i32 @exit(i32 10)
unreachable
32: ; preds = %24
%33 = load i32, i32* @SEEK_SET
%34 = tail call i64 @lseek64(i32 %26, i64 %16, i32 %33)
%35 = icmp eq i64 %34, %16
br i1 %35, label %40, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = tail call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i64 49)
%39 = tail call i32 @exit(i32 15)
unreachable
40: ; preds = %32
%41 = call i32 @memset(i8* %4, i32 0, i32 512)
%42 = call i32 @read(i32 %9, i8* %4, i32 512)
%43 = icmp eq i32 %42, 512
br i1 %43, label %48, label %44
44: ; preds = %40
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i64 %7)
%47 = call i32 @exit(i32 13)
unreachable
48: ; preds = %40
%49 = call i32 @write(i32 %26, i8* %4, i32 512)
%50 = icmp eq i32 %49, 512
br i1 %50, label %55, label %51
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0), i64 %7)
%54 = call i32 @exit(i32 13)
unreachable
55: ; preds = %48
%56 = call i32 @close(i32 %9)
%57 = call i32 @close(i32 %26)
ret i32 0
}