#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;
scalar_t__ fseek(int /*<<< orphan*/ *, unsigned long, int /*<<< orphan*/);
unsigned long fwrite(void const *, int, unsigned long, int /*<<< orphan*/ *);
int psi_write_ofs(FILE *fp, unsigned long ofs, const void *buf,
                  unsigned long cnt) {
  if (fseek(fp, ofs, SEEK_SET) != 0) {
    return (1);
  }
  if (fwrite(buf, 1, cnt, fp) != cnt) {
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<psi_write_ofs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
call   1030 <fseek@plt>
cmp    $0x0,%rax
je     1164 <psi_write_ofs+0x44>
movl   $0x1,-0x4(%rbp)
jmp    1197 <psi_write_ofs+0x77>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
cmp    -0x28(%rbp),%rax
je     1190 <psi_write_ofs+0x70>
movl   $0x1,-0x4(%rbp)
jmp    1197 <psi_write_ofs+0x77>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psi_write_ofs>:
push   %r15
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%rbx
mov    0x2eab(%rip),%rax
mov    (%rax),%edx
call   1030 <fseek@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1167 <psi_write_ofs+0x47>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %r14,%rcx
setne  %al
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @psi_write_ofs(i32* %0, i64 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i32* %0, i32** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%10 = load i32*, i32** %6
%11 = load i64, i64* %7
%12 = load i32, i32* @SEEK_SET
%13 = call i64 @fseek(i32* %10, i64 %11, i32 %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
store i32 1, i32* %5
br label %25
16: ; preds = %4
%17 = load i8*, i8** %8
%18 = load i64, i64* %9
%19 = load i32*, i32** %6
%20 = call i64 @fwrite(i8* %17, i32 1, i64 %18, i32* %19)
%21 = load i64, i64* %9
%22 = icmp ne i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1, i32* %5
br label %25
24: ; preds = %16
store i32 0, i32* %5
br label %25
25: ; preds = %24, %23, %15
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @psi_write_ofs(i32* nocapture %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = load i32, i32* @SEEK_SET
%6 = tail call i64 @fseek(i32* %0, i64 %1, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i64 @fwrite(i8* %2, i32 1, i64 %3, i32* %0)
%10 = icmp ne i64 %9, %3
%11 = zext i1 %10 to i32
br label %12
12: ; preds = %8, %4
%13 = phi i32 [ 1, %4 ], [ %11, %8 ]
ret i32 %13
}