#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*/ SEEK_SET;
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int read(int, char *, int);
int loaddisk(char *path, char *buf, int skip) {
  int f = open(path, O_RDONLY), i;
  if (f < 0)
    err("Can't open disk.");
  lseek(f, skip, SEEK_SET);
  i = read(f, buf, 180 * 1024);
  if (i < 0)
    err("Read failed.");
  if (i % 256)
    err("That's not a disk!");
  printf("(%dK)", i / 1024);
}


x86 assembly (clang, -O0):
<loaddisk>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    118e <loaddisk+0x3e>
lea    0xe77(%rip),%rdi
call   1060 <err@plt>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    -0x20(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x2d000,%edx
call   1050 <read@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11cc <loaddisk+0x7c>
lea    0xe4a(%rip),%rdi
call   1060 <err@plt>
mov    -0x24(%rbp),%eax
mov    $0x100,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     11ec <loaddisk+0x9c>
lea    0xe37(%rip),%rdi
call   1060 <err@plt>
mov    -0x24(%rbp),%eax
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
lea    0xe31(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<loaddisk>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1179 <loaddisk+0x29>
lea    0xe8c(%rip),%rdi
call   1060 <err@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %ebp,%esi
call   1040 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2d000,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
js     11ce <loaddisk+0x7e>
test   %bl,%bl
je     11b0 <loaddisk+0x60>
lea    0xe73(%rip),%rdi
call   1060 <err@plt>
lea    0x3ff(%rbx),%esi
test   %ebx,%ebx
cmovns %ebx,%esi
sar    $0xa,%esi
lea    0xe6c(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <printf@plt>
lea    0xe3c(%rip),%rdi
call   1060 <err@plt>
test   %bl,%bl
jne    11a4 <loaddisk+0x54>
jmp    11b0 <loaddisk+0x60>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [17 x i8] c"Can't open disk.\00"
@SEEK_SET = global i32 0
@.str.1 = [13 x i8] c"Read failed.\00"
@.str.2 = [19 x i8] c"That's not a disk!\00"
@.str.3 = [6 x i8] c"(%dK)\00"
define i32 @loaddisk(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i32, i32* @O_RDONLY
%12 = call i32 @open(i8* %10, i32 %11)
store i32 %12, i32* %8
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @err(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %3
%18 = load i32, i32* %8
%19 = load i32, i32* %7
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @lseek(i32 %18, i32 %19, i32 %20)
%22 = load i32, i32* %8
%23 = load i8*, i8** %6
%24 = call i32 @read(i32 %22, i8* %23, i32 184320)
store i32 %24, i32* %9
%25 = load i32, i32* %9
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %17
%30 = load i32, i32* %9
%31 = srem i32 %30, 256
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %29
%34 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %35
35: ; preds = %33, %29
%36 = load i32, i32* %9
%37 = sdiv i32 %36, 1024
%38 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = load i32, i32* %4
ret i32 %39
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [17 x i8] c"Can't open disk.\00"
@SEEK_SET = global i32 0
@.str.1 = [13 x i8] c"Read failed.\00"
@.str.2 = [19 x i8] c"That's not a disk!\00"
@.str.3 = [6 x i8] c"(%dK)\00"
define i32 @loaddisk(i8* nocapture %0, i8* nocapture %1, i32 %2) {
%4 = load i32, i32* @O_RDONLY
%5 = tail call i32 @open(i8* %0, i32 %4)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @err(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @lseek(i32 %5, i32 %2, i32 %10)
%12 = tail call i32 @read(i32 %5, i8* %1, i32 184320)
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = and i32 %12, 255
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %19
19: ; preds = %16
%20 = tail call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = sdiv i32 %12, 1024
%23 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 %22)
ret i32 undef
}