#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;
int close(int);
int errno;
int fsync(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int f = open("/", O_RDONLY);
  printf("fsync(opened): %d\n", fsync(f));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("close(opened): %d\n", close(f));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("fsync(closed): %d\n", fsync(f));
  printf("errno: %d\n", errno);
  errno = 0;
  printf("close(closed): %d\n", close(f));
  printf("errno: %d\n", errno);
  errno = 0;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <fsync@plt>
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3f(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%esi
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%esi
lea    0xe50(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e07(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%edi
call   1050 <fsync@plt>
mov    %eax,%esi
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%esi
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dcf(%rip),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    %eax,%esi
lea    0xe26(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
lea    0xde0(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d97(%rip),%rax
movl   $0x0,(%rax)
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1050 <fsync@plt>
lea    0xe98(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x2e60(%rip),%r15
mov    (%r15),%esi
lea    0xe93(%rip),%r14
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x0,(%r15)
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe81(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x0,(%r15)
mov    %ebx,%edi
call   1050 <fsync@plt>
lea    0xe6d(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x0,(%r15)
mov    %ebx,%edi
call   1040 <close@plt>
lea    0xe59(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    (%r15),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
movl   $0x0,(%r15)
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"fsync(opened): %d\0A\00"
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"close(opened): %d\0A\00"
@.str.4 = [19 x i8] c"fsync(closed): %d\0A\00"
@.str.5 = [19 x i8] c"close(closed): %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = load i32, i32* @O_RDONLY
%4 = call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %3)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @fsync(i32 %5)
%7 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @errno
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %8)
store i32 0, i32* @errno
%10 = load i32, i32* %2
%11 = call i32 @close(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @errno
%14 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i32 0, i32* @errno
%15 = load i32, i32* %2
%16 = call i32 @fsync(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %16)
%18 = load i32, i32* @errno
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %18)
store i32 0, i32* @errno
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @errno
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %23)
store i32 0, i32* @errno
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@O_RDONLY = global i32 0
@.str.1 = [19 x i8] c"fsync(opened): %d\0A\00"
@.str.2 = [11 x i8] c"errno: %d\0A\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"close(opened): %d\0A\00"
@.str.4 = [19 x i8] c"fsync(closed): %d\0A\00"
@.str.5 = [19 x i8] c"close(closed): %d\0A\00"
define i32 @main() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @fsync(i32 %2)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @errno
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %5)
store i32 0, i32* @errno
%7 = tail call i32 @close(i32 %2)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @errno
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %9)
store i32 0, i32* @errno
%11 = tail call i32 @fsync(i32 %2)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @errno
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %13)
store i32 0, i32* @errno
%15 = tail call i32 @close(i32 %2)
%16 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @errno
%18 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 0, i32* @errno
ret i32 0
}