#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 /*<<< orphan*/ ENOMEM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int fmustach(char const *, struct mustach_itf *, void *, int /*<<< orphan*/ *);
int fdmustach(const char *template, struct mustach_itf *itf, void *closure,
              int fd) {
  int rc;
  FILE *file;
  file = fdopen(fd, "w");
  if (file == NULL) {
    rc = -1;
    errno = ENOMEM;
  } else {
    rc = fmustach(template, itf, closure, file);
    fclose(file);
  }
  return rc;
}


x86 assembly (clang, -O0):
<fdmustach>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
lea    0xeaf(%rip),%rsi
call   1040 <fdopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1183 <fdmustach+0x53>
movl   $0xffffffff,-0x20(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%ecx
mov    0x2e5c(%rip),%rax
mov    %ecx,(%rax)
jmp    11a4 <fdmustach+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1050 <fmustach@plt>
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fdmustach>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xeb8(%rip),%rsi
mov    %ecx,%edi
call   1040 <fdopen@plt>
test   %rax,%rax
je     1176 <fdmustach+0x46>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
call   1050 <fmustach@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
jmp    118d <fdmustach+0x5d>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    0x2e52(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.mustach_itf = type { i32 }
@.str = [2 x i8] c"w\00"
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @fdmustach(i8* %0, %struct.mustach_itf* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca %struct.mustach_itf*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i8* %0, i8** %5
store %struct.mustach_itf* %1, %struct.mustach_itf** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = call i32* @fdopen(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 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 = %4
store i32 -1, i32* %9
%16 = load i32, i32* @ENOMEM
store i32 %16, i32* @errno
br label %25
17: ; preds = %4
%18 = load i8*, i8** %5
%19 = load %struct.mustach_itf*, %struct.mustach_itf** %6
%20 = load i8*, i8** %7
%21 = load i32*, i32** %10
%22 = call i32 @fmustach(i8* %18, %struct.mustach_itf* %19, i8* %20, i32* %21)
store i32 %22, i32* %9
%23 = load i32*, i32** %10
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %17, %15
%26 = load i32, i32* %9
ret i32 %26
}

LLVM IR (-O2):
%struct.mustach_itf = type { i32 }
@.str = [2 x i8] c"w\00"
@ENOMEM = global i32 0
@errno = global i32 0
define i32 @fdmustach(i8* %0, %struct.mustach_itf* %1, i8* %2, i32 %3) {
%5 = tail call i32* @fdopen(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = load i32, i32* @ENOMEM
store i32 %8, i32* @errno
br label %12
9: ; preds = %4
%10 = tail call i32 @fmustach(i8* %0, %struct.mustach_itf* %1, i8* %2, i32* %5)
%11 = tail call i32 @fclose(i32* %5)
br label %12
12: ; preds = %9, %7
%13 = phi i32 [ -1, %7 ], [ %10, %9 ]
ret i32 %13
}