#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fwrite(float *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
void save_grid(const char *filename, float *map, int size) {
  int i;
  FILE *fp = fopen(filename, "wb");
  i = fwrite(map, sizeof(float), size, fp);
  fclose(fp);
  if (i == size) {
    printf("Success");
  } else {
    printf("Failure! %d : %d", i, size);
  }
}


x86 assembly (clang, -O0):
<save_grid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1060 <fwrite@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    11a7 <save_grid+0x67>
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11bb <save_grid+0x7b>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xe57(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<save_grid>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbp
lea    0xeaf(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x4,%esi
mov    %r14d,%edx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    %r14d,%ebp
jne    118d <save_grid+0x4d>
lea    0xe81(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe77(%rip),%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [8 x i8] c"Success\00"
@.str.2 = [17 x i8] c"Failure! %d : %d\00"
define void @save_grid(i8* %0, float* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca float*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store float* %1, float** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %8
%11 = load float*, float** %5
%12 = load i32, i32* %6
%13 = load i32*, i32** %8
%14 = call i32 @fwrite(float* %11, i32 4, i32 %12, i32* %13)
store i32 %14, i32* %7
%15 = load i32*, i32** %8
%16 = call i32 @fclose(i32* %15)
%17 = load i32, i32* %7
%18 = load i32, i32* %6
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %3
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %26
22: ; preds = %3
%23 = load i32, i32* %7
%24 = load i32, i32* %6
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %23, i32 %24)
br label %26
26: ; preds = %22, %20
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [8 x i8] c"Success\00"
@.str.2 = [17 x i8] c"Failure! %d : %d\00"
define void @save_grid(i8* nocapture %0, float* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @fwrite(float* %1, i32 4, i32 %2, i32* %4)
%6 = tail call i32 @fclose(i32* %4)
%7 = icmp eq i32 %5, %2
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %12
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %5, i32 %2)
br label %12
12: ; preds = %10, %8
ret void
}