#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*/ XATTR_REPLACE;
int /*<<< orphan*/ connected();
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int setxattr(char *, char *, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ test_ftruncate_existing();
int /*<<< orphan*/ test_ftruncate_new_file();
int /*<<< orphan*/ test_truncate_existing();
int /*<<< orphan*/ test_truncate_new_file();
int main(void) {
  int result = 0;
  while (!connected()) {
    printf("Waiting for tsumufs to mount.\n");
    sleep(1);
  }
  printf("Mounted.\n");
  sleep(1);
  result = setxattr(".", "tsumufs.pause-sync", "1", strlen("1"), XATTR_REPLACE);
  if (result < 0) {
    perror("Unable to set pause-sync.");
    exit(1);
  }
  result = 0;
  if (!test_ftruncate_existing())
    result = 1;
  if (!test_truncate_existing())
    result = 1;
  if (!test_ftruncate_new_file())
    result = 1;
  if (!test_truncate_new_file())
    result = 1;
  return result;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1050 <connected@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11e2 <main+0x32>
jmp    11fd <main+0x4d>
lea    0xe17(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
jmp    11c6 <main+0x16>
lea    0xe1b(%rip),%rdi
call   1070 <printf@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
lea    0xe22(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    0x2db8(%rip),%rax
mov    (%rax),%r8d
lea    0xe24(%rip),%rdi
lea    0xdf0(%rip),%rsi
lea    0xdfc(%rip),%rdx
call   10b0 <setxattr@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1268 <main+0xb8>
lea    0xde5(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <test_ftruncate_existing@plt>
cmp    $0x0,%eax
jne    1286 <main+0xd6>
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   10c0 <test_truncate_existing@plt>
cmp    $0x0,%eax
jne    129d <main+0xed>
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   1080 <test_ftruncate_new_file@plt>
cmp    $0x0,%eax
jne    12b4 <main+0x104>
movl   $0x1,-0x8(%rbp)
mov    $0x0,%al
call   1030 <test_truncate_new_file@plt>
cmp    $0x0,%eax
jne    12cb <main+0x11b>
movl   $0x1,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1060 <connected@plt>
test   %eax,%eax
jne    11ed <main+0x3d>
lea    0xe72(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
xor    %eax,%eax
call   1060 <connected@plt>
test   %eax,%eax
je     11d0 <main+0x20>
lea    0xe3b(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10d0 <sleep@plt>
lea    0xe09(%rip),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    0x2dc7(%rip),%rcx
mov    (%rcx),%r8d
lea    0xe0a(%rip),%rdi
lea    0xdd6(%rip),%rsi
mov    %rbx,%rdx
mov    %eax,%ecx
call   10b0 <setxattr@plt>
test   %eax,%eax
js     127a <main+0xca>
xor    %eax,%eax
call   1050 <test_ftruncate_existing@plt>
test   %eax,%eax
sete   %bpl
xor    %eax,%eax
call   10c0 <test_truncate_existing@plt>
test   %eax,%eax
sete   %bl
xor    %eax,%eax
call   1080 <test_ftruncate_new_file@plt>
test   %eax,%eax
sete   %r14b
xor    %eax,%eax
call   1030 <test_truncate_new_file@plt>
test   %eax,%eax
sete   %al
or     %r14b,%al
or     %bpl,%bl
or     %al,%bl
movzbl %bl,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd94(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [31 x i8] c"Waiting for tsumufs to mount.\0A\00"
@.str.1 = [10 x i8] c"Mounted.\0A\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [19 x i8] c"tsumufs.pause-sync\00"
@.str.4 = [2 x i8] c"1\00"
@XATTR_REPLACE = global i32 0
@.str.5 = [26 x i8] c"Unable to set pause-sync.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
br label %3
3: ; preds = %7, %0
%4 = call i32 (...) @connected()
%5 = icmp ne i32 %4, 0
%6 = xor i1 %5, true
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @sleep(i32 1)
br label %3
10: ; preds = %3
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 @sleep(i32 1)
%13 = call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%14 = load i32, i32* @XATTR_REPLACE
%15 = call i32 @setxattr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %13, i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %10
%19 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %10
store i32 0, i32* %2
%22 = call i32 (...) @test_ftruncate_existing()
%23 = icmp ne i32 %22, 0
br i1 %23, label %25, label %24
24: ; preds = %21
store i32 1, i32* %2
br label %25
25: ; preds = %24, %21
%26 = call i32 (...) @test_truncate_existing()
%27 = icmp ne i32 %26, 0
br i1 %27, label %29, label %28
28: ; preds = %25
store i32 1, i32* %2
br label %29
29: ; preds = %28, %25
%30 = call i32 (...) @test_ftruncate_new_file()
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %29
store i32 1, i32* %2
br label %33
33: ; preds = %32, %29
%34 = call i32 (...) @test_truncate_new_file()
%35 = icmp ne i32 %34, 0
br i1 %35, label %37, label %36
36: ; preds = %33
store i32 1, i32* %2
br label %37
37: ; preds = %36, %33
%38 = load i32, i32* %2
ret i32 %38
}

LLVM IR (-O2):
@.str.2 = [2 x i8] c".\00"
@.str.3 = [19 x i8] c"tsumufs.pause-sync\00"
@.str.4 = [2 x i8] c"1\00"
@XATTR_REPLACE = global i32 0
@.str.5 = [26 x i8] c"Unable to set pause-sync.\00"
@str = [9 x i8] c"Mounted.\00"
@str.6 = [30 x i8] c"Waiting for tsumufs to mount.\00"
define i32 @main() {
%1 = tail call i32 (...) @connected()
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %8
3: ; preds = %0, %3
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.6, i64 0, i64 0))
%5 = tail call i32 @sleep(i32 1)
%6 = tail call i32 (...) @connected()
%7 = icmp eq i32 %6, 0
br i1 %7, label %3, label %8
8: ; preds = %3, %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%12 = load i32, i32* @XATTR_REPLACE
%13 = tail call i32 @setxattr(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %8
%19 = tail call i32 (...) @test_ftruncate_existing()
%20 = icmp eq i32 %19, 0
%21 = tail call i32 (...) @test_truncate_existing()
%22 = icmp eq i32 %21, 0
%23 = tail call i32 (...) @test_ftruncate_new_file()
%24 = icmp eq i32 %23, 0
%25 = tail call i32 (...) @test_truncate_new_file()
%26 = icmp eq i32 %25, 0
%27 = select i1 %26, i1 true, i1 %24
%28 = select i1 %27, i1 true, i1 %22
%29 = select i1 %28, i1 true, i1 %20
%30 = zext i1 %29 to i32
ret i32 %30
}