#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 */
typedef int uint32_t;
typedef int pid_t;

/* Variables and functions */
int LOCK_EX;
int LOCK_NB;
int NAME_MAX;
int O_CREAT;
int O_SYNC;
int O_WRONLY;
int PATH_MAX;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ flock(int, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ ftruncate(int, int /*<<< orphan*/);
int getpid();
int /*<<< orphan*/ mkdir(char *, int);
int open(char *, int, int);
int remove(char *);
int /*<<< orphan*/ sleep(int);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ write(int, char *, int);
int check_collision(const char *program_name, uint32_t flags) {
  char program[NAME_MAX];
  char dir[NAME_MAX];
  if (flags & (2))
    strncpy(dir, "tmp", NAME_MAX);
  else
    strncpy(dir, "run", NAME_MAX);
  strncpy(program, program_name, NAME_MAX);
  char path[PATH_MAX];
  strcpy(path, "/");
  strcat(path, dir);
  strcat(path, "/");
  strcat(path, program);
  mkdir(path, 00755);
  strcat(path, "/");
  strcat(path, program);
  strcat(path, ".pid");
  int flock_flag = LOCK_EX;
  if (flags & (1)) {
    flock_flag = flock_flag | LOCK_NB;
  }
  int success = -1;
  while (1) {
    pid_t pid = getpid();
    int fd = open(path, O_CREAT | O_SYNC | O_WRONLY, 00644);
    if (fd < 0) {
      fprintf(stderr, "Cannot open lock file\n");
      fprintf(stderr, "%d\n", remove(path));
      fflush(stderr);
      sleep(1);
      continue;
    }
    if (flock(fd, flock_flag) < 0) {
      close(fd);
      fprintf(stderr, "Someone is using lock file\n");
      fflush(stderr);
      break;
    }
    if (ftruncate(fd, 0) < 0) {
      fprintf(stderr, "truncate failed\n");
      fflush(stderr);
      break;
    }
    success = 0;
    char pid_buf[NAME_MAX];
    int len = snprintf(pid_buf, NAME_MAX, "%d\n", pid);
    write(fd, pid_buf, len);
    break;
  }
  return success;
}


x86 assembly (clang, -O0):
<check_collision>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x68(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     1279 <check_collision+0x89>
mov    -0x60(%rbp),%rdi
mov    0x2d42(%rip),%rax
mov    (%rax),%edx
lea    0xd91(%rip),%rsi
call   1030 <strncpy@plt>
jmp    1292 <check_collision+0xa2>
mov    -0x60(%rbp),%rdi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
lea    0xd77(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x68(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    0x2d39(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x70(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
lea    0xd34(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x60(%rbp),%rsi
mov    -0x70(%rbp),%rdi
call   1100 <strcat@plt>
mov    -0x70(%rbp),%rdi
lea    0xd17(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdi
call   1100 <strcat@plt>
mov    -0x70(%rbp),%rdi
mov    $0x1ed,%esi
call   1060 <mkdir@plt>
mov    -0x70(%rbp),%rdi
lea    0xcec(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x68(%rbp),%rsi
mov    -0x70(%rbp),%rdi
call   1100 <strcat@plt>
mov    -0x70(%rbp),%rdi
lea    0xcd1(%rip),%rsi
call   1100 <strcat@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0xc(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1368 <check_collision+0x178>
mov    -0x34(%rbp),%eax
mov    0x2c3d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x34(%rbp)
movl   $0xffffffff,-0x38(%rbp)
jmp    1374 <check_collision+0x184>
mov    $0x0,%al
call   1080 <getpid@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,-0x3c(%rbp)
mov    0x2c6f(%rip),%rax
mov    (%rax),%esi
mov    0x2c46(%rip),%rax
or     (%rax),%esi
mov    0x2c15(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
call   10e0 <open@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1410 <check_collision+0x220>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
lea    0xc4b(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x70(%rbp),%rdi
mov    0x2bea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
call   1040 <remove@plt>
mov    -0x74(%rbp),%edi
mov    %eax,%edx
lea    0xc3a(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
jmp    136f <check_collision+0x17f>
mov    -0x40(%rbp),%edi
mov    -0x34(%rbp),%esi
call   10f0 <flock@plt>
cmp    $0x0,%rax
jge    1457 <check_collision+0x267>
mov    -0x40(%rbp),%edi
call   10b0 <close@plt>
mov    0x2b8c(%rip),%rax
mov    (%rax),%edi
lea    0xbed(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2b75(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    14f9 <check_collision+0x309>
mov    -0x40(%rbp),%edi
xor    %esi,%esi
call   10a0 <ftruncate@plt>
cmp    $0x0,%rax
jge    1495 <check_collision+0x2a5>
mov    0x2b4e(%rip),%rax
mov    (%rax),%edi
lea    0xbcb(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    0x2b37(%rip),%rax
mov    (%rax),%edi
call   10d0 <fflush@plt>
jmp    14f9 <check_collision+0x309>
movl   $0x0,-0x38(%rbp)
mov    0x2b05(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x80(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    0x2ad9(%rip),%rax
mov    (%rax),%esi
mov    -0x3c(%rbp),%ecx
lea    0xb4b(%rip),%rdx
call   1090 <snprintf@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,-0x54(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x54(%rbp),%edx
call   1070 <write@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x38(%rbp),%eax
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_collision>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%r15
mov    0x2d9d(%rip),%r12
mov    (%r12),%edx
mov    %rsp,%r14
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
test   $0x2,%r13b
lea    0xdcd(%rip),%rax
lea    0xdc2(%rip),%rsi
cmove  %rax,%rsi
mov    %rbx,%rdi
call   1030 <strncpy@plt>
mov    (%r12),%edx
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <strncpy@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xd8e(%rip),%r12
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <strcpy@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1100 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1100 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1100 <strcat@plt>
mov    %r15,%rdi
mov    $0x1ed,%esi
call   1060 <mkdir@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1100 <strcat@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1100 <strcat@plt>
lea    0xd3a(%rip),%rsi
mov    %r15,%rdi
call   1100 <strcat@plt>
mov    0x2cf1(%rip),%rax
and    $0x1,%r13d
neg    %r13d
mov    0x2cb3(%rip),%rcx
and    (%rcx),%r13d
or     (%rax),%r13d
xor    %eax,%eax
call   1080 <getpid@plt>
mov    0x2cf7(%rip),%rdx
mov    0x2cd0(%rip),%rcx
mov    (%rcx),%esi
or     (%rdx),%esi
mov    %eax,%r12d
mov    0x2c9a(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
mov    $0x1a4,%edx
call   10e0 <open@plt>
test   %eax,%eax
js     1330 <check_collision+0x140>
mov    %eax,%ebx
jmp    13cb <check_collision+0x1db>
mov    %r13d,-0x2c(%rbp)
mov    0x2c85(%rip),%r13
lea    0xce4(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%r13),%edi
lea    0xcb4(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%r13),%ebx
mov    %r15,%rdi
call   1040 <remove@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    0x0(%r13),%edi
call   10d0 <fflush@plt>
mov    $0x1,%edi
call   1110 <sleep@plt>
xor    %eax,%eax
call   1080 <getpid@plt>
mov    %eax,%r12d
mov    0x2c38(%rip),%rax
mov    (%rax),%esi
mov    0x2c4f(%rip),%rax
or     (%rax),%esi
mov    0x2bfe(%rip),%rax
or     (%rax),%esi
mov    %r15,%rdi
mov    $0x1a4,%edx
call   10e0 <open@plt>
test   %eax,%eax
js     1350 <check_collision+0x160>
mov    %eax,%ebx
mov    -0x2c(%rbp),%r13d
mov    %ebx,%edi
mov    %r13d,%esi
call   10f0 <flock@plt>
test   %rax,%rax
js     142d <check_collision+0x23d>
xor    %r14d,%r14d
mov    %ebx,%edi
xor    %esi,%esi
call   10a0 <ftruncate@plt>
test   %rax,%rax
js     1446 <check_collision+0x256>
mov    %rsp,%r13
mov    0x2bb3(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    (%rcx),%esi
lea    0xc15(%rip),%rdx
mov    %r15,%rdi
mov    %r12d,%ecx
call   1090 <snprintf@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1070 <write@plt>
mov    %r13,%rsp
jmp    146a <check_collision+0x27a>
mov    %ebx,%edi
call   10b0 <close@plt>
mov    0x2b85(%rip),%rbx
mov    (%rbx),%edi
lea    0xbe6(%rip),%rsi
jmp    1456 <check_collision+0x266>
mov    0x2b73(%rip),%rbx
mov    (%rbx),%edi
lea    0xbf0(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
call   10d0 <fflush@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@NAME_MAX = global i32 0
@.str = [4 x i8] c"tmp\00"
@.str.1 = [4 x i8] c"run\00"
@PATH_MAX = global i32 0
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [5 x i8] c".pid\00"
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@O_CREAT = global i32 0
@O_SYNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.4 = [23 x i8] c"Cannot open lock file\0A\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [28 x i8] c"Someone is using lock file\0A\00"
@.str.7 = [17 x i8] c"truncate failed\0A\00"
define i32 @check_collision(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%16 = load i32, i32* @NAME_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %5
%19 = alloca i8, i64 %17
store i64 %17, i64* %6
%20 = load i32, i32* @NAME_MAX
%21 = zext i32 %20 to i64
%22 = alloca i8, i64 %21
store i64 %21, i64* %7
%23 = load i32, i32* %4
%24 = and i32 %23, 2
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = load i32, i32* @NAME_MAX
%28 = call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %27)
br label %32
29: ; preds = %2
%30 = load i32, i32* @NAME_MAX
%31 = call i32 @strncpy(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %26
%33 = load i8*, i8** %3
%34 = load i32, i32* @NAME_MAX
%35 = call i32 @strncpy(i8* %19, i8* %33, i32 %34)
%36 = load i32, i32* @PATH_MAX
%37 = zext i32 %36 to i64
%38 = alloca i8, i64 %37
store i64 %37, i64* %8
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = call i32 @strcat(i8* %38, i8* %22)
%41 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @strcat(i8* %38, i8* %19)
%43 = call i32 @mkdir(i8* %38, i32 493)
%44 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @strcat(i8* %38, i8* %19)
%46 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%47 = load i32, i32* @LOCK_EX
store i32 %47, i32* %9
%48 = load i32, i32* %4
%49 = and i32 %48, 1
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %32
%52 = load i32, i32* %9
%53 = load i32, i32* @LOCK_NB
%54 = or i32 %52, %53
store i32 %54, i32* %9
br label %55
55: ; preds = %51, %32
store i32 -1, i32* %10
br label %56
56: ; preds = %67, %55
br label %57
57: ; preds = %56
%58 = call i32 (...) @getpid()
store i32 %58, i32* %11
%59 = load i32, i32* @O_CREAT
%60 = load i32, i32* @O_SYNC
%61 = or i32 %59, %60
%62 = load i32, i32* @O_WRONLY
%63 = or i32 %61, %62
%64 = call i32 @open(i8* %38, i32 %63, i32 420)
store i32 %64, i32* %12
%65 = load i32, i32* %12
%66 = icmp slt i32 %65, 0
br i1 %66, label %67, label %76
67: ; preds = %57
%68 = load i32, i32* @stderr
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%70 = load i32, i32* @stderr
%71 = call i32 @remove(i8* %38)
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %71)
%73 = load i32, i32* @stderr
%74 = call i32 @fflush(i32 %73)
%75 = call i32 @sleep(i32 1)
br label %56
76: ; preds = %57
%77 = load i32, i32* %12
%78 = load i32, i32* %9
%79 = call i64 @flock(i32 %77, i32 %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %88
81: ; preds = %76
%82 = load i32, i32* %12
%83 = call i32 @close(i32 %82)
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%86 = load i32, i32* @stderr
%87 = call i32 @fflush(i32 %86)
br label %109
88: ; preds = %76
%89 = load i32, i32* %12
%90 = call i64 @ftruncate(i32 %89, i32 0)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%95 = load i32, i32* @stderr
%96 = call i32 @fflush(i32 %95)
br label %109
97: ; preds = %88
store i32 0, i32* %10
%98 = load i32, i32* @NAME_MAX
%99 = zext i32 %98 to i64
%100 = call i8* @llvm.stacksave()
store i8* %100, i8** %13
%101 = alloca i8, i64 %99
store i64 %99, i64* %14
%102 = load i32, i32* @NAME_MAX
%103 = load i32, i32* %11
%104 = call i32 @snprintf(i8* %101, i32 %102, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %103)
store i32 %104, i32* %15
%105 = load i32, i32* %12
%106 = load i32, i32* %15
%107 = call i32 @write(i32 %105, i8* %101, i32 %106)
%108 = load i8*, i8** %13
br label %109
109: ; preds = %97, %92, %81
%110 = load i32, i32* %10
%111 = load i8*, i8** %5
ret i32 %110
}

LLVM IR (-O2):
@NAME_MAX = global i32 0
@.str = [4 x i8] c"tmp\00"
@.str.1 = [4 x i8] c"run\00"
@PATH_MAX = global i32 0
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [5 x i8] c".pid\00"
@LOCK_EX = global i32 0
@LOCK_NB = global i32 0
@O_CREAT = global i32 0
@O_SYNC = global i32 0
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str.4 = [23 x i8] c"Cannot open lock file\0A\00"
@.str.5 = [4 x i8] c"%d\0A\00"
@.str.6 = [28 x i8] c"Someone is using lock file\0A\00"
@.str.7 = [17 x i8] c"truncate failed\0A\00"
define i32 @check_collision(i8* %0, i32 %1) {
%3 = load i32, i32* @NAME_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = and i32 %1, 2
%8 = icmp eq i32 %7, 0
%9 = select i1 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0)
%10 = call i32 @strncpy(i8* %6, i8* %9, i32 %3)
%11 = load i32, i32* @NAME_MAX
%12 = call i32 @strncpy(i8* %5, i8* %0, i32 %11)
%13 = load i32, i32* @PATH_MAX
%14 = zext i32 %13 to i64
%15 = alloca i8, i64 %14
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @strcat(i8* %15, i8* %6)
%18 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @strcat(i8* %15, i8* %5)
%20 = call i32 @mkdir(i8* %15, i32 493)
%21 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i32 @strcat(i8* %15, i8* %5)
%23 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @LOCK_EX
%25 = and i32 %1, 1
%26 = icmp eq i32 %25, 0
%27 = load i32, i32* @LOCK_NB
%28 = select i1 %26, i32 0, i32 %27
%29 = or i32 %28, %24
%30 = call i32 (...) @getpid()
%31 = load i32, i32* @O_CREAT
%32 = load i32, i32* @O_SYNC
%33 = or i32 %32, %31
%34 = load i32, i32* @O_WRONLY
%35 = or i32 %33, %34
%36 = call i32 @open(i8* %15, i32 %35, i32 420)
%37 = icmp slt i32 %36, 0
br i1 %37, label %65, label %38
38: ; preds = %65, %2
%39 = phi i32 [ %30, %2 ], [ %74, %65 ]
%40 = phi i32 [ %36, %2 ], [ %80, %65 ]
%41 = call i64 @flock(i32 %40, i32 %29)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = call i32 @close(i32 %40)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
%47 = load i32, i32* @stderr
%48 = call i32 @fflush(i32 %47)
br label %82
49: ; preds = %38
%50 = call i64 @ftruncate(i32 %40, i32 0)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %49
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%55 = load i32, i32* @stderr
%56 = call i32 @fflush(i32 %55)
br label %82
57: ; preds = %49
%58 = load i32, i32* @NAME_MAX
%59 = zext i32 %58 to i64
%60 = call i8* @llvm.stacksave()
%61 = alloca i8, i64 %59
%62 = load i32, i32* @NAME_MAX
%63 = call i32 @snprintf(i8* %61, i32 %62, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %39)
%64 = call i32 @write(i32 %40, i8* %61, i32 %63)
br label %82
65: ; preds = %2, %65
%66 = load i32, i32* @stderr
%67 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%68 = load i32, i32* @stderr
%69 = call i32 @remove(i8* %15)
%70 = call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %69)
%71 = load i32, i32* @stderr
%72 = call i32 @fflush(i32 %71)
%73 = call i32 @sleep(i32 1)
%74 = call i32 (...) @getpid()
%75 = load i32, i32* @O_CREAT
%76 = load i32, i32* @O_SYNC
%77 = or i32 %76, %75
%78 = load i32, i32* @O_WRONLY
%79 = or i32 %77, %78
%80 = call i32 @open(i8* %15, i32 %79, i32 420)
%81 = icmp slt i32 %80, 0
br i1 %81, label %65, label %38
82: ; preds = %43, %52, %57
%83 = phi i32 [ 0, %57 ], [ -1, %52 ], [ -1, %43 ]
ret i32 %83
}