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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int strtoul(char *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char sector[512];
  int r, fd, sect;
  if (argc < 3) {
    fprintf(stderr, "Usage: %s DEVICE OFFSET\n", argv[0]);
    exit(1);
  }
  sect = strtoul(argv[2], NULL, 10);
  fd = open(argv[1], O_RDWR);
  if (fd == -1) {
    fprintf(stderr, "%s: unable to open %s\n", argv[0], argv[1]);
    exit(1);
  }
  memset(sector, 0, sizeof(sector));
  sector[510] = 'R';
  sector[511] = 'K';
  sector[0x1be] = 0x80;
  sector[0x1c6] = sect;
  sector[0x1c7] = sect >> 8;
  sector[0x1c8] = sect >> 16;
  sector[0x1c9] = sect >> 24;
  write(fd, sector, sizeof(sector));
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11bb <main+0x4b>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x21c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x218(%rbp)
cmpl   $0xffffffff,-0x218(%rbp)
jne    1230 <main+0xc0>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xdfa(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
movb   $0x52,-0x12(%rbp)
movb   $0x4b,-0x11(%rbp)
movb   $0x80,-0x52(%rbp)
mov    -0x21c(%rbp),%eax
mov    %al,-0x4a(%rbp)
mov    -0x21c(%rbp),%eax
sar    $0x8,%eax
mov    %al,-0x49(%rbp)
mov    -0x21c(%rbp),%eax
sar    $0x10,%eax
mov    %al,-0x48(%rbp)
mov    -0x21c(%rbp),%eax
sar    $0x18,%eax
mov    %al,-0x47(%rbp)
mov    -0x218(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    -0x218(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsi,%r14
cmp    $0x2,%edi
jle    1222 <main+0xb2>
mov    0x10(%r14),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtoul@plt>
mov    %eax,%ebx
mov    0x8(%r14),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     1246 <main+0xd6>
mov    %eax,%ebp
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1040 <memset@plt>
movw   $0x4b52,0x1fe(%rsp)
movb   $0x80,0x1be(%rsp)
80
mov    %bl,0x1c6(%rsp)
mov    %bh,0x1c7(%rsp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x1c8(%rsp)
shr    $0x18,%ebx
mov    %bl,0x1c9(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xdcb(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
mov    0x8(%r14),%rcx
lea    0xdbc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s DEVICE OFFSET\0A\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"%s: unable to open %s\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 i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @strtoul(i8* %22, i32* null, i32 10)
store i32 %23, i32* %9
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i32, i32* @O_RDWR
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %8
%29 = load i32, i32* %8
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %41
31: ; preds = %19
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %19
%42 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%43 = call i32 @memset(i8* %42, i32 0, i32 512)
%44 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 510
store i8 82, i8* %44
%45 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 511
store i8 75, i8* %45
%46 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 446
store i8 -128, i8* %46
%47 = load i32, i32* %9
%48 = trunc i32 %47 to i8
%49 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 454
store i8 %48, i8* %49
%50 = load i32, i32* %9
%51 = ashr i32 %50, 8
%52 = trunc i32 %51 to i8
%53 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 455
store i8 %52, i8* %53
%54 = load i32, i32* %9
%55 = ashr i32 %54, 16
%56 = trunc i32 %55 to i8
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 456
store i8 %56, i8* %57
%58 = load i32, i32* %9
%59 = ashr i32 %58, 24
%60 = trunc i32 %59 to i8
%61 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 457
store i8 %60, i8* %61
%62 = load i32, i32* %8
%63 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%64 = call i32 @write(i32 %62, i8* %63, i32 512)
%65 = load i32, i32* %8
%66 = call i32 @close(i32 %65)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"Usage: %s DEVICE OFFSET\0A\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"%s: unable to open %s\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 = icmp slt i32 %0, 3
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @strtoul(i8* nocapture %13, i32* null, i32 10)
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = load i32, i32* @O_RDWR
%18 = tail call i32 @open(i8* %16, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %26
20: ; preds = %11
%21 = load i32, i32* @stderr
%22 = load i8*, i8** %1
%23 = load i8*, i8** %15
%24 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %11
%27 = call i32 @memset(i8* %4, i32 0, i32 512)
%28 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 510
store i8 82, i8* %28
%29 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 511
store i8 75, i8* %29
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 446
store i8 -128, i8* %30
%31 = trunc i32 %14 to i8
%32 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 454
store i8 %31, i8* %32
%33 = lshr i32 %14, 8
%34 = trunc i32 %33 to i8
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 455
store i8 %34, i8* %35
%36 = lshr i32 %14, 16
%37 = trunc i32 %36 to i8
%38 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 456
store i8 %37, i8* %38
%39 = lshr i32 %14, 24
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 457
store i8 %40, i8* %41
%42 = call i32 @write(i32 %18, i8* %4, i32 512)
%43 = call i32 @close(i32 %18)
ret i32 0
}