#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*/ assert(int);
int fputc(int, int /*<<< orphan*/ *);
scalar_t__ ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ *tape_attach(char *);
int /*<<< orphan*/ tape_detach();
char *tmpnam(int /*<<< orphan*/ *);
void test_tape_attach_file_doesnt_exist() {
  char *filename = tmpnam(NULL);
  FILE *fp = tape_attach(filename);
  assert(fp != NULL);
  assert(ftell(fp) == 0);
  assert(fputc(65, fp) == 65);
  tape_detach();
}


x86 assembly (clang, -O0):
<test_tape_attach_file_doesnt_exist>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1080 <tmpnam@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <tape_attach@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rsi
mov    $0x41,%edi
call   1040 <fputc@plt>
cmp    $0x41,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    $0x0,%al
call   1030 <tape_detach@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_tape_attach_file_doesnt_exist>:
push   %rbx
xor    %edi,%edi
call   1080 <tmpnam@plt>
mov    %rax,%rdi
call   1070 <tape_attach@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    $0x41,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
xor    %edi,%edi
cmp    $0x41,%eax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
pop    %rbx
jmp    1030 <tape_detach@plt>

LLVM IR (-O0):
define void @test_tape_attach_file_doesnt_exist() {
%1 = alloca i8*
%2 = alloca i32*
%3 = call i8* @tmpnam(i32* null)
store i8* %3, i8** %1
%4 = load i8*, i8** %1
%5 = call i32* @tape_attach(i8* %4)
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32*, i32** %2
%11 = call i64 @ftell(i32* %10)
%12 = icmp eq i64 %11, 0
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i32*, i32** %2
%16 = call i32 @fputc(i32 65, i32* %15)
%17 = icmp eq i32 %16, 65
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 (...) @tape_detach()
ret void
}

LLVM IR (-O2):
define void @test_tape_attach_file_doesnt_exist() {
%1 = tail call i8* @tmpnam(i32* null)
%2 = tail call i32* @tape_attach(i8* %1)
%3 = icmp ne i32* %2, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i64 @ftell(i32* %2)
%7 = icmp eq i64 %6, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @fputc(i32 65, i32* %2)
%11 = icmp eq i32 %10, 65
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = tail call i32 (...) @tape_detach()
ret void
}