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

/* Variables and functions */
scalar_t__ ENOENT;
int /*<<< orphan*/ assert(int);
scalar_t__ errno;
scalar_t__ read_int32_from_path(char *, int *);
scalar_t__ unlink(char *);
scalar_t__ write_int32_to_path(char *, int, int /*<<< orphan*/);
void test_int32_read_write(void) {
  int32_t i;
  assert(unlink("/tmp/test-read-write") == 0 || errno == ENOENT);
  assert(write_int32_to_path("/tmp/test-read-write", 0x7fabcdef, 0) >= 0);
  assert(read_int32_from_path("/tmp/test-read-write", &i) >= 0);
  assert(i == 0x7fabcdef);
  assert(unlink("/tmp/test-read-write") == 0 || errno == ENOENT);
}


x86 assembly (clang, -O0):
<test_int32_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_int32_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   1050 <assert@plt>
lea    0xe6c(%rip),%rdi
mov    $0x7fabcdef,%esi
xor    %edx,%edx
call   1040 <write_int32_to_path@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe48(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1060 <read_int32_from_path@plt>
cmp    $0x0,%rax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x7fabcdef,-0x4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    0xe13(%rip),%rdi
call   1030 <unlink@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x6(%rbp)
je     121e <test_int32_read_write+0xde>
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    0x2dbb(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x6(%rbp)
mov    -0x6(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_int32_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   1050 <assert@plt>
mov    %rbx,%rdi
mov    $0x7fabcdef,%esi
xor    %edx,%edx
call   1040 <write_int32_to_path@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1050 <assert@plt>
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1060 <read_int32_from_path@plt>
shr    $0x3f,%rax
xor    $0x1,%eax
mov    %eax,%edi
call   1050 <assert@plt>
xor    %edi,%edi
cmpl   $0x7fabcdef,0xc(%rsp)
7f
sete   %dil
call   1050 <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   1050 <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_int32_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_int32_to_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2141965807, i32 0)
%13 = icmp sge i64 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i64 @read_int32_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 = icmp eq i32 %20, 2141965807
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = call i64 @unlink(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %8
%27 = load i64, i64* @errno
%28 = load i64, i64* @ENOENT
%29 = icmp eq i64 %27, %28
br label %30
30: ; preds = %26, %8
%31 = phi i1 [ true, %8 ], [ %29, %26 ]
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
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_int32_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_int32_to_path(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 2141965807, 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_int32_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 = load i32, i32* %1
%22 = icmp eq i32 %21, 2141965807
%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
%27 = load i64, i64* @errno
%28 = load i64, i64* @ENOENT
%29 = icmp eq i64 %27, %28
%30 = select i1 %26, i1 true, i1 %29
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
ret void
}