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

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
size_t fwrite(void *, int, int, int /*<<< orphan*/ *);
void testWriteFile(const char *zFile, int iOff, void *pOut, int nByte,
                   int *pRc) {
  if (*pRc == 0) {
    FILE *fd;
    fd = fopen(zFile, "r+b");
    if (fd == 0) {
      *pRc = 1;
    } else {
      if (0 != fseek(fd, iOff, SEEK_SET)) {
        *pRc = 1;
      } else {
        assert(nByte >= 0);
        if ((size_t)nByte != fwrite(pOut, 1, nByte, fd)) {
          *pRc = 1;
        }
      }
      fclose(fd);
    }
  }
}


x86 assembly (clang, -O0):
<testWriteFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpl   $0x0,(%rax)
jne    1232 <testWriteFile+0xe2>
mov    -0x8(%rbp),%rdi
lea    0xe7e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11a5 <testWriteFile+0x55>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    122d <testWriteFile+0xdd>
mov    -0x30(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e2d(%rip),%rax
mov    (%rax),%edx
call   1050 <fseek@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11d7 <testWriteFile+0x87>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    1224 <testWriteFile+0xd4>
cmpl   $0x0,-0x1c(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movslq -0x1c(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
je     121f <testWriteFile+0xcf>
mov    -0x28(%rbp),%rax
movl   $0x1,(%rax)
jmp    1224 <testWriteFile+0xd4>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1232 <testWriteFile+0xe2>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testWriteFile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmpl   $0x0,(%r8)
je     1167 <testWriteFile+0x17>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r8,%rbx
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %esi,%ebp
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11db <testWriteFile+0x8b>
mov    %rax,%r14
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <fseek@plt>
test   %rax,%rax
jne    11c5 <testWriteFile+0x75>
mov    %r12d,%edi
not    %edi
shr    $0x1f,%edi
call   1040 <assert@plt>
movslq %r12d,%rbp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
cmp    %rbp,%rax
je     11cb <testWriteFile+0x7b>
movl   $0x1,(%rbx)
mov    %r14,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
movl   $0x1,(%rbx)
jmp    115e <testWriteFile+0xe>

LLVM IR (-O0):
@.str = [4 x i8] c"r+b\00"
@SEEK_SET = global i32 0
define void @testWriteFile(i8* %0, i32 %1, i8* %2, i32 %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
store i32* %4, i32** %10
%12 = load i32*, i32** %10
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %49
15: ; preds = %5
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %11
%18 = load i32*, i32** %11
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = load i32*, i32** %10
store i32 1, i32* %21
br label %48
22: ; preds = %15
%23 = load i32*, i32** %11
%24 = load i32, i32* %7
%25 = load i32, i32* @SEEK_SET
%26 = call i64 @fseek(i32* %23, i32 %24, i32 %25)
%27 = icmp ne i64 0, %26
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = load i32*, i32** %10
store i32 1, i32* %29
br label %45
30: ; preds = %22
%31 = load i32, i32* %9
%32 = icmp sge i32 %31, 0
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
%35 = load i32, i32* %9
%36 = sext i32 %35 to i64
%37 = load i8*, i8** %8
%38 = load i32, i32* %9
%39 = load i32*, i32** %11
%40 = call i64 @fwrite(i8* %37, i32 1, i32 %38, i32* %39)
%41 = icmp ne i64 %36, %40
br i1 %41, label %42, label %44
42: ; preds = %30
%43 = load i32*, i32** %10
store i32 1, i32* %43
br label %44
44: ; preds = %42, %30
br label %45
45: ; preds = %44, %28
%46 = load i32*, i32** %11
%47 = call i32 @fclose(i32* %46)
br label %48
48: ; preds = %45, %20
br label %49
49: ; preds = %48, %5
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+b\00"
@SEEK_SET = global i32 0
define void @testWriteFile(i8* nocapture %0, i32 %1, i8* nocapture %2, i32 %3, i32* nocapture %4) {
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %8
store i32 1, i32* %4
br label %26
12: ; preds = %8
%13 = load i32, i32* @SEEK_SET
%14 = tail call i64 @fseek(i32* %9, i32 %1, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %12
%17 = xor i32 %3, -1
%18 = lshr i32 %17, 31
%19 = tail call i32 @assert(i32 %18)
%20 = sext i32 %3 to i64
%21 = tail call i64 @fwrite(i8* %2, i32 1, i32 %3, i32* %9)
%22 = icmp eq i64 %21, %20
br i1 %22, label %24, label %23
23: ; preds = %16, %12
store i32 1, i32* %4
br label %24
24: ; preds = %23, %16
%25 = tail call i32 @fclose(i32* %9)
br label %26
26: ; preds = %11, %24, %5
ret void
}