#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 */
struct stat {
  int st_nlink;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ create_file(int (*)(char const *, int), char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ getcwd(char *, int);
int getpid();
scalar_t__ link(char *, char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ unlink(char *);
int test_flcow(int (*ofunc)(char const *, int, ...), char const *ext) {
  struct stat stb1, stb2;
  char buf[512], name1[512], name2[512];
  getcwd(buf, sizeof(buf) - 1);
  setenv("FLCOW_PATH", buf, 1);
  sprintf(name1, ",,flcow-test1++.%u", getpid());
  if (create_file(ofunc, name1, "FLCOW Test Data Before") < 0) {
    fprintf(stdout, "[%s] Test Result\t\t[ FAILED ]\n", ext);
    return 1;
  }
  fprintf(stdout, "[%s] File Creation\t\t[ OK ]\n", ext);
  sprintf(name2, ",,flcow-test2++.%u", getpid());
  if (link(name1, name2) < 0) {
    unlink(name1);
    fprintf(stdout, "[%s] Test Result\t\t[ FAILED ]\n", ext);
    return 2;
  }
  fprintf(stdout, "[%s] Link Creation\t\t[ OK ]\n", ext);
  stat(name1, &stb1);
  stat(name2, &stb2);
  if (stb1.st_nlink < 2 || stb2.st_nlink < 2) {
    unlink(name2);
    unlink(name1);
    fprintf(stdout, "[%s] Link Check\t\t[ FAILED ]\n", ext);
    return 3;
  }
  fprintf(stdout, "[%s] Link Check\t\t[ OK ]\n", ext);
  if (create_file(ofunc, name1, "FLCOW Test Data After") < 0) {
    unlink(name2);
    unlink(name1);
    fprintf(stdout, "[%s] File Rewrite\t\t[ FAILED ]\n", ext);
    return 4;
  }
  fprintf(stdout, "[%s] File Rewrite\t\t[ OK ]\n", ext);
  stat(name1, &stb1);
  stat(name2, &stb2);
  if (stb1.st_nlink > 1 || stb2.st_nlink > 1) {
    unlink(name2);
    unlink(name1);
    fprintf(stdout, "[%s] COW Check\t\t[ FAILED ]\n", ext);
    return 5;
  }
  fprintf(stdout, "[%s] COW Check\t\t[ OK ]\n", ext);
  unlink(name2);
  unlink(name1);
  fprintf(stdout, "[%s] Test Result\t\t[ OK ]\n\n", ext);
  return 0;
}


x86 assembly (clang, -O0):
<test_flcow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x640,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x230(%rbp),%rdi
mov    $0x1ff,%esi
call   1060 <getcwd@plt>
lea    -0x230(%rbp),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x1,%edx
call   1040 <setenv@plt>
lea    -0x430(%rbp),%rax
mov    %rax,-0x638(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x638(%rbp),%rdi
mov    %eax,%edx
lea    0xe1a(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
lea    0xe16(%rip),%rdx
call   1090 <create_file@plt>
cmp    $0x0,%rax
jge    123c <test_flcow+0xac>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0a(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14a9 <test_flcow+0x319>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x630(%rbp),%rax
mov    %rax,-0x640(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0x640(%rbp),%rdi
mov    %eax,%edx
lea    0xdf5(%rip),%rsi
call   10a0 <sprintf@plt>
lea    -0x430(%rbp),%rdi
lea    -0x630(%rbp),%rsi
call   10b0 <link@plt>
cmp    $0x0,%rax
jge    12cd <test_flcow+0x13d>
lea    -0x430(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd79(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14a9 <test_flcow+0x319>
mov    0x2d0c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xda1(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x430(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
lea    -0x630(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmpl   $0x2,-0x20(%rbp)
jl     131a <test_flcow+0x18a>
cmpl   $0x2,-0x28(%rbp)
jge    1357 <test_flcow+0x1c7>
lea    -0x630(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x430(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd58(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    14a9 <test_flcow+0x319>
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd50(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
lea    0xd52(%rip),%rdx
call   1090 <create_file@plt>
cmp    $0x0,%rax
jge    13ce <test_flcow+0x23e>
lea    -0x630(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x430(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd2d(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x4,-0x4(%rbp)
jmp    14a9 <test_flcow+0x319>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd27(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x430(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
lea    -0x630(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1080 <stat@plt>
cmpl   $0x1,-0x20(%rbp)
jg     141b <test_flcow+0x28b>
cmpl   $0x1,-0x28(%rbp)
jle    1458 <test_flcow+0x2c8>
lea    -0x630(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x430(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2ba6(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcdd(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x5,-0x4(%rbp)
jmp    14a9 <test_flcow+0x319>
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcd4(%rip),%rsi
call   1070 <fprintf@plt>
lea    -0x630(%rbp),%rdi
call   1030 <unlink@plt>
lea    -0x430(%rbp),%rdi
call   1030 <unlink@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xcbb(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x640,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_flcow>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x610,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1060 <getcwd@plt>
lea    0xe3f(%rip),%rdi
mov    $0x1,%ebp
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <setenv@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe2a(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
lea    0xe27(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1090 <create_file@plt>
mov    0x2dd7(%rip),%r12
mov    (%r12),%edi
test   %rax,%rax
js     135d <test_flcow+0x1cd>
lea    0xe36(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe3c(%rip),%rsi
lea    0x210(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10a0 <sprintf@plt>
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   10b0 <link@plt>
test   %rax,%rax
js     1371 <test_flcow+0x1e1>
mov    (%r12),%edi
lea    0xe1c(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
lea    0x210(%rsp),%rdi
mov    %rsp,%rsi
call   1080 <stat@plt>
cmpl   $0x2,0x8(%rsp)
jl     1398 <test_flcow+0x208>
cmpl   $0x1,(%rsp)
jle    1398 <test_flcow+0x208>
mov    (%r12),%edi
lea    0xe0e(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
lea    0xe18(%rip),%rdx
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1090 <create_file@plt>
test   %rax,%rax
js     13c9 <test_flcow+0x239>
mov    (%r12),%edi
lea    0xe2c(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <stat@plt>
lea    0x210(%rsp),%rdi
mov    %rsp,%rsi
call   1080 <stat@plt>
cmpl   $0x1,0x8(%rsp)
jg     13fa <test_flcow+0x26a>
cmpl   $0x2,(%rsp)
jge    13fa <test_flcow+0x26a>
mov    (%r12),%edi
lea    0xe1c(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
lea    0x210(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    (%r12),%edi
lea    0xe0a(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
xor    %ebp,%ebp
jmp    1429 <test_flcow+0x299>
lea    0xcd1(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
jmp    1429 <test_flcow+0x299>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    (%r12),%edi
lea    0xcaf(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x2,%ebp
jmp    1429 <test_flcow+0x299>
lea    0x210(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    (%r12),%edi
lea    0xce4(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x3,%ebp
jmp    1429 <test_flcow+0x299>
lea    0x210(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    (%r12),%edi
lea    0xcff(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x4,%ebp
jmp    1429 <test_flcow+0x299>
lea    0x210(%rsp),%rdi
call   1030 <unlink@plt>
lea    0x10(%rsp),%rdi
call   1030 <unlink@plt>
mov    (%r12),%edi
lea    0xd08(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    $0x5,%ebp
mov    %ebp,%eax
add    $0x610,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [11 x i8] c"FLCOW_PATH\00"
@.str.1 = [19 x i8] c",,flcow-test1++.%u\00"
@.str.2 = [23 x i8] c"FLCOW Test Data Before\00"
@stdout = global i32 0
@.str.3 = [30 x i8] c"[%s] Test Result\09\09[ FAILED ]\0A\00"
@.str.4 = [28 x i8] c"[%s] File Creation\09\09[ OK ]\0A\00"
@.str.5 = [19 x i8] c",,flcow-test2++.%u\00"
@.str.6 = [28 x i8] c"[%s] Link Creation\09\09[ OK ]\0A\00"
@.str.7 = [29 x i8] c"[%s] Link Check\09\09[ FAILED ]\0A\00"
@.str.8 = [25 x i8] c"[%s] Link Check\09\09[ OK ]\0A\00"
@.str.9 = [22 x i8] c"FLCOW Test Data After\00"
@.str.10 = [31 x i8] c"[%s] File Rewrite\09\09[ FAILED ]\0A\00"
@.str.11 = [27 x i8] c"[%s] File Rewrite\09\09[ OK ]\0A\00"
@.str.12 = [28 x i8] c"[%s] COW Check\09\09[ FAILED ]\0A\00"
@.str.13 = [24 x i8] c"[%s] COW Check\09\09[ OK ]\0A\00"
@.str.14 = [27 x i8] c"[%s] Test Result\09\09[ OK ]\0A\0A\00"
define i32 @test_flcow(i32 (i8*, i32, ...)* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32 (i8*, i32, ...)*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca %struct.stat
%8 = alloca [512 x i8]
%9 = alloca [512 x i8]
%10 = alloca [512 x i8]
store i32 (i8*, i32, ...)* %0, i32 (i8*, i32, ...)** %4
store i8* %1, i8** %5
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%12 = call i32 @getcwd(i8* %11, i32 511)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %8, i64 0, i64 0
%14 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %13, i32 1)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%16 = call i32 (...) @getpid()
%17 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = load i32 (i8*, i32, ...)*, i32 (i8*, i32, ...)** %4
%19 = bitcast i32 (i8*, i32, ...)* %18 to i32 (i8*, i32)*
%20 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%21 = call i64 @create_file(i32 (i8*, i32)* %19, i8* %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %2
%24 = load i32, i32* @stdout
%25 = load i8*, i8** %5
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %118
27: ; preds = %2
%28 = load i32, i32* @stdout
%29 = load i8*, i8** %5
%30 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%32 = call i32 (...) @getpid()
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%35 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%36 = call i64 @link(i8* %34, i8* %35)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %27
%39 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%40 = call i32 @unlink(i8* %39)
%41 = load i32, i32* @stdout
%42 = load i8*, i8** %5
%43 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i32 2, i32* %3
br label %118
44: ; preds = %27
%45 = load i32, i32* @stdout
%46 = load i8*, i8** %5
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %46)
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%49 = call i32 @stat(i8* %48, %struct.stat* %6)
%50 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%51 = call i32 @stat(i8* %50, %struct.stat* %7)
%52 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%53 = load i32, i32* %52
%54 = icmp slt i32 %53, 2
br i1 %54, label %59, label %55
55: ; preds = %44
%56 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%57 = load i32, i32* %56
%58 = icmp slt i32 %57, 2
br i1 %58, label %59, label %67
59: ; preds = %55, %44
%60 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%61 = call i32 @unlink(i8* %60)
%62 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%63 = call i32 @unlink(i8* %62)
%64 = load i32, i32* @stdout
%65 = load i8*, i8** %5
%66 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %65)
store i32 3, i32* %3
br label %118
67: ; preds = %55
%68 = load i32, i32* @stdout
%69 = load i8*, i8** %5
%70 = call i32 @fprintf(i32 %68, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %69)
%71 = load i32 (i8*, i32, ...)*, i32 (i8*, i32, ...)** %4
%72 = bitcast i32 (i8*, i32, ...)* %71 to i32 (i8*, i32)*
%73 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%74 = call i64 @create_file(i32 (i8*, i32)* %72, i8* %73, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%75 = icmp slt i64 %74, 0
br i1 %75, label %76, label %84
76: ; preds = %67
%77 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%78 = call i32 @unlink(i8* %77)
%79 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%80 = call i32 @unlink(i8* %79)
%81 = load i32, i32* @stdout
%82 = load i8*, i8** %5
%83 = call i32 @fprintf(i32 %81, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i8* %82)
store i32 4, i32* %3
br label %118
84: ; preds = %67
%85 = load i32, i32* @stdout
%86 = load i8*, i8** %5
%87 = call i32 @fprintf(i32 %85, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i8* %86)
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%89 = call i32 @stat(i8* %88, %struct.stat* %6)
%90 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%91 = call i32 @stat(i8* %90, %struct.stat* %7)
%92 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%93 = load i32, i32* %92
%94 = icmp sgt i32 %93, 1
br i1 %94, label %99, label %95
95: ; preds = %84
%96 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%97 = load i32, i32* %96
%98 = icmp sgt i32 %97, 1
br i1 %98, label %99, label %107
99: ; preds = %95, %84
%100 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%101 = call i32 @unlink(i8* %100)
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%103 = call i32 @unlink(i8* %102)
%104 = load i32, i32* @stdout
%105 = load i8*, i8** %5
%106 = call i32 @fprintf(i32 %104, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %105)
store i32 5, i32* %3
br label %118
107: ; preds = %95
%108 = load i32, i32* @stdout
%109 = load i8*, i8** %5
%110 = call i32 @fprintf(i32 %108, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %109)
%111 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%112 = call i32 @unlink(i8* %111)
%113 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%114 = call i32 @unlink(i8* %113)
%115 = load i32, i32* @stdout
%116 = load i8*, i8** %5
%117 = call i32 @fprintf(i32 %115, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %116)
store i32 0, i32* %3
br label %118
118: ; preds = %107, %99, %76, %59, %38, %23
%119 = load i32, i32* %3
ret i32 %119
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [11 x i8] c"FLCOW_PATH\00"
@.str.1 = [19 x i8] c",,flcow-test1++.%u\00"
@.str.2 = [23 x i8] c"FLCOW Test Data Before\00"
@stdout = global i32 0
@.str.3 = [30 x i8] c"[%s] Test Result\09\09[ FAILED ]\0A\00"
@.str.4 = [28 x i8] c"[%s] File Creation\09\09[ OK ]\0A\00"
@.str.5 = [19 x i8] c",,flcow-test2++.%u\00"
@.str.6 = [28 x i8] c"[%s] Link Creation\09\09[ OK ]\0A\00"
@.str.7 = [29 x i8] c"[%s] Link Check\09\09[ FAILED ]\0A\00"
@.str.8 = [25 x i8] c"[%s] Link Check\09\09[ OK ]\0A\00"
@.str.9 = [22 x i8] c"FLCOW Test Data After\00"
@.str.10 = [31 x i8] c"[%s] File Rewrite\09\09[ FAILED ]\0A\00"
@.str.11 = [27 x i8] c"[%s] File Rewrite\09\09[ OK ]\0A\00"
@.str.12 = [28 x i8] c"[%s] COW Check\09\09[ FAILED ]\0A\00"
@.str.13 = [24 x i8] c"[%s] COW Check\09\09[ OK ]\0A\00"
@.str.14 = [27 x i8] c"[%s] Test Result\09\09[ OK ]\0A\0A\00"
define i32 @test_flcow(i32 (i8*, i32, ...)* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca [512 x i8]
%6 = alloca [512 x i8]
%7 = alloca [512 x i8]
%8 = bitcast %struct.stat* %3 to i8*
%9 = bitcast %struct.stat* %4 to i8*
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [512 x i8], [512 x i8]* %7, i64 0, i64 0
%13 = call i32 @getcwd(i8* %10, i32 511)
%14 = call i32 @setenv(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %10, i32 1)
%15 = call i32 (...) @getpid()
%16 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = bitcast i32 (i8*, i32, ...)* %0 to i32 (i8*, i32)*
%18 = call i64 @create_file(i32 (i8*, i32)* %17, i8* %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp slt i64 %18, 0
%20 = load i32, i32* @stdout
br i1 %19, label %21, label %23
21: ; preds = %2
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %82
23: ; preds = %2
%24 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %1)
%25 = call i32 (...) @getpid()
%26 = call i32 @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = call i64 @link(i8* %11, i8* %12)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %23
%30 = call i32 @unlink(i8* %11)
%31 = load i32, i32* @stdout
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8* %1)
br label %82
33: ; preds = %23
%34 = load i32, i32* @stdout
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %1)
%36 = call i32 @stat(i8* %11, %struct.stat* %3)
%37 = call i32 @stat(i8* %12, %struct.stat* %4)
%38 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%39 = load i32, i32* %38
%40 = icmp slt i32 %39, 2
%41 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%42 = load i32, i32* %41
%43 = icmp slt i32 %42, 2
%44 = select i1 %40, i1 true, i1 %43
br i1 %44, label %45, label %50
45: ; preds = %33
%46 = call i32 @unlink(i8* %12)
%47 = call i32 @unlink(i8* %11)
%48 = load i32, i32* @stdout
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.7, i64 0, i64 0), i8* %1)
br label %82
50: ; preds = %33
%51 = load i32, i32* @stdout
%52 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), i8* %1)
%53 = call i64 @create_file(i32 (i8*, i32)* %17, i8* %11, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%54 = icmp slt i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %50
%56 = call i32 @unlink(i8* %12)
%57 = call i32 @unlink(i8* %11)
%58 = load i32, i32* @stdout
%59 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i8* %1)
br label %82
60: ; preds = %50
%61 = load i32, i32* @stdout
%62 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), i8* %1)
%63 = call i32 @stat(i8* %11, %struct.stat* %3)
%64 = call i32 @stat(i8* %12, %struct.stat* %4)
%65 = load i32, i32* %38
%66 = icmp sgt i32 %65, 1
%67 = load i32, i32* %41
%68 = icmp sgt i32 %67, 1
%69 = select i1 %66, i1 true, i1 %68
br i1 %69, label %70, label %75
70: ; preds = %60
%71 = call i32 @unlink(i8* %12)
%72 = call i32 @unlink(i8* %11)
%73 = load i32, i32* @stdout
%74 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.12, i64 0, i64 0), i8* %1)
br label %82
75: ; preds = %60
%76 = load i32, i32* @stdout
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.13, i64 0, i64 0), i8* %1)
%78 = call i32 @unlink(i8* %12)
%79 = call i32 @unlink(i8* %11)
%80 = load i32, i32* @stdout
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %1)
br label %82
82: ; preds = %75, %70, %55, %45, %29, %21
%83 = phi i32 [ 1, %21 ], [ 2, %29 ], [ 3, %45 ], [ 4, %55 ], [ 5, %70 ], [ 0, %75 ]
ret i32 %83
}