#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_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int lseek(int, int, int /*<<< orphan*/);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  char *filename;
  int nblocks, blocksize;
  int fd;
  char *block;
  int ret;
  if (argc != 4)
    usage(argv[0]);
  filename = argv[1];
  nblocks = strtoul(argv[2], 0, 0) - 1;
  blocksize = strtoul(argv[3], 0, 0);
  if (nblocks < 0) {
    fprintf(stderr, ("Illegal number of blocks!\n"));
    exit(1);
  }
  block = malloc(blocksize);
  if (block == 0) {
    fprintf(stderr, ("Couldn't allocate block buffer (size=%d)\n"), blocksize);
    exit(1);
  }
  memset(block, 0, blocksize);
  fd = open(filename, O_RDWR);
  if (fd < 0) {
    perror(filename);
    exit(1);
  }
  ret = lseek(fd, nblocks * blocksize, SEEK_SET);
  if (ret < 0) {
    perror("lseek");
    exit(1);
  }
  ret = read(fd, block, blocksize);
  if (ret < 0) {
    perror("read");
    exit(1);
  }
  ret = lseek(fd, nblocks * blocksize, SEEK_SET);
  if (ret < 0) {
    perror("lseek #2");
    exit(1);
  }
  ret = write(fd, block, blocksize);
  if (ret < 0) {
    perror("read");
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     11dc <main+0x2c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1090 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <strtoul@plt>
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   10c0 <strtoul@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    123e <main+0x8e>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
lea    0xdd3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1279 <main+0xc9>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%edx
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
call   10a0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12b9 <main+0x109>
mov    -0x18(%rbp),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
imul   -0x20(%rbp),%esi
mov    0x2d06(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    12f4 <main+0x144>
lea    0xd60(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1060 <read@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1326 <main+0x176>
lea    0xd34(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x1c(%rbp),%esi
imul   -0x20(%rbp),%esi
mov    0x2c99(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1361 <main+0x1b1>
lea    0xcfe(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1393 <main+0x1e3>
lea    0xcc7(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x4,%edi
je     11c8 <main+0x18>
mov    (%rbx),%rdi
call   1090 <usage@plt>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtoul@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   10c0 <strtoul@plt>
test   %ebp,%ebp
jg     120d <main+0x5d>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1080 <malloc@plt>
test   %rax,%rax
jne    123e <main+0x8e>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rax,%r14
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <memset@plt>
mov    0x2d94(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10a0 <open@plt>
test   %eax,%eax
jns    1267 <main+0xb7>
mov    %r15,%rdi
jmp    12d9 <main+0x129>
mov    %eax,%r12d
add    $0xffffffff,%ebp
mov    %ebx,%r15d
imul   %ebp,%r15d
mov    0x2d55(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %eax,%edi
mov    %r15d,%esi
call   1040 <lseek@plt>
test   %eax,%eax
jns    1295 <main+0xe5>
lea    0xdb2(%rip),%rdi
jmp    12d9 <main+0x129>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <read@plt>
test   %eax,%eax
js     12d2 <main+0x122>
mov    0x0(%rbp),%edx
mov    %r12d,%edi
mov    %r15d,%esi
call   1040 <lseek@plt>
test   %eax,%eax
jns    12c1 <main+0x111>
lea    0xd91(%rip),%rdi
jmp    12d9 <main+0x129>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
test   %eax,%eax
jns    12e8 <main+0x138>
lea    0xd72(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"Illegal number of blocks!\0A\00"
@.str.1 = [42 x i8] c"Couldn't allocate block buffer (size=%d)\0A\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [9 x i8] c"lseek\00"
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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 @usage(i8* %17)
br label %19
19: ; preds = %14, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
store i8* %22, i8** %6
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 2
%25 = load i8*, i8** %24
%26 = call i32 @strtoul(i8* %25, i32 0, i32 0)
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
%31 = call i32 @strtoul(i8* %30, i32 0, i32 0)
store i32 %31, i32* %8
%32 = load i32, i32* %7
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %19
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %19
%39 = load i32, i32* %8
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %10
%41 = load i8*, i8** %10
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %48
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i32, i32* %8
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = load i8*, i8** %10
%50 = load i32, i32* %8
%51 = call i32 @memset(i8* %49, i32 0, i32 %50)
%52 = load i8*, i8** %6
%53 = load i32, i32* @O_RDWR
%54 = call i32 @open(i8* %52, i32 %53)
store i32 %54, i32* %9
%55 = load i32, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %61
57: ; preds = %48
%58 = load i8*, i8** %6
%59 = call i32 @perror(i8* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %48
%62 = load i32, i32* %9
%63 = load i32, i32* %7
%64 = load i32, i32* %8
%65 = mul nsw i32 %63, %64
%66 = load i32, i32* @SEEK_SET
%67 = call i32 @lseek(i32 %62, i32 %65, i32 %66)
store i32 %67, i32* %11
%68 = load i32, i32* %11
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %61
%71 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %61
%74 = load i32, i32* %9
%75 = load i8*, i8** %10
%76 = load i32, i32* %8
%77 = call i32 @read(i32 %74, i8* %75, i32 %76)
store i32 %77, i32* %11
%78 = load i32, i32* %11
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %73
%81 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %73
%84 = load i32, i32* %9
%85 = load i32, i32* %7
%86 = load i32, i32* %8
%87 = mul nsw i32 %85, %86
%88 = load i32, i32* @SEEK_SET
%89 = call i32 @lseek(i32 %84, i32 %87, i32 %88)
store i32 %89, i32* %11
%90 = load i32, i32* %11
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %83
%93 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %83
%96 = load i32, i32* %9
%97 = load i8*, i8** %10
%98 = load i32, i32* %8
%99 = call i32 @write(i32 %96, i8* %97, i32 %98)
store i32 %99, i32* %11
%100 = load i32, i32* %11
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %105
102: ; preds = %95
%103 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %95
%106 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"Illegal number of blocks!\0A\00"
@.str.1 = [42 x i8] c"Couldn't allocate block buffer (size=%d)\0A\00"
@O_RDWR = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [6 x i8] c"lseek\00"
@.str.3 = [5 x i8] c"read\00"
@.str.4 = [9 x i8] c"lseek\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @usage(i8* %5)
br label %7
7: ; preds = %4, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @strtoul(i8* %11, i32 0, i32 0)
%13 = add nsw i32 %12, -1
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @strtoul(i8* %15, i32 0, i32 0)
%17 = icmp slt i32 %12, 1
br i1 %17, label %18, label %22
18: ; preds = %7
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %7
%23 = tail call i8* @malloc(i32 %16)
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %22
%30 = tail call i32 @memset(i8* %23, i32 0, i32 %16)
%31 = load i32, i32* @O_RDWR
%32 = tail call i32 @open(i8* %9, i32 %31)
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %29
%35 = tail call i32 @perror(i8* %9)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %29
%38 = mul nsw i32 %16, %13
%39 = load i32, i32* @SEEK_SET
%40 = tail call i32 @lseek(i32 %32, i32 %38, i32 %39)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %37
%46 = tail call i32 @read(i32 %32, i8* %23, i32 %16)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %45
%49 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %45
%52 = load i32, i32* @SEEK_SET
%53 = tail call i32 @lseek(i32 %32, i32 %38, i32 %52)
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%57 = tail call i32 @exit(i32 1)
unreachable
58: ; preds = %51
%59 = tail call i32 @write(i32 %32, i8* %23, i32 %16)
%60 = icmp slt i32 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%63 = tail call i32 @exit(i32 1)
unreachable
64: ; preds = %58
%65 = tail call i32 @exit(i32 0)
unreachable
}