#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 */
char *allocfile(char *, unsigned long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fwrite(void *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int __mp_writealloc(char *s, unsigned long n, void *a, size_t l) {
  FILE *f;
  char *t;
  int r;
  r = 0;
  t = allocfile(s, n);
  if ((f = fopen(t, "wb")) != NULL) {
    if (fwrite(a, sizeof(char), l, f) == l)
      r = 1;
    fclose(f);
    if (r == 0)
      remove(t);
  }
  return r;
}


x86 assembly (clang, -O0):
<__mp_writealloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <allocfile@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11e6 <__mp_writealloc+0x96>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
cmp    -0x20(%rbp),%rax
jne    11c5 <__mp_writealloc+0x75>
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x34(%rbp)
jne    11e1 <__mp_writealloc+0x91>
mov    -0x30(%rbp),%rdi
call   1040 <remove@plt>
jmp    11e6 <__mp_writealloc+0x96>
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mp_writealloc>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
call   1030 <allocfile@plt>
mov    %rax,%r12
lea    0xe93(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     11b1 <__mp_writealloc+0x61>
mov    %rax,%rbx
mov    $0x1,%ebp
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1070 <fwrite@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    %r14,%r15
je     11b1 <__mp_writealloc+0x61>
mov    %r12,%rdi
call   1040 <remove@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define i32 @__mp_writealloc(i8* %0, i64 %1, i8* nocapture %2, i64 %3) {
%5 = tail call i8* @allocfile(i8* %0, i64 %1)
%6 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %14, label %8
8: ; preds = %4
%9 = tail call i64 @fwrite(i8* %2, i32 1, i64 %3, i32* %6)
%10 = icmp eq i64 %9, %3
%11 = tail call i32 @fclose(i32* %6)
br i1 %10, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @remove(i8* %5)
br label %14
14: ; preds = %8, %12, %4
%15 = phi i32 [ 0, %12 ], [ 1, %8 ], [ 0, %4 ]
ret i32 %15
}