#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*/ fdatasync(int);
int /*<<< orphan*/ fsync(int);
int write(int, char *, int);
int set_loading(int fd, int value) {
  int rc = 0;
  if (value == -1)
    rc = write(fd, "-1", 3);
  else if (value == 0)
    rc = write(fd, "0", 2);
  else if (value == 1)
    rc = write(fd, "1", 2);
  fsync(fd);
  fdatasync(fd);
  return rc < 0 ? rc : 0;
}


x86 assembly (clang, -O0):
<set_loading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    116b <set_loading+0x3b>
mov    -0x4(%rbp),%edi
lea    0xea7(%rip),%rsi
mov    $0x3,%edx
call   1040 <write@plt>
mov    %eax,-0xc(%rbp)
jmp    11bc <set_loading+0x8c>
cmpl   $0x0,-0x8(%rbp)
jne    1191 <set_loading+0x61>
mov    -0x4(%rbp),%edi
lea    0xe84(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %eax,-0xc(%rbp)
jmp    11b7 <set_loading+0x87>
cmpl   $0x1,-0x8(%rbp)
jne    11b2 <set_loading+0x82>
mov    -0x4(%rbp),%edi
lea    0xe5c(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %eax,-0xc(%rbp)
jmp    11b7 <set_loading+0x87>
jmp    11bc <set_loading+0x8c>
mov    -0x4(%rbp),%edi
call   1050 <fsync@plt>
mov    -0x4(%rbp),%edi
call   1030 <fdatasync@plt>
cmpl   $0x0,-0xc(%rbp)
jge    11e1 <set_loading+0xb1>
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    11eb <set_loading+0xbb>
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    11eb <set_loading+0xbb>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_loading>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x1,%esi
je     1155 <set_loading+0x25>
test   %esi,%esi
je     115e <set_loading+0x2e>
xor    %ebp,%ebp
cmp    $0xffffffff,%esi
jne    1173 <set_loading+0x43>
lea    0xeb4(%rip),%rsi
mov    %ebx,%edi
mov    $0x3,%edx
jmp    116c <set_loading+0x3c>
lea    0xea5(%rip),%rsi
jmp    1165 <set_loading+0x35>
lea    0xe9e(%rip),%rsi
mov    %ebx,%edi
mov    $0x2,%edx
call   1040 <write@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1050 <fsync@plt>
mov    %ebx,%edi
call   1030 <fdatasync@plt>
mov    %ebp,%eax
sar    $0x1f,%eax
and    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"-1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"1\00"
define i32 @set_loading(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %3
%10 = call i32 @write(i32 %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
store i32 %10, i32* %5
br label %25
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %3
%16 = call i32 @write(i32 %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %16, i32* %5
br label %24
17: ; preds = %11
%18 = load i32, i32* %4
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %3
%22 = call i32 @write(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 %22, i32* %5
br label %23
23: ; preds = %20, %17
br label %24
24: ; preds = %23, %14
br label %25
25: ; preds = %24, %8
%26 = load i32, i32* %3
%27 = call i32 @fsync(i32 %26)
%28 = load i32, i32* %3
%29 = call i32 @fdatasync(i32 %28)
%30 = load i32, i32* %5
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = load i32, i32* %5
br label %35
34: ; preds = %25
br label %35
35: ; preds = %34, %32
%36 = phi i32 [ %33, %32 ], [ 0, %34 ]
ret i32 %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"-1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"1\00"
define i32 @set_loading(i32 %0, i32 %1) {
switch i32 %1, label %9 [
i32 -1, label %3
i32 0, label %5
i32 1, label %7
]
3: ; preds = %2
%4 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 3)
br label %9
5: ; preds = %2
%6 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %9
7: ; preds = %2
%8 = tail call i32 @write(i32 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 2)
br label %9
9: ; preds = %2, %5, %7, %3
%10 = phi i32 [ %4, %3 ], [ %6, %5 ], [ %8, %7 ], [ 0, %2 ]
%11 = tail call i32 @fsync(i32 %0)
%12 = tail call i32 @fdatasync(i32 %0)
%13 = icmp slt i32 %10, 0
%14 = select i1 %13, i32 %10, i32 0
ret i32 %14
}