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

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
size_t fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
size_t fwrite(unsigned int const *, size_t, unsigned int const,
              int /*<<< orphan*/ *);
int hvec_write(const char *file_in, const uint16_t *data,
               const unsigned int n) {
  size_t s = sizeof(uint16_t), i = 0;
  FILE *fid = fopen(file_in, "wb");
  if (fid == NULL)
    return EXIT_FAILURE;
  i = fwrite(&n, s, 1, fid);
  if (i != 1)
    return EXIT_FAILURE;
  i = fwrite(data, s, n, fid);
  if (i != n)
    return EXIT_FAILURE;
  i = fclose(fid);
  if (i != 0)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<hvec_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x4,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1183 <hvec_write+0x53>
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <hvec_write+0xf7>
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rcx
lea    -0x1c(%rbp),%rdi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x1,-0x30(%rbp)
je     11b9 <hvec_write+0x89>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <hvec_write+0xf7>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x38(%rbp),%rcx
call   1050 <fwrite@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmp    %rcx,%rax
je     11f2 <hvec_write+0xc2>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <hvec_write+0xf7>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     121b <hvec_write+0xeb>
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1227 <hvec_write+0xf7>
mov    0x2db6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hvec_write>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edx,0x4(%rsp)
lea    0xeba(%rip),%rsi
call   1040 <fopen@plt>
mov    0x2e8e(%rip),%r12
test   %rax,%rax
je     11b1 <hvec_write+0x81>
mov    %rax,%rbx
lea    0x4(%rsp),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
cmp    $0x1,%rax
jne    11b1 <hvec_write+0x81>
mov    0x4(%rsp),%r15d
mov    $0x4,%esi
mov    %r14,%rdi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
cmp    %r15,%rax
jne    11b1 <hvec_write+0x81>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    11aa <hvec_write+0x7a>
mov    0x2e30(%rip),%r12
jmp    11b1 <hvec_write+0x81>
mov    0x2e2f(%rip),%r12
mov    (%r12),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @hvec_write(i8* nocapture %0, i32* nocapture %1, i32 %2) {
%4 = alloca i32
store i32 %2, i32* %4
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %19, label %7
7: ; preds = %3
%8 = call i64 @fwrite(i32* %4, i64 4, i32 1, i32* %5)
%9 = icmp eq i64 %8, 1
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* %4
%12 = tail call i64 @fwrite(i32* %1, i64 4, i32 %11, i32* %5)
%13 = zext i32 %11 to i64
%14 = icmp eq i64 %12, %13
br i1 %14, label %15, label %19
15: ; preds = %10
%16 = tail call i64 @fclose(i32* %5)
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i32* @EXIT_SUCCESS, i32* @EXIT_FAILURE
br label %19
19: ; preds = %15, %10, %7, %3
%20 = phi i32* [ @EXIT_FAILURE, %3 ], [ @EXIT_FAILURE, %7 ], [ @EXIT_FAILURE, %10 ], [ %18, %15 ]
%21 = load i32, i32* %20
ret i32 %21
}