#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*/ AT_FDCWD;
int /*<<< orphan*/ AT_SYMLINK_NOFOLLOW;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fchownat(int /*<<< orphan*/, char *, int /*<<< orphan*/, int /*<<< orphan*/,
             int /*<<< orphan*/);
int /*<<< orphan*/ getgid();
int /*<<< orphan*/ getuid();
int symlink(char *, char *);
char *tmpnam(int /*<<< orphan*/ *);
int main() {
  int status;
  char *path;
  path = tmpnam(NULL);
  status = symlink(path, path);
  if (status < 0)
    exit(EXIT_FAILURE);
  status = fchownat(AT_FDCWD, path, getuid(), getgid(), 0);
  if (status >= 0)
    exit(EXIT_FAILURE);
  status = fchownat(AT_FDCWD, path, getuid(), getgid(), AT_SYMLINK_NOFOLLOW);
  if (status < 0)
    exit(EXIT_FAILURE);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1080 <tmpnam@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <symlink@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11a4 <main+0x44>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getgid@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <fchownat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jl     11f8 <main+0x98>
mov    0x2def(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getuid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <getgid@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
mov    0x2da8(%rip),%rax
mov    (%rax),%r8d
call   1060 <fchownat@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1253 <main+0xf3>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %edi,%edi
call   1080 <tmpnam@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %rax,%rsi
call   1040 <symlink@plt>
test   %eax,%eax
js     11e0 <main+0x80>
mov    0x2e39(%rip),%r15
mov    (%r15),%r14d
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getgid@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
call   1060 <fchownat@plt>
test   %eax,%eax
jns    11e0 <main+0x80>
mov    (%r15),%r14d
xor    %eax,%eax
call   1030 <getuid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getgid@plt>
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%r8d
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %eax,%ecx
call   1060 <fchownat@plt>
test   %eax,%eax
jns    11ee <main+0x8e>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@EXIT_FAILURE = global i32 0
@AT_FDCWD = global i32 0
@AT_SYMLINK_NOFOLLOW = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
store i32 0, i32* %1
%4 = call i8* @tmpnam(i32* null)
store i8* %4, i8** %3
%5 = load i8*, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @symlink(i8* %5, i8* %6)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = load i32, i32* @AT_FDCWD
%15 = load i8*, i8** %3
%16 = call i32 (...) @getuid()
%17 = call i32 (...) @getgid()
%18 = call i32 @fchownat(i32 %14, i8* %15, i32 %16, i32 %17, i32 0)
store i32 %18, i32* %2
%19 = load i32, i32* %2
%20 = icmp sge i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %13
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %13
%25 = load i32, i32* @AT_FDCWD
%26 = load i8*, i8** %3
%27 = call i32 (...) @getuid()
%28 = call i32 (...) @getgid()
%29 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%30 = call i32 @fchownat(i32 %25, i8* %26, i32 %27, i32 %28, i32 %29)
store i32 %30, i32* %2
%31 = load i32, i32* %2
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %24
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@AT_FDCWD = global i32 0
@AT_SYMLINK_NOFOLLOW = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = tail call i8* @tmpnam(i32* null)
%2 = tail call i32 @symlink(i8* %1, i8* %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = load i32, i32* @AT_FDCWD
%9 = tail call i32 (...) @getuid()
%10 = tail call i32 (...) @getgid()
%11 = tail call i32 @fchownat(i32 %8, i8* %1, i32 %9, i32 %10, i32 0)
%12 = icmp sgt i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = load i32, i32* @AT_FDCWD
%18 = tail call i32 (...) @getuid()
%19 = tail call i32 (...) @getgid()
%20 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%21 = tail call i32 @fchownat(i32 %17, i8* %1, i32 %18, i32 %19, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* @EXIT_FAILURE
%25 = tail call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
}