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

/* Variables and functions */
int fwrite(int const *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int ivec_fwrite(FILE *f, const int *v, int d) {
  int ret = fwrite(&d, sizeof(d), 1, f);
  if (ret != 1) {
    perror("ivec_fwrite: write error 1");
    return -1;
  }
  ret = fwrite(v, sizeof(*v), d, f);
  if (ret != d) {
    perror("ivec_fwrite: write error 2");
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<ivec_fwrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
call   1040 <fwrite@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
je     116f <ivec_fwrite+0x4f>
lea    0xea2(%rip),%rdi
call   1030 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b2 <ivec_fwrite+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rcx
mov    $0x4,%esi
call   1040 <fwrite@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
je     11ab <ivec_fwrite+0x8b>
lea    0xe81(%rip),%rdi
call   1030 <perror@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11b2 <ivec_fwrite+0x92>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ivec_fwrite>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %edx,0xc(%rsp)
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
cmp    $0x1,%eax
jne    1175 <ivec_fwrite+0x55>
mov    0xc(%rsp),%ebp
mov    %r14,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1040 <fwrite@plt>
xor    %ebx,%ebx
cmp    %ebp,%eax
jne    1183 <ivec_fwrite+0x63>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    $0xffffffff,%ebx
lea    0xe7f(%rip),%rdi
jmp    118f <ivec_fwrite+0x6f>
mov    $0xfffffffe,%ebx
lea    0xe8c(%rip),%rdi
call   1030 <perror@plt>
jmp    116a <ivec_fwrite+0x4a>

LLVM IR (-O0):
@.str = [27 x i8] c"ivec_fwrite: write error 1\00"
@.str.1 = [27 x i8] c"ivec_fwrite: write error 2\00"
define i32 @ivec_fwrite(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%9 = load i32*, i32** %5
%10 = call i32 @fwrite(i32* %7, i32 4, i32 1, i32* %9)
store i32 %10, i32* %8
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %26
15: ; preds = %3
%16 = load i32*, i32** %6
%17 = load i32, i32* %7
%18 = load i32*, i32** %5
%19 = call i32 @fwrite(i32* %16, i32 4, i32 %17, i32* %18)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = load i32, i32* %7
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %4
br label %26
25: ; preds = %15
store i32 0, i32* %4
br label %26
26: ; preds = %25, %23, %13
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@.str = [27 x i8] c"ivec_fwrite: write error 1\00"
@.str.1 = [27 x i8] c"ivec_fwrite: write error 2\00"
define i32 @ivec_fwrite(i32* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca i32
store i32 %2, i32* %4
%5 = call i32 @fwrite(i32* %4, i32 4, i32 1, i32* %0)
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %11
7: ; preds = %3
%8 = load i32, i32* %4
%9 = tail call i32 @fwrite(i32* %1, i32 4, i32 %8, i32* %0)
%10 = icmp eq i32 %9, %8
br i1 %10, label %15, label %11
11: ; preds = %7, %3
%12 = phi i8* [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), %7 ]
%13 = phi i32 [ -1, %3 ], [ -2, %7 ]
%14 = tail call i32 @perror(i8* %12)
br label %15
15: ; preds = %11, %7
%16 = phi i32 [ 0, %7 ], [ %13, %11 ]
ret i32 %16
}