#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
scalar_t__ unlink(char *);
main() {
  int tub;
  char buf[11];
  tub = open("fictub", O_RDONLY);
  read(tub, buf, 10);
  buf[10] = 0;
  printf("J’ai lu %s\n", buf);
  if (unlink("fictub") < 0) {
    perror("Unlink avant close");
  }
  sleep(60);
  printf("Apres unlink");
  read(tub, buf, 10);
  buf[10] = 0;
  printf("J’ai lu %s\n", buf);
  if (close(tub) < 0) {
    perror("close Apres unlink");
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
lea    0xe61(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,-0x9(%rbp)
lea    -0x13(%rbp),%rsi
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2b(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    11f0 <main+0x70>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
lea    0xe2d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x13(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,-0x9(%rbp)
lea    -0x13(%rbp),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
jge    124d <main+0xcd>
lea    0xde0(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
lea    0xe67(%rip),%r14
mov    %r14,%rdi
call   1070 <open@plt>
mov    %eax,%ebx
lea    0x5(%rsp),%r15
mov    %eax,%edi
mov    %r15,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,0xf(%rsp)
lea    0xe44(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    11e6 <main+0x66>
lea    0xe34(%rip),%rdi
call   1080 <perror@plt>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
lea    0xe37(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x5(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,0xf(%rsp)
lea    0xde9(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
test   %rax,%rax
jns    1240 <main+0xc0>
lea    0xded(%rip),%rdi
call   1080 <perror@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"fictub\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"J\E2\80\99ai lu %s\0A\00"
@.str.2 = [19 x i8] c"Unlink avant close\00"
@.str.3 = [13 x i8] c"Apres unlink\00"
@.str.4 = [19 x i8] c"close Apres unlink\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [11 x i8]
store i32 0, i32* %1
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%8 = call i32 @read(i32 %6, i8* %7, i32 10)
%9 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 0, i8* %9
%10 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = call i64 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %0
%17 = call i32 @sleep(i32 60)
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32, i32* %2
%20 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%21 = call i32 @read(i32 %19, i8* %20, i32 10)
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 0, i8* %22
%23 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %2
%26 = call i64 @close(i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
%31 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"fictub\00"
@O_RDONLY = global i32 0
@.str.1 = [14 x i8] c"J\E2\80\99ai lu %s\0A\00"
@.str.2 = [19 x i8] c"Unlink avant close\00"
@.str.3 = [13 x i8] c"Apres unlink\00"
@.str.4 = [19 x i8] c"close Apres unlink\00"
define i32 @main() {
%1 = alloca [11 x i8]
%2 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = call i32 @read(i32 %4, i8* %2, i32 10)
%6 = getelementptr inbounds [11 x i8], [11 x i8]* %1, i64 0, i64 10
store i8 0, i8* %6
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%8 = call i64 @unlink(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32 @sleep(i32 60)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @read(i32 %4, i8* %2, i32 10)
store i8 0, i8* %6
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%17 = call i64 @close(i32 %4)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %19, %12
%22 = call i32 @exit(i32 0)
unreachable
}