#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 */
struct mustach_itf {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int fmustach(char const *, struct mustach_itf *, void *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memfile_abort(int /*<<< orphan*/ *, char **, size_t *);
int memfile_close(int /*<<< orphan*/ *, char **, size_t *);
int /*<<< orphan*/ *memfile_open(char **, size_t *);
int mustach(const char *template, struct mustach_itf *itf, void *closure,
            char **result, size_t *size) {
  int rc;
  FILE *file;
  size_t s;
  *result = NULL;
  if (size == NULL)
    size = &s;
  file = memfile_open(result, size);
  if (file == NULL)
    rc = -1;
  else {
    rc = fmustach(template, itf, closure, file);
    if (rc < 0)
      memfile_abort(file, result, size);
    else
      rc = memfile_close(file, result, size);
  }
  return rc;
}


x86 assembly (clang, -O0):
<mustach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
jne    117a <mustach+0x3a>
lea    -0x40(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <memfile_open@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11a2 <mustach+0x62>
movl   $0xffffffff,-0x2c(%rbp)
jmp    11f3 <mustach+0xb3>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x38(%rbp),%rcx
call   1050 <fmustach@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11da <mustach+0x9a>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <memfile_abort@plt>
jmp    11ee <mustach+0xae>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <memfile_close@plt>
mov    %eax,-0x2c(%rbp)
jmp    11f3 <mustach+0xb3>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mustach>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%r13
movq   $0x0,(%rcx)
test   %r8,%r8
mov    %rsp,%rbx
cmovne %r8,%rbx
mov    %rcx,%rdi
mov    %rbx,%rsi
call   1060 <memfile_open@plt>
test   %rax,%rax
je     11a3 <mustach+0x63>
mov    %rax,%rbp
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
mov    %rax,%rcx
call   1050 <fmustach@plt>
test   %eax,%eax
js     11ab <mustach+0x6b>
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memfile_close@plt>
mov    %eax,%r15d
jmp    11bc <mustach+0x7c>
mov    $0xffffffff,%r15d
jmp    11bc <mustach+0x7c>
mov    %eax,%r15d
mov    %rbp,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <memfile_abort@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mustach_itf = type { i32 }
define i32 @mustach(i8* %0, %struct.mustach_itf* %1, i8* %2, i8** %3, i64* %4) {
%6 = alloca i8*
%7 = alloca %struct.mustach_itf*
%8 = alloca i8*
%9 = alloca i8**
%10 = alloca i64*
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i64
store i8* %0, i8** %6
store %struct.mustach_itf* %1, %struct.mustach_itf** %7
store i8* %2, i8** %8
store i8** %3, i8*** %9
store i64* %4, i64** %10
%14 = load i8**, i8*** %9
store i8* null, i8** %14
%15 = load i64*, i64** %10
%16 = icmp eq i64* %15, null
br i1 %16, label %17, label %18
17: ; preds = %5
store i64* %13, i64** %10
br label %18
18: ; preds = %17, %5
%19 = load i8**, i8*** %9
%20 = load i64*, i64** %10
%21 = call i32* @memfile_open(i8** %19, i64* %20)
store i32* %21, i32** %12
%22 = load i32*, i32** %12
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 -1, i32* %11
br label %44
25: ; preds = %18
%26 = load i8*, i8** %6
%27 = load %struct.mustach_itf*, %struct.mustach_itf** %7
%28 = load i8*, i8** %8
%29 = load i32*, i32** %12
%30 = call i32 @fmustach(i8* %26, %struct.mustach_itf* %27, i8* %28, i32* %29)
store i32 %30, i32* %11
%31 = load i32, i32* %11
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %25
%34 = load i32*, i32** %12
%35 = load i8**, i8*** %9
%36 = load i64*, i64** %10
%37 = call i32 @memfile_abort(i32* %34, i8** %35, i64* %36)
br label %43
38: ; preds = %25
%39 = load i32*, i32** %12
%40 = load i8**, i8*** %9
%41 = load i64*, i64** %10
%42 = call i32 @memfile_close(i32* %39, i8** %40, i64* %41)
store i32 %42, i32* %11
br label %43
43: ; preds = %38, %33
br label %44
44: ; preds = %43, %24
%45 = load i32, i32* %11
ret i32 %45
}

LLVM IR (-O2):
%struct.mustach_itf = type { i32 }
define i32 @mustach(i8* %0, %struct.mustach_itf* %1, i8* %2, i8** %3, i64* %4) {
%6 = alloca i64
%7 = bitcast i64* %6 to i8*
store i8* null, i8** %3
%8 = icmp eq i64* %4, null
%9 = select i1 %8, i64* %6, i64* %4
%10 = call i32* @memfile_open(i8** %3, i64* %9)
%11 = icmp eq i32* %10, null
br i1 %11, label %19, label %12
12: ; preds = %5
%13 = call i32 @fmustach(i8* %0, %struct.mustach_itf* %1, i8* %2, i32* %10)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @memfile_abort(i32* %10, i8** %3, i64* %9)
br label %19
17: ; preds = %12
%18 = call i32 @memfile_close(i32* %10, i8** %3, i64* %9)
br label %19
19: ; preds = %5, %15, %17
%20 = phi i32 [ %13, %15 ], [ %18, %17 ], [ -1, %5 ]
ret i32 %20
}