#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 int64_t;

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
scalar_t__ read_int64_from_path(char *, int *);
scalar_t__ unlink(char *);
scalar_t__ write_int64_to_path(char *, int, int /*<<< orphan*/);
void test_int64_read_write(void) {
  int64_t i;
  assert(unlink("/tmp/test-read-write") == 0 || errno == ENOENT);
  assert(write_int64_to_path("/tmp/test-read-write", 0x7fabcdef00abcdef, 0) >=
         0);
  assert(read_int64_from_path("/tmp/test-read-write", &i) >= 0);
  assert(i == 0x7fabcdef00abcdef);
  assert(unlink("/tmp/test-read-write") == 0 || errno == ENOENT);
}


x86 assembly (clang, -O0):
<test_int64_read_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1030 <unlink@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x5(%rbp)
je     1180 <test_int64_read_write+0x40>
mov    0x2e73(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe6c(%rip),%rdi
mov    $0xabcdef,%esi
xor    %edx,%edx
call   1060 <write_int64_to_path@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe48(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1050 <read_int64_from_path@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movslq -0x4(%rbp),%rax
movabs $0x7fabcdef00abcdef,%rcx
cd ab 7f
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    0xe09(%rip),%rdi
call   1030 <unlink@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x6(%rbp)
je     1228 <test_int64_read_write+0xe8>
mov    0x2dcb(%rip),%rax
mov    (%rax),%rax
mov    0x2db1(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_int64_read_write>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xeb0(%rip),%rbx
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
sete   %al
mov    0x2e7b(%rip),%r14
mov    (%r14),%rcx
mov    0x2e61(%rip),%r15
cmp    (%r15),%rcx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    $0xabcdef,%esi
xor    %edx,%edx
call   1060 <write_int64_to_path@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1040 <assert@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <read_int64_from_path@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1040 <assert@plt>
xor    %edi,%edi
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
sete   %al
mov    (%r14),%rcx
cmp    (%r15),%rcx
sete   %cl
or     %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/tmp/test-read-write\00"
@errno = global i64 0
@ENOENT = global i64 0
define void @test_int64_read_write() {
%1 = alloca i32
%2 = call i64 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %0
%5 = load i64, i64* @errno
%6 = load i64, i64* @ENOENT
%7 = icmp eq i64 %5, %6
br label %8
8: ; preds = %4, %0
%9 = phi i1 [ true, %0 ], [ %7, %4 ]
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = call i64 @write_int64_to_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 11259375, i32 0)
%13 = icmp sge i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i64 @read_int64_from_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %1)
%17 = icmp sge i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %1
%21 = sext i32 %20 to i64
%22 = icmp eq i64 %21, 9199673090226507247
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = call i64 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %31, label %27
27: ; preds = %8
%28 = load i64, i64* @errno
%29 = load i64, i64* @ENOENT
%30 = icmp eq i64 %28, %29
br label %31
31: ; preds = %27, %8
%32 = phi i1 [ true, %8 ], [ %30, %27 ]
%33 = zext i1 %32 to i32
%34 = call i32 @assert(i32 %33)
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"/tmp/test-read-write\00"
@errno = global i64 0
@ENOENT = global i64 0
define void @test_int64_read_write() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i64 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
%5 = load i64, i64* @errno
%6 = load i64, i64* @ENOENT
%7 = icmp eq i64 %5, %6
%8 = select i1 %4, i1 true, i1 %7
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i64 @write_int64_to_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 11259375, i32 0)
%12 = lshr i64 %11, 63
%13 = trunc i64 %12 to i32
%14 = xor i32 %13, 1
%15 = tail call i32 @assert(i32 %14)
%16 = call i64 @read_int64_from_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32* %1)
%17 = lshr i64 %16, 63
%18 = trunc i64 %17 to i32
%19 = xor i32 %18, 1
%20 = call i32 @assert(i32 %19)
%21 = call i32 @assert(i32 0)
%22 = call i64 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp eq i64 %24, %25
%27 = select i1 %23, i1 true, i1 %26
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
ret void
}