#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, int, ...);
int pwrite(int, char *, int, int);
char *strerror(int /*<<< orphan*/);
int do_write_offset(int f, int offset, int blockSize, char *filename,
                    char *pCompareBuff, char *pBlock) {
  ssize_t size;
  memcpy(&pCompareBuff[offset], pBlock, blockSize);
  size = pwrite(f, pBlock, blockSize, offset);
  if (size != blockSize) {
    printf("%d %s - ", 276, filename);
    printf("pwrite size %d offset %d %s\n", blockSize, offset, strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<do_write_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
call   1050 <pwrite@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     11e9 <do_write_offset+0xa9>
mov    -0x18(%rbp),%rdx
lea    0xe60(%rip),%rdi
mov    $0x114,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    %rax,%rcx
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f0 <do_write_offset+0xb0>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_write_offset>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%rbx
mov    %rcx,%r14
mov    %edx,%r13d
mov    %esi,%r15d
mov    %edi,%r12d
movslq %esi,%rbp
lea    (%r8,%rbp,1),%rdi
mov    %r9,%rsi
call   1040 <memcpy@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
mov    %ebp,%ecx
call   1050 <pwrite@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %r13d,%ecx
je     11c2 <do_write_offset+0x82>
lea    0xe77(%rip),%rdi
mov    $0x114,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe5c(%rip),%rdi
mov    %r13d,%esi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"%d %s - \00"
@.str.1 = [29 x i8] c"pwrite size %d offset %d %s\0A\00"
@errno = global i32 0
define i32 @do_write_offset(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i8* %4, i8** %12
store i8* %5, i8** %13
%15 = load i8*, i8** %12
%16 = load i32, i32* %9
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8*, i8** %13
%20 = load i32, i32* %10
%21 = call i32 @memcpy(i8* %18, i8* %19, i32 %20)
%22 = load i32, i32* %8
%23 = load i8*, i8** %13
%24 = load i32, i32* %10
%25 = load i32, i32* %9
%26 = call i32 @pwrite(i32 %22, i8* %23, i32 %24, i32 %25)
store i32 %26, i32* %14
%27 = load i32, i32* %14
%28 = load i32, i32* %10
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %38
30: ; preds = %6
%31 = load i8*, i8** %11
%32 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 276, i8* %31)
%33 = load i32, i32* %10
%34 = load i32, i32* %9
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34, i8* %36)
store i32 -1, i32* %7
br label %39
38: ; preds = %6
store i32 0, i32* %7
br label %39
39: ; preds = %38, %30
%40 = load i32, i32* %7
ret i32 %40
}

LLVM IR (-O2):
@.str = [9 x i8] c"%d %s - \00"
@.str.1 = [29 x i8] c"pwrite size %d offset %d %s\0A\00"
@errno = global i32 0
define i32 @do_write_offset(i32 %0, i32 %1, i32 %2, i8* %3, i8* %4, i8* %5) {
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds i8, i8* %4, i64 %7
%9 = tail call i32 @memcpy(i8* %8, i8* %5, i32 %2)
%10 = tail call i32 @pwrite(i32 %0, i8* %5, i32 %2, i32 %1)
%11 = icmp eq i32 %10, %2
br i1 %11, label %17, label %12
12: ; preds = %6
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 276, i8* %3)
%14 = load i32, i32* @errno
%15 = tail call i8* @strerror(i32 %14)
%16 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i32 %2, i32 %1, i8* %15)
br label %17
17: ; preds = %6, %12
%18 = phi i32 [ -1, %12 ], [ 0, %6 ]
ret i32 %18
}