#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 float uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int write_curveset(FILE *f, float *curve, uint32_t *hist) {
  int ret = -1;
  int w = fwrite(curve, 1, 3 * 0x10000 * sizeof(float), f);
  if (w != 3 * 0x10000 * sizeof(float)) {
    fprintf(stderr, "error: failed writing curves to save state file\n");
    goto exit;
  }
  w = fwrite(hist, 1, 3 * 0x10000 * sizeof(uint32_t), f);
  if (w != 3 * 0x10000 * sizeof(uint32_t)) {
    fprintf(stderr, "error: failed writing histograms to save state file\n");
    goto exit;
  }
  ret = 0;
exit:
  return ret;
}


x86 assembly (clang, -O0):
<write_curveset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc0000,%edx
call   1040 <fwrite@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0xc0000,%rax
je     117f <write_curveset+0x5f>
mov    0x2e74(%rip),%rax
mov    (%rax),%edi
lea    0xe8b(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ca <write_curveset+0xaa>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1,%esi
mov    $0xc0000,%edx
call   1040 <fwrite@plt>
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0xc0000,%rax
je     11c3 <write_curveset+0xa3>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11ca <write_curveset+0xaa>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_curveset>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rdi,%rbx
mov    %rsi,%rdi
mov    $0x1,%esi
mov    $0xc0000,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmp    $0xc0000,%eax
jne    1170 <write_curveset+0x50>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xc0000,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xc0000,%ecx
je     118a <write_curveset+0x6a>
lea    0xec3(%rip),%rsi
jmp    1177 <write_curveset+0x57>
lea    0xe89(%rip),%rsi
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [49 x i8] c"error: failed writing curves to save state file\0A\00"
@.str.1 = [53 x i8] c"error: failed writing histograms to save state file\0A\00"
define i32 @write_curveset(i32* %0, float* %1, float* %2) {
%4 = alloca i32*
%5 = alloca float*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %4
store float* %1, float** %5
store float* %2, float** %6
store i32 -1, i32* %7
%9 = load float*, float** %5
%10 = load i32*, i32** %4
%11 = call i32 @fwrite(float* %9, i32 1, i32 786432, i32* %10)
store i32 %11, i32* %8
%12 = load i32, i32* %8
%13 = sext i32 %12 to i64
%14 = icmp ne i64 %13, 786432
br i1 %14, label %15, label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0))
br label %29
18: ; preds = %3
%19 = load float*, float** %6
%20 = load i32*, i32** %4
%21 = call i32 @fwrite(float* %19, i32 1, i32 786432, i32* %20)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = sext i32 %22 to i64
%24 = icmp ne i64 %23, 786432
br i1 %24, label %25, label %28
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
br label %29
28: ; preds = %18
store i32 0, i32* %7
br label %29
29: ; preds = %28, %25, %15
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [49 x i8] c"error: failed writing curves to save state file\0A\00"
@.str.1 = [53 x i8] c"error: failed writing histograms to save state file\0A\00"
define i32 @write_curveset(i32* nocapture %0, float* nocapture %1, float* nocapture %2) {
%4 = tail call i32 @fwrite(float* %1, i32 1, i32 786432, i32* %0)
%5 = icmp eq i32 %4, 786432
br i1 %5, label %6, label %9
6: ; preds = %3
%7 = tail call i32 @fwrite(float* %2, i32 1, i32 786432, i32* %0)
%8 = icmp eq i32 %7, 786432
br i1 %8, label %13, label %9
9: ; preds = %6, %3
%10 = phi i8* [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0), %6 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* %10)
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ 0, %6 ], [ -1, %9 ]
ret i32 %14
}