#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ unlink(char *);
void test_no_concurrent_opens() {
  FILE *fp, *fp1, *bad_fp;
  fp = fopen("test", "w");
  assert(fp);
  bad_fp = fopen("nope", "w");
  assert(!bad_fp);
  fp1 = fopen("test", "r");
  assert(fp1);
  fclose(fp1);
  fclose(fp);
  fp = fopen("test again", "w");
  assert(fp);
  fclose(fp);
  unlink("test again");
  unlink("test");
}


x86 assembly (clang, -O0):
<test_no_concurrent_opens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1050 <assert@plt>
lea    0xe96(%rip),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe64(%rip),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe3e(%rip),%rdi
lea    0xe2e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe13(%rip),%rdi
call   1030 <unlink@plt>
lea    0xdf9(%rip),%rdi
call   1030 <unlink@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_no_concurrent_opens>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%r14
lea    0xeaf(%rip),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
mov    %r12d,%edi
call   1050 <assert@plt>
lea    0xe94(%rip),%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
lea    0xe7c(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xe55(%rip),%r12
mov    %r12,%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %ebx,%edi
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r12,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <unlink@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"nope\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [11 x i8] c"test again\00"
define void @test_no_concurrent_opens() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = ptrtoint i32* %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp ne i32* %9, null
%11 = xor i1 %10, true
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %14, i32** %2
%15 = load i32*, i32** %2
%16 = ptrtoint i32* %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32*, i32** %2
%19 = call i32 @fclose(i32* %18)
%20 = load i32*, i32** %1
%21 = call i32 @fclose(i32* %20)
%22 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %1
%23 = load i32*, i32** %1
%24 = ptrtoint i32* %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32*, i32** %1
%27 = call i32 @fclose(i32* %26)
%28 = call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [5 x i8] c"nope\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [11 x i8] c"test again\00"
define void @test_no_concurrent_opens() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = ptrtoint i32* %1 to i64
%3 = trunc i64 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = ptrtoint i32* %9 to i64
%11 = trunc i64 %10 to i32
%12 = tail call i32 @assert(i32 %11)
%13 = tail call i32 @fclose(i32* %9)
%14 = tail call i32 @fclose(i32* %1)
%15 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = ptrtoint i32* %15 to i64
%17 = trunc i64 %16 to i32
%18 = tail call i32 @assert(i32 %17)
%19 = tail call i32 @fclose(i32* %15)
%20 = tail call i32 @unlink(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%21 = tail call i32 @unlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
ret void
}