#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*/ printf(char *, int);
int symlink(char *, char *);
int /*<<< orphan*/ tsleep();
int /*<<< orphan*/ unlink(char *);
int main(int argc, char *argv[]) {
  char *target = "/home/target/public_html/targetfile\0";
  char *dummy = "/home/example/public_html/dummy\0";
  char *sym = "/home/example/public_html/link\0";
  symlink(dummy, sym);
  int trv, drv;
  while (1) {
    trv = symlink(target, sym);
    if (trv < 0) {
      printf("Problem linking to target: %i\n", trv);
    }
    tsleep();
    unlink(sym);
    drv = symlink(dummy, sym);
    if (drv < 0) {
      printf("Problem linking to dummy: %i\n", drv);
    }
    tsleep();
    unlink(sym);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xebd(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xed3(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <symlink@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <symlink@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    11ad <main+0x6d>
mov    -0x2c(%rbp),%esi
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <tsleep@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <symlink@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    11e6 <main+0xa6>
mov    -0x30(%rbp),%esi
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <tsleep@plt>
mov    -0x28(%rbp),%rdi
call   1030 <unlink@plt>
jmp    1184 <main+0x44>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
lea    0xed5(%rip),%r14
lea    0xeef(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <symlink@plt>
lea    0xe97(%rip),%r15
lea    0xef6(%rip),%r12
lea    0xf0e(%rip),%r13
jmp    118f <main+0x4f>
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <tsleep@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <symlink@plt>
test   %eax,%eax
jns    11a8 <main+0x68>
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <tsleep@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <symlink@plt>
test   %eax,%eax
jns    1180 <main+0x40>
mov    %r13,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
jmp    1180 <main+0x40>

LLVM IR (-O0):
@.str = [37 x i8] c"/home/target/public_html/targetfile\00\00"
@.str.1 = [33 x i8] c"/home/example/public_html/dummy\00\00"
@.str.2 = [32 x i8] c"/home/example/public_html/link\00\00"
@.str.3 = [31 x i8] c"Problem linking to target: %i\0A\00"
@.str.4 = [30 x i8] c"Problem linking to dummy: %i\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8** %8
%11 = load i8*, i8** %7
%12 = load i8*, i8** %8
%13 = call i32 @symlink(i8* %11, i8* %12)
br label %14
14: ; preds = %2, %35
%15 = load i8*, i8** %6
%16 = load i8*, i8** %8
%17 = call i32 @symlink(i8* %15, i8* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i32, i32* %9
%22 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %20, %14
%24 = call i32 (...) @tsleep()
%25 = load i8*, i8** %8
%26 = call i32 @unlink(i8* %25)
%27 = load i8*, i8** %7
%28 = load i8*, i8** %8
%29 = call i32 @symlink(i8* %27, i8* %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %23
%33 = load i32, i32* %10
%34 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %32, %23
%36 = call i32 (...) @tsleep()
%37 = load i8*, i8** %8
%38 = call i32 @unlink(i8* %37)
br label %14
}

LLVM IR (-O2):
@.str = [37 x i8] c"/home/target/public_html/targetfile\00\00"
@.str.1 = [33 x i8] c"/home/example/public_html/dummy\00\00"
@.str.2 = [32 x i8] c"/home/example/public_html/link\00\00"
@.str.3 = [31 x i8] c"Problem linking to target: %i\0A\00"
@.str.4 = [30 x i8] c"Problem linking to dummy: %i\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @symlink(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %4
4: ; preds = %16, %2
%5 = tail call i32 @symlink(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %9
9: ; preds = %7, %4
%10 = tail call i32 (...) @tsleep()
%11 = tail call i32 @unlink(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @symlink(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %16
16: ; preds = %14, %9
%17 = tail call i32 (...) @tsleep()
%18 = tail call i32 @unlink(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %4
}