#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 uint32_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 hvecs32_write(const char *file_in, const uint32_t *data,
                  const unsigned int n, const unsigned int m) {
  size_t s1 = sizeof(uint32_t), s2 = sizeof(uint32_t), i = 0, k = 0;
  FILE *fid = fopen(file_in, "wb");
  if (fid == NULL)
    return EXIT_FAILURE;
  for (i = 0; i < n; i++) {
    k = fwrite(&m, s1, 1, fid);
    if (k != 1)
      return EXIT_FAILURE;
    k = fwrite(data + i * m, s2, m, fid);
    if (k != m)
      return EXIT_FAILURE;
  }
  k = fclose(fid);
  if (k != 0)
    return EXIT_FAILURE;
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<hvecs32_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movq   $0x4,-0x28(%rbp)
movq   $0x4,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1196 <hvecs32_write+0x66>
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <hvecs32_write+0x14a>
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cmp    %rcx,%rax
jae    1245 <hvecs32_write+0x115>
mov    -0x28(%rbp),%rsi
mov    -0x48(%rbp),%rcx
lea    -0x20(%rbp),%rdi
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x1,-0x40(%rbp)
je     11e4 <hvecs32_write+0xb4>
mov    0x2e06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <hvecs32_write+0x14a>
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
imul   %rcx,%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x20(%rbp),%edx
mov    -0x48(%rbp),%rcx
call   1050 <fwrite@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x20(%rbp),%ecx
cmp    %rcx,%rax
je     122f <hvecs32_write+0xff>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <hvecs32_write+0x14a>
jmp    1234 <hvecs32_write+0x104>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    119e <hvecs32_write+0x6e>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     126e <hvecs32_write+0x13e>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    127a <hvecs32_write+0x14a>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hvecs32_write>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %ecx,0x4(%rsp)
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
mov    0x2e86(%rip),%rax
test   %rbx,%rbx
je     11d4 <hvecs32_write+0xa4>
test   %ebp,%ebp
je     11b7 <hvecs32_write+0x87>
mov    %ebp,%r13d
xor    %r12d,%r12d
lea    0x4(%rsp),%r15
xchg   %ax,%ax
mov    $0x4,%esi
mov    %r15,%rdi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
cmp    $0x1,%rax
jne    11cd <hvecs32_write+0x9d>
mov    0x4(%rsp),%ebp
mov    %r12,%rax
imul   %rbp,%rax
lea    (%r14,%rax,4),%rdi
mov    $0x4,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
cmp    %rbp,%rax
jne    11cd <hvecs32_write+0x9d>
add    $0x1,%r12
cmp    %r12,%r13
jne    1170 <hvecs32_write+0x40>
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rax,%rax
jne    11cd <hvecs32_write+0x9d>
mov    0x2e0d(%rip),%rax
jmp    11d4 <hvecs32_write+0xa4>
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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