#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 char *ssize_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
char *write(int, char *, int);
int main() {
  int fd;
  ssize_t size;
  fd = open("data.in", O_RDWR);
  assert(fd >= 0);
  printf("open %d successfully!\n", fd);
  printf("please execute: rm %s in another terminal...\n", "data.in");
  sleep(10);
  size = write(fd, "xixi", 4);
  printf("write %zd bytes!\n", size);
  printf("Now, will close the file:%s\n", "data.in");
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%esi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6f(%rip),%rdi
lea    0xe49(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
mov    -0x8(%rbp),%edi
lea    0xe7b(%rip),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rbx
mov    %rbx,%rdi
call   1070 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1060 <assert@plt>
lea    0xe78(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1080 <sleep@plt>
lea    0xe92(%rip),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1030 <write@plt>
lea    0xe84(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebp,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"data.in\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"open %d successfully!\0A\00"
@.str.2 = [46 x i8] c"please execute: rm %s in another terminal...\0A\00"
@.str.3 = [5 x i8] c"xixi\00"
@.str.4 = [18 x i8] c"write %zd bytes!\0A\00"
@.str.5 = [29 x i8] c"Now, will close the file:%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp sge i32 %6, 0
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @sleep(i32 10)
%14 = load i32, i32* %2
%15 = call i8* @write(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
store i8* %15, i8** %3
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %16)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = call i32 @close(i32 %19)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"data.in\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"open %d successfully!\0A\00"
@.str.2 = [46 x i8] c"please execute: rm %s in another terminal...\0A\00"
@.str.3 = [5 x i8] c"xixi\00"
@.str.4 = [18 x i8] c"write %zd bytes!\0A\00"
@.str.5 = [29 x i8] c"Now, will close the file:%s\0A\00"
define i32 @main() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = xor i32 %2, -1
%4 = lshr i32 %3, 31
%5 = tail call i32 @assert(i32 %4)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %2)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @sleep(i32 10)
%9 = tail call i8* @write(i32 %2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i32 4)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @close(i32 %2)
ret i32 0
}