#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 */
scalar_t__ EOF;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fputs(char const *, int /*<<< orphan*/ *);
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ *tmpfile();
FILE *str_tmpfile(const char *str) {
  FILE *file;
  if (!(file = tmpfile()))
    return NULL;
  if (fputs(str, file) == EOF)
    goto error;
  if (fseek(file, 0, SEEK_SET) == -1)
    goto error;
  return file;
error:
  fclose(file);
  return NULL;
}


x86 assembly (clang, -O0):
<str_tmpfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <tmpfile@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    116e <str_tmpfile+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11d0 <str_tmpfile+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <fputs@plt>
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%rax
jne    1190 <str_tmpfile+0x50>
jmp    11bf <str_tmpfile+0x7f>
mov    -0x18(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    11b2 <str_tmpfile+0x72>
jmp    11bf <str_tmpfile+0x7f>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d0 <str_tmpfile+0x90>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_tmpfile>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <tmpfile@plt>
test   %rax,%rax
je     118d <str_tmpfile+0x4d>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <fputs@plt>
mov    0x2e80(%rip),%rcx
cmp    (%rcx),%rax
je     1185 <str_tmpfile+0x45>
mov    0x2e64(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0xffffffff,%eax
jne    118f <str_tmpfile+0x4f>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i64 0
@SEEK_SET = global i32 0
define i32* @str_tmpfile(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = call i32* (...) @tmpfile()
store i32* %5, i32** %4
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i32* null, i32** %2
br label %26
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = load i32*, i32** %4
%11 = call i64 @fputs(i8* %9, i32* %10)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %8
br label %23
15: ; preds = %8
%16 = load i32*, i32** %4
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i32 0, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %15
br label %23
21: ; preds = %15
%22 = load i32*, i32** %4
store i32* %22, i32** %2
br label %26
23: ; preds = %20, %14
%24 = load i32*, i32** %4
%25 = call i32 @fclose(i32* %24)
store i32* null, i32** %2
br label %26
26: ; preds = %23, %21, %7
%27 = load i32*, i32** %2
ret i32* %27
}

LLVM IR (-O2):
@EOF = global i64 0
@SEEK_SET = global i32 0
define noalias i32* @str_tmpfile(i8* nocapture %0) {
%2 = tail call i32* (...) @tmpfile()
%3 = icmp eq i32* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1
%5 = tail call i64 @fputs(i8* %0, i32* %2)
%6 = load i64, i64* @EOF
%7 = icmp eq i64 %5, %6
br i1 %7, label %12, label %8
8: ; preds = %4
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %2, i32 0, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %8, %4
%13 = tail call i32 @fclose(i32* %2)
br label %14
14: ; preds = %8, %1, %12
%15 = phi i32* [ null, %12 ], [ null, %1 ], [ %2, %8 ]
ret i32* %15
}