#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 /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int mkdir(char *, int);
int rename(char *, char *);
int symlink(char *, char *);
int main(int argc, char **argv) {
  if (mkdir("dir1", 0755) == -1)
    return 1;
  if (mkdir("dir2", 0755) == -1)
    return 1;
  {
    FILE *orig = fopen("dir1/file", "w");
    if (orig == NULL)
      return 1;
    fclose(orig);
    if (rename("dir1/file", "dir2/file") == -1)
      return 1;
  }
  if (symlink("dirN/something", "dir2/brokensymlink") == -1)
    return 1;
  if (symlink("dir1", "dir2/symlink") == -1)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    118c <main+0x3c>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
lea    0xe72(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    11b2 <main+0x62>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
lea    0xe51(%rip),%rdi
lea    0xe54(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <main+0x90>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe1a(%rip),%rdi
lea    0xe1f(%rip),%rsi
call   1070 <rename@plt>
cmp    $0xffffffff,%eax
jne    1211 <main+0xc1>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
lea    0xe08(%rip),%rdi
lea    0xe10(%rip),%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
jne    1239 <main+0xe9>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
lea    0xdc0(%rip),%rdi
lea    0xdfb(%rip),%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
jne    1261 <main+0x111>
movl   $0x1,-0x4(%rbp)
jmp    1268 <main+0x118>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    $0x1,%ebx
cmp    $0xffffffff,%eax
je     11f1 <main+0xa1>
lea    0xe8e(%rip),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0xa1>
lea    0xe7d(%rip),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f1 <main+0xa1>
mov    %rax,%rdi
call   1040 <fclose@plt>
lea    0xe5d(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1070 <rename@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0xa1>
lea    0xe5b(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1050 <symlink@plt>
cmp    $0xffffffff,%eax
je     11f1 <main+0xa1>
lea    0xe23(%rip),%rdi
lea    0xe5e(%rip),%rsi
call   1050 <symlink@plt>
xor    %ebx,%ebx
cmp    $0xffffffff,%eax
sete   %bl
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"dir1\00"
@.str.1 = [5 x i8] c"dir2\00"
@.str.2 = [10 x i8] c"dir1/file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [10 x i8] c"dir2/file\00"
@.str.5 = [15 x i8] c"dirN/something\00"
@.str.6 = [19 x i8] c"dir2/brokensymlink\00"
@.str.7 = [13 x i8] c"dir2/symlink\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 493)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 1, i32* %3
br label %34
10: ; preds = %2
%11 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 493)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 1, i32* %3
br label %34
14: ; preds = %10
%15 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 1, i32* %3
br label %34
19: ; preds = %14
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
%22 = call i32 @rename(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 1, i32* %3
br label %34
25: ; preds = %19
%26 = call i32 @symlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 1, i32* %3
br label %34
29: ; preds = %25
%30 = call i32 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 1, i32* %3
br label %34
33: ; preds = %29
store i32 0, i32* %3
br label %34
34: ; preds = %33, %32, %28, %24, %18, %13, %9
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [5 x i8] c"dir1\00"
@.str.1 = [5 x i8] c"dir2\00"
@.str.2 = [10 x i8] c"dir1/file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [10 x i8] c"dir2/file\00"
@.str.5 = [15 x i8] c"dirN/something\00"
@.str.6 = [19 x i8] c"dir2/brokensymlink\00"
@.str.7 = [13 x i8] c"dir2/symlink\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 493)
%4 = icmp eq i32 %3, -1
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = tail call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 493)
%7 = icmp eq i32 %6, -1
br i1 %7, label %22, label %8
8: ; preds = %5
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %8
%12 = tail call i32 @fclose(i32* %9)
%13 = tail call i32 @rename(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i32 %13, -1
br i1 %14, label %22, label %15
15: ; preds = %11
%16 = tail call i32 @symlink(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%17 = icmp eq i32 %16, -1
br i1 %17, label %22, label %18
18: ; preds = %15
%19 = tail call i32 @symlink(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%20 = icmp eq i32 %19, -1
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %8, %18, %15, %11, %5, %2
%23 = phi i32 [ 1, %11 ], [ 1, %2 ], [ 1, %5 ], [ 1, %15 ], [ %21, %18 ], [ 1, %8 ]
ret i32 %23
}