#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*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
long lseek(int, long, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, void *, int);
void writeBlocks(int disk, int blockNumber, void *data, int blockCount) {
  long offset = blockNumber * 1024;
  int byteCount = blockCount * 1024;
  if (offset != lseek(disk, offset, SEEK_SET)) {
    fprintf(stderr, "Error seeking to valid block during write.\n");
    exit(1);
  }
  if (byteCount != write(disk, data, byteCount)) {
    fprintf(stderr, "Error during write to seemingly valid block.\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<writeBlocks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x8(%rbp),%eax
shl    $0xa,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    0x2e58(%rip),%rax
mov    (%rax),%edx
call   1040 <lseek@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     11b6 <writeBlocks+0x76>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1030 <write@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
je     11f7 <writeBlocks+0xb7>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writeBlocks>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %edi,%r15d
shl    $0xa,%esi
movslq %esi,%rbp
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %rbp,%rsi
call   1040 <lseek@plt>
cmp    %rbp,%rax
jne    118a <writeBlocks+0x4a>
shl    $0xa,%ebx
mov    %r15d,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %eax,%ebx
jne    119c <writeBlocks+0x5c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
jmp    11ac <writeBlocks+0x6c>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error seeking to valid block during write.\0A\00"
@.str.1 = [46 x i8] c"Error during write to seemingly valid block.\0A\00"
define void @writeBlocks(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %6
%12 = mul nsw i32 %11, 1024
%13 = sext i32 %12 to i64
store i64 %13, i64* %9
%14 = load i32, i32* %8
%15 = mul nsw i32 %14, 1024
store i32 %15, i32* %10
%16 = load i64, i64* %9
%17 = load i32, i32* %5
%18 = load i64, i64* %9
%19 = load i32, i32* @SEEK_SET
%20 = call i64 @lseek(i32 %17, i64 %18, i32 %19)
%21 = icmp ne i64 %16, %20
br i1 %21, label %22, label %26
22: ; preds = %4
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %4
%27 = load i32, i32* %10
%28 = load i32, i32* %5
%29 = load i8*, i8** %7
%30 = load i32, i32* %10
%31 = call i32 @write(i32 %28, i8* %29, i32 %30)
%32 = icmp ne i32 %27, %31
br i1 %32, label %33, label %37
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %26
ret void
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
@stderr = global i32 0
@.str = [44 x i8] c"Error seeking to valid block during write.\0A\00"
@.str.1 = [46 x i8] c"Error during write to seemingly valid block.\0A\00"
define void @writeBlocks(i32 %0, i32 %1, i8* nocapture %2, i32 %3) {
%5 = shl nsw i32 %1, 10
%6 = sext i32 %5 to i64
%7 = shl nsw i32 %3, 10
%8 = load i32, i32* @SEEK_SET
%9 = tail call i64 @lseek(i32 %0, i64 %6, i32 %8)
%10 = icmp eq i64 %9, %6
br i1 %10, label %15, label %11
11: ; preds = %4
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %4
%16 = tail call i32 @write(i32 %0, i8* %2, i32 %7)
%17 = icmp eq i32 %7, %16
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = load i32, i32* @stderr
%20 = tail call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%21 = tail call i32 @exit(i32 1)
unreachable
22: ; preds = %15
ret void
}