#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_RDWR;
int /*<<< orphan*/ close(int);
int fsync(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void file_sync(void) {
  int fd = 0;
  fd = open("/mnt/mmc/.nvramblock", O_RDWR);
  if (-1 == fd) {
    perror("file_sync open");
    return;
  }
  if (-1 == fsync(fd)) {
    perror("file_sync fsync");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<file_sync>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x4(%rbp)
mov    $0xffffffff,%eax
cmp    -0x4(%rbp),%eax
jne    1186 <file_sync+0x46>
lea    0xe99(%rip),%rdi
call   1060 <perror@plt>
jmp    11b1 <file_sync+0x71>
mov    -0x4(%rbp),%edi
call   1040 <fsync@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    11a9 <file_sync+0x69>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_sync>:
push   %rbx
mov    0x2ea0(%rip),%rax
mov    (%rax),%esi
lea    0xeaf(%rip),%rdi
call   1050 <open@plt>
cmp    $0xffffffff,%eax
je     1171 <file_sync+0x31>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <fsync@plt>
cmp    $0xffffffff,%eax
je     117e <file_sync+0x3e>
mov    %ebx,%edi
pop    %rbx
jmp    1030 <close@plt>
lea    0xe9d(%rip),%rdi
pop    %rbx
jmp    1060 <perror@plt>
lea    0xe9f(%rip),%rdi
call   1060 <perror@plt>
jmp    1169 <file_sync+0x29>

LLVM IR (-O0):
@.str = [21 x i8] c"/mnt/mmc/.nvramblock\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"file_sync open\00"
@.str.2 = [16 x i8] c"file_sync fsync\00"
define void @file_sync() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @O_RDWR
%3 = call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %2)
store i32 %3, i32* %1
%4 = load i32, i32* %1
%5 = icmp eq i32 -1, %4
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %17
8: ; preds = %0
%9 = load i32, i32* %1
%10 = call i32 @fsync(i32 %9)
%11 = icmp eq i32 -1, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i32, i32* %1
%16 = call i32 @close(i32 %15)
br label %17
17: ; preds = %14, %6
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"/mnt/mmc/.nvramblock\00"
@O_RDWR = global i32 0
@.str.1 = [15 x i8] c"file_sync open\00"
@.str.2 = [16 x i8] c"file_sync fsync\00"
define void @file_sync() {
%1 = load i32, i32* @O_RDWR
%2 = tail call i32 @open(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp eq i32 %2, -1
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %13
6: ; preds = %0
%7 = tail call i32 @fsync(i32 %2)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = tail call i32 @close(i32 %2)
br label %13
13: ; preds = %11, %4
ret void
}