#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*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int fwrite(char const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int pfr_disk_write(FILE *fp, const void *source_struct, int source_size,
                   const char *flex_value, int flex_size, const char *err_id) {
  int write_size_a = 0, write_size_b = 0;
  write_size_a = fwrite(source_struct, 1, source_size, fp);
  if (write_size_a != source_size) {
    fprintf(stderr, "Error writing %s structure data: %s\n", err_id,
            strerror(errno));
    return 0;
  }
  write_size_b = fwrite(flex_value, 1, flex_size, fp);
  if (write_size_b != flex_size) {
    fprintf(stderr, "Error writing %s flexible value: %s\n", err_id,
            strerror(errno));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<pfr_disk_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8d,-0x2c(%rbp)
mov    %r9,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11c5 <pfr_disk_write+0x95>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe4c(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <pfr_disk_write+0x104>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fwrite@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    -0x2c(%rbp),%eax
je     122d <pfr_disk_write+0xfd>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    %rax,%rcx
lea    0xe09(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1234 <pfr_disk_write+0x104>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pfr_disk_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r14
mov    %r8d,%r15d
mov    %rcx,%r12
mov    %edx,%ebp
mov    %rdi,%rbx
mov    $0x1,%r13d
mov    %rsi,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmp    %ebp,%eax
jne    1184 <pfr_disk_write+0x54>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmp    %r15d,%eax
je     11b5 <pfr_disk_write+0x85>
lea    0xea3(%rip),%rbx
jmp    118b <pfr_disk_write+0x5b>
lea    0xe75(%rip),%rbx
mov    0x2e4e(%rip),%rax
mov    (%rax),%ebp
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1030 <fprintf@plt>
xor    %r13d,%r13d
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Error writing %s structure data: %s\0A\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"Error writing %s flexible value: %s\0A\00"
define i32 @pfr_disk_write(i32* %0, i8* %1, i32 %2, i8* %3, i32 %4, i8* %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %8
store i8* %1, i8** %9
store i32 %2, i32* %10
store i8* %3, i8** %11
store i32 %4, i32* %12
store i8* %5, i8** %13
store i32 0, i32* %14
store i32 0, i32* %15
%16 = load i8*, i8** %9
%17 = load i32, i32* %10
%18 = load i32*, i32** %8
%19 = call i32 @fwrite(i8* %16, i32 1, i32 %17, i32* %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = load i32, i32* %10
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %6
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %13
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %25, i8* %27)
store i32 0, i32* %7
br label %44
29: ; preds = %6
%30 = load i8*, i8** %11
%31 = load i32, i32* %12
%32 = load i32*, i32** %8
%33 = call i32 @fwrite(i8* %30, i32 1, i32 %31, i32* %32)
store i32 %33, i32* %15
%34 = load i32, i32* %15
%35 = load i32, i32* %12
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %13
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8* %41)
store i32 0, i32* %7
br label %44
43: ; preds = %29
store i32 1, i32* %7
br label %44
44: ; preds = %43, %37, %23
%45 = load i32, i32* %7
ret i32 %45
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Error writing %s structure data: %s\0A\00"
@errno = global i32 0
@.str.1 = [37 x i8] c"Error writing %s flexible value: %s\0A\00"
define i32 @pfr_disk_write(i32* nocapture %0, i8* nocapture %1, i32 %2, i8* nocapture %3, i32 %4, i8* %5) {
%7 = tail call i32 @fwrite(i8* %1, i32 1, i32 %2, i32* %0)
%8 = icmp eq i32 %7, %2
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @fwrite(i8* %3, i32 1, i32 %4, i32* %0)
%11 = icmp eq i32 %10, %4
br i1 %11, label %18, label %12
12: ; preds = %9, %6
%13 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %6 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), %9 ]
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 @fprintf(i32 %14, i8* %13, i8* %5, i8* %16)
br label %18
18: ; preds = %12, %9
%19 = phi i32 [ 1, %9 ], [ 0, %12 ]
ret i32 %19
}