#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 /*<<< orphan*/ st_mode;
};
struct passwd {
  char *pw_name;
  char *pw_dir;
};
typedef int /*<<< orphan*/ kde_tmp_dir;

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISLNK(int /*<<< orphan*/);
int check_tmp_dir(char *);
int create_link(char *, char *);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *getenv(char *);
scalar_t__ gethostname(char *, int);
struct passwd *getpwuid(int);
int getuid();
int lstat(char *, struct stat *);
int mkdir(char *, int);
int /*<<< orphan*/ mktemp(char *);
int /*<<< orphan*/ perror(char *);
int readlink(char *, char *, int);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int strlen(char const *);
int /*<<< orphan*/ strncat(char *, char const *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
int /*<<< orphan*/ unlink(char *);
int build_link(const char *tmp_prefix, const char *kde_prefix,
               int kdehostname) {
  struct passwd *pw_ent;
  char kde_tmp_dir[4096 + 1];
  char user_tmp_dir[4096 + 1];
  char tmp_buf[4096 + 1];
  int uid = getuid();
  const char *home_dir = getenv("HOME");
  const char *kde_home = uid ? getenv("TDEHOME") : getenv("TDEROOTHOME");
  int result;
  struct stat stat_buf;
  kde_tmp_dir[0] = 0;
  pw_ent = getpwuid(uid);
  if (!pw_ent) {
    fprintf(stderr,
            "[lnusertemp] Error: Can not find password entry for uid %d.\n",
            getuid());
    return 1;
  }
  strncpy(user_tmp_dir, tmp_prefix, 4096);
  user_tmp_dir[4096] = '\0';
  strncat(user_tmp_dir, pw_ent->pw_name, 4096 - strlen(tmp_prefix));
  if (!kde_home || !kde_home[0]) {
    kde_home = "~/.trinity/";
  }
  if (kde_home[0] == '~') {
    if (uid == 0) {
      home_dir = pw_ent->pw_dir ? pw_ent->pw_dir : "/root";
    }
    if (!home_dir || !home_dir[0]) {
      fprintf(stderr, "[lnusertemp] Aborting. $HOME not set!\n");
      return 1;
    }
    if (strlen(home_dir) > (4096 - 100)) {
      fprintf(stderr, "[lnusertemp] Aborting. Home directory path too long!\n");
      return 1;
    }
    kde_home++;
    strncpy(kde_tmp_dir, home_dir, 4096);
    kde_tmp_dir[4096] = '\0';
  }
  strncat(kde_tmp_dir, kde_home, 4096 - strlen(kde_tmp_dir));
  if (kde_tmp_dir[strlen(kde_tmp_dir) - 1] == '/')
    kde_tmp_dir[strlen(kde_tmp_dir) - 1] = 0;
  result = stat(kde_tmp_dir, &stat_buf);
  if ((result == -1) && (errno == ENOENT)) {
    result = mkdir(kde_tmp_dir, 0700);
  }
  if (result == -1) {
    perror("[lnusertemp] mkdir failed: ");
    return 1;
  }
  strncat(kde_tmp_dir, kde_prefix, 4096 - strlen(kde_tmp_dir));
  if (kdehostname) {
    if (getenv("XAUTHLOCALHOSTNAME"))
      strncat(kde_tmp_dir + strlen(kde_tmp_dir), getenv("XAUTHLOCALHOSTNAME"),
              4096 - strlen(kde_tmp_dir) - 1);
    else
      return 0;
  } else {
    if (gethostname(kde_tmp_dir + strlen(kde_tmp_dir),
                    4096 - strlen(kde_tmp_dir) - 1) != 0) {
      perror("[lnusertemp] Could not determine hostname: ");
      return 1;
    }
  }
  kde_tmp_dir[sizeof(kde_tmp_dir) - 1] = '\0';
  result = lstat(kde_tmp_dir, &stat_buf);
  if ((result == 0) && (S_ISDIR(stat_buf.st_mode))) {
    return 0;
  }
  if ((result == -1) && (errno == ENOENT)) {
    result = create_link(kde_tmp_dir, user_tmp_dir);
    if (result == 0)
      return 0;
    unlink(kde_tmp_dir);
    strncat(user_tmp_dir, "XXXXXX", 4096 - strlen(user_tmp_dir));
    mktemp(user_tmp_dir);
    return create_link(kde_tmp_dir, user_tmp_dir);
  }
  if ((result == -1) || (!S_ISLNK(stat_buf.st_mode))) {
    fprintf(stderr,
            "[lnusertemp] Error: \"%s\" is not a link or a directory.\n",
            kde_tmp_dir);
    return 1;
  }
  result = readlink(kde_tmp_dir, tmp_buf, 4096);
  if (result == -1) {
    fprintf(stderr, "[lnusertemp] Error: \"%s\" could not be read.\n",
            kde_tmp_dir);
    return 1;
  }
  tmp_buf[result] = '\0';
  if (strncmp(tmp_buf, user_tmp_dir, strlen(user_tmp_dir)) != 0) {
    fprintf(stderr,
            "[lnusertemp] Error: \"%s\" points to \"%s\" instead of \"%s\".\n",
            kde_tmp_dir, tmp_buf, user_tmp_dir);
    unlink(kde_tmp_dir);
    result = create_link(kde_tmp_dir, user_tmp_dir);
    if (result == 0)
      return 0;
    unlink(kde_tmp_dir);
    strncat(user_tmp_dir, "XXXXXX", 4096 - strlen(user_tmp_dir));
    mktemp(user_tmp_dir);
    return create_link(kde_tmp_dir, user_tmp_dir);
  }
  result = check_tmp_dir(tmp_buf);
  if (result == 0)
    return 0;
  unlink(kde_tmp_dir);
  strncat(user_tmp_dir, "XXXXXX", 4096 - strlen(user_tmp_dir));
  mktemp(user_tmp_dir);
  return create_link(kde_tmp_dir, user_tmp_dir);
}


x86 assembly (clang, -O0):
<build_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3110,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   10c0 <getuid@plt>
mov    %eax,-0x3054(%rbp)
lea    0xd99(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x3060(%rbp)
cmpl   $0x0,-0x3054(%rbp)
je     129b <build_link+0x5b>
lea    0xd76(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x3078(%rbp)
jmp    12ae <build_link+0x6e>
lea    0xd66(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x3078(%rbp)
mov    -0x3078(%rbp),%rax
mov    %rax,-0x3068(%rbp)
movb   $0x0,-0x1030(%rbp)
mov    -0x3054(%rbp),%edi
call   10a0 <getpwuid@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1315 <build_link+0xd5>
mov    0x2cfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x307c(%rbp)
mov    $0x0,%al
call   10c0 <getuid@plt>
mov    -0x307c(%rbp),%edi
mov    %eax,%edx
lea    0xd12(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x2040(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <strncpy@plt>
movb   $0x0,-0x1040(%rbp)
lea    -0x2040(%rbp),%rax
mov    %rax,-0x3090(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x3088(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x3090(%rbp),%rdi
mov    -0x3088(%rbp),%rsi
mov    $0x1000,%edx
sub    %eax,%edx
call   10e0 <strncat@plt>
cmpq   $0x0,-0x3068(%rbp)
je     138e <build_link+0x14e>
mov    -0x3068(%rbp),%rax
cmpb   $0x0,(%rax)
jne    139c <build_link+0x15c>
lea    0xcbc(%rip),%rax
mov    %rax,-0x3068(%rbp)
mov    -0x3068(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    14a9 <build_link+0x269>
cmpl   $0x0,-0x3054(%rbp)
jne    1400 <build_link+0x1c0>
mov    -0x28(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     13df <build_link+0x19f>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x3098(%rbp)
jmp    13f2 <build_link+0x1b2>
lea    0xc77(%rip),%rax
mov    %rax,-0x3098(%rbp)
jmp    13f2 <build_link+0x1b2>
mov    -0x3098(%rbp),%rax
mov    %rax,-0x3060(%rbp)
cmpq   $0x0,-0x3060(%rbp)
je     141e <build_link+0x1de>
mov    -0x3060(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1441 <build_link+0x201>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
lea    0xc35(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
mov    -0x3060(%rbp),%rdi
call   10b0 <strlen@plt>
cmp    $0xf9c,%eax
jle    147b <build_link+0x23b>
mov    0x2b81(%rip),%rax
mov    (%rax),%edi
lea    0xc22(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
mov    -0x3068(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x3068(%rbp)
lea    -0x1030(%rbp),%rdi
mov    -0x3060(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <strncpy@plt>
movb   $0x0,-0x30(%rbp)
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30a8(%rbp)
mov    -0x3068(%rbp),%rax
mov    %rax,-0x30a0(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30a8(%rbp),%rdi
mov    -0x30a0(%rbp),%rsi
mov    $0x1000,%edx
sub    %eax,%edx
call   10e0 <strncat@plt>
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x1030(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1526 <build_link+0x2e6>
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x1030(%rbp,%rax,1)
lea    -0x1030(%rbp),%rdi
lea    -0x3070(%rbp),%rsi
call   1110 <stat@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0xffffffff,-0x306c(%rbp)
jne    157d <build_link+0x33d>
mov    0x2a85(%rip),%rax
mov    (%rax),%rax
mov    0x2a6b(%rip),%rcx
cmp    (%rcx),%rax
jne    157d <build_link+0x33d>
lea    -0x1030(%rbp),%rdi
mov    $0x1c0,%esi
call   1080 <mkdir@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0xffffffff,-0x306c(%rbp)
jne    15a2 <build_link+0x362>
lea    0xb2f(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30b8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30b0(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30b8(%rbp),%rdi
mov    -0x30b0(%rbp),%rsi
mov    $0x1000,%edx
sub    %eax,%edx
call   10e0 <strncat@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1683 <build_link+0x443>
lea    0xaea(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     1672 <build_link+0x432>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30d0(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    %eax,%ecx
mov    -0x30d0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30c8(%rbp)
lea    0xaa4(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30c0(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30c8(%rbp),%rdi
mov    -0x30c0(%rbp),%rsi
mov    $0x1000,%edx
sub    %eax,%edx
sub    $0x1,%edx
call   10e0 <strncat@plt>
jmp    167e <build_link+0x43e>
movl   $0x0,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
jmp    16fc <build_link+0x4bc>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30e0(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    %eax,%ecx
mov    -0x30e0(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30d8(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30d8(%rbp),%rdi
mov    $0x1000,%esi
sub    %eax,%esi
sub    $0x1,%esi
call   1150 <gethostname@plt>
cmp    $0x0,%rax
je     16f7 <build_link+0x4b7>
lea    0xa09(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
jmp    16fc <build_link+0x4bc>
movb   $0x0,-0x30(%rbp)
lea    -0x1030(%rbp),%rdi
lea    -0x3070(%rbp),%rsi
call   10f0 <lstat@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0x0,-0x306c(%rbp)
jne    1747 <build_link+0x507>
mov    -0x3070(%rbp),%edi
call   10d0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1747 <build_link+0x507>
movl   $0x0,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
cmpl   $0xffffffff,-0x306c(%rbp)
jne    1807 <build_link+0x5c7>
mov    0x287d(%rip),%rax
mov    (%rax),%rax
mov    0x2863(%rip),%rcx
cmp    (%rcx),%rax
jne    1807 <build_link+0x5c7>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0x0,-0x306c(%rbp)
jne    17a0 <build_link+0x560>
movl   $0x0,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x1030(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x30e8(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30e8(%rbp),%rdi
mov    $0x1000,%edx
sub    %eax,%edx
lea    0x940(%rip),%rsi
call   10e0 <strncat@plt>
lea    -0x2040(%rbp),%rdi
call   1160 <mktemp@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
cmpl   $0xffffffff,-0x306c(%rbp)
je     1828 <build_link+0x5e8>
mov    -0x3070(%rbp),%edi
call   1070 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    1852 <build_link+0x612>
mov    0x27b1(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    0x8e3(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x1030(%rbp),%rdi
lea    -0x3050(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <readlink@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0xffffffff,-0x306c(%rbp)
jne    18a7 <build_link+0x667>
mov    0x275c(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    0x8c6(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
movslq -0x306c(%rbp),%rax
movb   $0x0,-0x3050(%rbp,%rax,1)
lea    -0x3050(%rbp),%rax
mov    %rax,-0x30f8(%rbp)
lea    -0x2040(%rbp),%rax
mov    %rax,-0x30f0(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30f8(%rbp),%rdi
mov    -0x30f0(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
je     19ce <build_link+0x78e>
mov    0x26dc(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    -0x3050(%rbp),%rcx
lea    -0x2040(%rbp),%r8
lea    0x865(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
lea    -0x1030(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0x0,-0x306c(%rbp)
jne    1967 <build_link+0x727>
movl   $0x0,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x1030(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x3100(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x3100(%rbp),%rdi
mov    $0x1000,%edx
sub    %eax,%edx
lea    0x779(%rip),%rsi
call   10e0 <strncat@plt>
lea    -0x2040(%rbp),%rdi
call   1160 <mktemp@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x3050(%rbp),%rdi
call   1140 <check_tmp_dir@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0x0,-0x306c(%rbp)
jne    19f9 <build_link+0x7b9>
movl   $0x0,-0x4(%rbp)
jmp    1a5b <build_link+0x81b>
lea    -0x1030(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x3108(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x3108(%rbp),%rdi
mov    $0x1000,%edx
sub    %eax,%edx
lea    0x6e7(%rip),%rsi
call   10e0 <strncat@plt>
lea    -0x2040(%rbp),%rdi
call   1160 <mktemp@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_link>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3048,%rsp
mov    %edx,0xc(%rsp)
mov    %rsi,0x18(%rsp)
mov    %rdi,%r14
xor    %eax,%eax
call   10c0 <getuid@plt>
mov    %eax,%ebx
lea    0xd96(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
test   %ebx,%ebx
lea    0xd8a(%rip),%rax
lea    0xd7b(%rip),%rdi
cmove  %rax,%rdi
call   1030 <getenv@plt>
mov    %rax,%r13
movb   $0x0,0x20(%rsp)
mov    %ebx,%edi
call   10a0 <getpwuid@plt>
test   %rax,%rax
je     134b <build_link+0x10b>
mov    %rax,%rbp
mov    %r15,0x10(%rsp)
lea    0x1030(%rsp),%rdi
mov    $0x1000,%r12d
mov    %r14,%rsi
mov    $0x1000,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x2030(%rsp)
mov    0x0(%rbp),%r15
mov    %r14,%rdi
call   10b0 <strlen@plt>
sub    %eax,%r12d
lea    0x1030(%rsp),%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   10e0 <strncat@plt>
lea    0xd57(%rip),%r14
test   %r13,%r13
je     136f <build_link+0x12f>
mov    0x0(%r13),%al
test   %al,%al
mov    0x10(%rsp),%r15
je     1317 <build_link+0xd7>
cmp    $0x7e,%al
jne    13e1 <build_link+0x1a1>
mov    %r13,%r14
test   %ebx,%ebx
je     1378 <build_link+0x138>
test   %r15,%r15
je     1390 <build_link+0x150>
cmpb   $0x0,(%r15)
je     1390 <build_link+0x150>
mov    %r15,%rdi
call   10b0 <strlen@plt>
cmp    $0xf9d,%eax
jl     13c0 <build_link+0x180>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
jmp    13a0 <build_link+0x160>
mov    0x2c8e(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10c0 <getuid@plt>
lea    0xcb2(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1100 <fprintf@plt>
jmp    13a7 <build_link+0x167>
mov    0x10(%rsp),%r15
test   %ebx,%ebx
jne    131b <build_link+0xdb>
mov    0x8(%rbp),%rax
test   %rax,%rax
lea    0xcd7(%rip),%r15
cmovne %rax,%r15
cmpb   $0x0,(%r15)
jne    1326 <build_link+0xe6>
mov    0x2c49(%rip),%rax
mov    (%rax),%edi
lea    0xcc3(%rip),%rsi
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x3048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%r14
lea    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x1020(%rsp)
mov    %r14,%r13
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    $0x1000,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r13,%rsi
call   10e0 <strncat@plt>
mov    %rbx,%rdi
call   10b0 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
jne    1420 <build_link+0x1e0>
mov    %rbx,%rdi
call   10b0 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1110 <stat@plt>
cmp    $0xffffffff,%eax
jne    1466 <build_link+0x226>
mov    0x2b9d(%rip),%rax
mov    (%rax),%rax
mov    0x2b83(%rip),%rcx
cmp    (%rcx),%rax
jne    16dd <build_link+0x49d>
lea    0x20(%rsp),%rdi
mov    $0x1c0,%esi
call   1080 <mkdir@plt>
cmp    $0xffffffff,%eax
je     16dd <build_link+0x49d>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    $0x1000,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    0x18(%rsp),%rsi
call   10e0 <strncat@plt>
cmpl   $0x0,0xc(%rsp)
je     14e5 <build_link+0x2a5>
lea    0xc47(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     16d6 <build_link+0x496>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   10b0 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
add    $0x20,%rbp
lea    0xc1b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   10b0 <strlen@plt>
mov    $0xfff,%edx
sub    %eax,%edx
mov    %rbp,%rdi
mov    %rbx,%rsi
call   10e0 <strncat@plt>
jmp    151c <build_link+0x2dc>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rbp
add    $0x20,%rbp
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    $0xfff,%esi
sub    %eax,%esi
mov    %rbp,%rdi
call   1150 <gethostname@plt>
test   %rax,%rax
jne    16e6 <build_link+0x4a6>
movb   $0x0,0x1020(%rsp)
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10f0 <lstat@plt>
cmp    $0xffffffff,%eax
je     1554 <build_link+0x314>
test   %eax,%eax
jne    158d <build_link+0x34d>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   10d0 <S_ISDIR@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    13ac <build_link+0x16c>
jmp    1591 <build_link+0x351>
mov    0x2a7d(%rip),%rax
mov    (%rax),%rax
mov    0x2a63(%rip),%rcx
cmp    (%rcx),%rax
jne    1645 <build_link+0x405>
lea    0x20(%rsp),%rdi
lea    0x1030(%rsp),%rsi
call   1120 <create_link@plt>
test   %eax,%eax
jne    1689 <build_link+0x449>
jmp    16d6 <build_link+0x496>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1070 <S_ISLNK@plt>
test   %eax,%eax
je     1645 <build_link+0x405>
lea    0x20(%rsp),%rdi
lea    0x2040(%rsp),%rsi
mov    $0x1000,%edx
call   1090 <readlink@plt>
cmp    $0xffffffff,%eax
je     1657 <build_link+0x417>
cltq
movb   $0x0,0x2040(%rsp,%rax,1)
lea    0x1030(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
lea    0x2040(%rsp),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
je     1678 <build_link+0x438>
mov    0x29e4(%rip),%rax
mov    (%rax),%edi
lea    0xb82(%rip),%rsi
xor    %ebx,%ebx
lea    0x20(%rsp),%rbp
lea    0x2040(%rsp),%rcx
lea    0x1030(%rsp),%r14
mov    %rbp,%rdx
mov    %r14,%r8
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    %rbp,%rdi
call   1040 <unlink@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   1120 <create_link@plt>
test   %eax,%eax
jne    1689 <build_link+0x449>
jmp    13ac <build_link+0x16c>
mov    0x2994(%rip),%rax
mov    (%rax),%edi
lea    0xacd(%rip),%rsi
jmp    1667 <build_link+0x427>
mov    0x2982(%rip),%rax
mov    (%rax),%edi
lea    0xaf3(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   1100 <fprintf@plt>
jmp    13a7 <build_link+0x167>
lea    0x2040(%rsp),%rdi
call   1140 <check_tmp_dir@plt>
test   %eax,%eax
je     16d6 <build_link+0x496>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <unlink@plt>
lea    0x1030(%rsp),%rbp
mov    %rbp,%rdi
call   10b0 <strlen@plt>
mov    $0x1000,%edx
sub    %eax,%edx
lea    0xa67(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strncat@plt>
mov    %rbp,%rdi
call   1160 <mktemp@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1120 <create_link@plt>
mov    %eax,%ebx
jmp    13ac <build_link+0x16c>
xor    %ebx,%ebx
jmp    13ac <build_link+0x16c>
lea    0x9dc(%rip),%rdi
jmp    16ed <build_link+0x4ad>
lea    0xa02(%rip),%rdi
call   1130 <perror@plt>
jmp    13a7 <build_link+0x167>

LLVM IR (-O0):
%struct.passwd = type { i8*, i8* }
%struct.stat = type { i32 }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [8 x i8] c"TDEHOME\00"
@.str.2 = [12 x i8] c"TDEROOTHOME\00"
@stderr = global i32 0
@.str.3 = [61 x i8] c"[lnusertemp] Error: Can not find password entry for uid %d.\0A\00"
@.str.4 = [12 x i8] c"~/.trinity/\00"
@.str.5 = [6 x i8] c"/root\00"
@.str.6 = [39 x i8] c"[lnusertemp] Aborting. $HOME not set!\0A\00"
@.str.7 = [54 x i8] c"[lnusertemp] Aborting. Home directory path too long!\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.8 = [28 x i8] c"[lnusertemp] mkdir failed: \00"
@.str.9 = [19 x i8] c"XAUTHLOCALHOSTNAME\00"
@.str.10 = [44 x i8] c"[lnusertemp] Could not determine hostname: \00"
@.str.11 = [7 x i8] c"XXXXXX\00"
@.str.12 = [56 x i8] c"[lnusertemp] Error: \22%s\22 is not a link or a directory.\0A\00"
@.str.13 = [45 x i8] c"[lnusertemp] Error: \22%s\22 could not be read.\0A\00"
@.str.14 = [58 x i8] c"[lnusertemp] Error: \22%s\22 points to \22%s\22 instead of \22%s\22.\0A\00"
define i32 @build_link(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.passwd*
%9 = alloca [4097 x i8]
%10 = alloca [4097 x i8]
%11 = alloca [4097 x i8]
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca %struct.stat
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%17 = call i32 (...) @getuid()
store i32 %17, i32* %12
%18 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %18, i8** %13
%19 = load i32, i32* %12
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %25
23: ; preds = %3
%24 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %21
%26 = phi i8* [ %22, %21 ], [ %24, %23 ]
store i8* %26, i8** %14
%27 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
store i8 0, i8* %27
%28 = load i32, i32* %12
%29 = call %struct.passwd* @getpwuid(i32 %28)
store %struct.passwd* %29, %struct.passwd** %8
%30 = load %struct.passwd*, %struct.passwd** %8
%31 = icmp ne %struct.passwd* %30, null
br i1 %31, label %36, label %32
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i32 (...) @getuid()
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i32 %34)
store i32 1, i32* %4
br label %299
36: ; preds = %25
%37 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%38 = load i8*, i8** %5
%39 = call i32 @strncpy(i8* %37, i8* %38, i32 4096)
%40 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 4096
store i8 0, i8* %40
%41 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%42 = load %struct.passwd*, %struct.passwd** %8
%43 = getelementptr inbounds %struct.passwd, %struct.passwd* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = load i8*, i8** %5
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 4096, %46
%48 = call i32 @strncat(i8* %41, i8* %44, i32 %47)
%49 = load i8*, i8** %14
%50 = icmp ne i8* %49, null
br i1 %50, label %51, label %56
51: ; preds = %36
%52 = load i8*, i8** %14
%53 = getelementptr inbounds i8, i8* %52, i64 0
%54 = load i8, i8* %53
%55 = icmp ne i8 %54, 0
br i1 %55, label %57, label %56
56: ; preds = %51, %36
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8** %14
br label %57
57: ; preds = %56, %51
%58 = load i8*, i8** %14
%59 = getelementptr inbounds i8, i8* %58, i64 0
%60 = load i8, i8* %59
%61 = sext i8 %60 to i32
%62 = icmp eq i32 %61, 126
br i1 %62, label %63, label %103
63: ; preds = %57
%64 = load i32, i32* %12
%65 = icmp eq i32 %64, 0
br i1 %65, label %66, label %78
66: ; preds = %63
%67 = load %struct.passwd*, %struct.passwd** %8
%68 = getelementptr inbounds %struct.passwd, %struct.passwd* %67, i32 0, i32 1
%69 = load i8*, i8** %68
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %75
71: ; preds = %66
%72 = load %struct.passwd*, %struct.passwd** %8
%73 = getelementptr inbounds %struct.passwd, %struct.passwd* %72, i32 0, i32 1
%74 = load i8*, i8** %73
br label %76
75: ; preds = %66
br label %76
76: ; preds = %75, %71
%77 = phi i8* [ %74, %71 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %75 ]
store i8* %77, i8** %13
br label %78
78: ; preds = %76, %63
%79 = load i8*, i8** %13
%80 = icmp ne i8* %79, null
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load i8*, i8** %13
%83 = getelementptr inbounds i8, i8* %82, i64 0
%84 = load i8, i8* %83
%85 = icmp ne i8 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %81, %78
%87 = load i32, i32* @stderr
%88 = call i32 (i32, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %4
br label %299
89: ; preds = %81
%90 = load i8*, i8** %13
%91 = call i32 @strlen(i8* %90)
%92 = icmp sgt i32 %91, 3996
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = load i32, i32* @stderr
%95 = call i32 (i32, i8*, ...) @fprintf(i32 %94, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %4
br label %299
96: ; preds = %89
%97 = load i8*, i8** %14
%98 = getelementptr inbounds i8, i8* %97, i32 1
store i8* %98, i8** %14
%99 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%100 = load i8*, i8** %13
%101 = call i32 @strncpy(i8* %99, i8* %100, i32 4096)
%102 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 4096
store i8 0, i8* %102
br label %103
103: ; preds = %96, %57
%104 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%105 = load i8*, i8** %14
%106 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%107 = call i32 @strlen(i8* %106)
%108 = sub nsw i32 4096, %107
%109 = call i32 @strncat(i8* %104, i8* %105, i32 %108)
%110 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%111 = call i32 @strlen(i8* %110)
%112 = sub nsw i32 %111, 1
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 %113
%115 = load i8, i8* %114
%116 = sext i8 %115 to i32
%117 = icmp eq i32 %116, 47
br i1 %117, label %118, label %124
118: ; preds = %103
%119 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%120 = call i32 @strlen(i8* %119)
%121 = sub nsw i32 %120, 1
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 %122
store i8 0, i8* %123
br label %124
124: ; preds = %118, %103
%125 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%126 = call i32 @stat(i8* %125, %struct.stat* %16)
store i32 %126, i32* %15
%127 = load i32, i32* %15
%128 = icmp eq i32 %127, -1
br i1 %128, label %129, label %136
129: ; preds = %124
%130 = load i64, i64* @errno
%131 = load i64, i64* @ENOENT
%132 = icmp eq i64 %130, %131
br i1 %132, label %133, label %136
133: ; preds = %129
%134 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%135 = call i32 @mkdir(i8* %134, i32 448)
store i32 %135, i32* %15
br label %136
136: ; preds = %133, %129, %124
%137 = load i32, i32* %15
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %141
139: ; preds = %136
%140 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %4
br label %299
141: ; preds = %136
%142 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%143 = load i8*, i8** %6
%144 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%145 = call i32 @strlen(i8* %144)
%146 = sub nsw i32 4096, %145
%147 = call i32 @strncat(i8* %142, i8* %143, i32 %146)
%148 = load i32, i32* %7
%149 = icmp ne i32 %148, 0
br i1 %149, label %150, label %167
150: ; preds = %141
%151 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%152 = icmp ne i8* %151, null
br i1 %152, label %153, label %165
153: ; preds = %150
%154 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%155 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%156 = call i32 @strlen(i8* %155)
%157 = sext i32 %156 to i64
%158 = getelementptr inbounds i8, i8* %154, i64 %157
%159 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%160 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%161 = call i32 @strlen(i8* %160)
%162 = sub nsw i32 4096, %161
%163 = sub nsw i32 %162, 1
%164 = call i32 @strncat(i8* %158, i8* %159, i32 %163)
br label %166
165: ; preds = %150
store i32 0, i32* %4
br label %299
166: ; preds = %153
br label %182
167: ; preds = %141
%168 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%169 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%170 = call i32 @strlen(i8* %169)
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds i8, i8* %168, i64 %171
%173 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%174 = call i32 @strlen(i8* %173)
%175 = sub nsw i32 4096, %174
%176 = sub nsw i32 %175, 1
%177 = call i64 @gethostname(i8* %172, i32 %176)
%178 = icmp ne i64 %177, 0
br i1 %178, label %179, label %181
179: ; preds = %167
%180 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %4
br label %299
181: ; preds = %167
br label %182
182: ; preds = %181, %166
%183 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 4096
store i8 0, i8* %183
%184 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%185 = call i32 @lstat(i8* %184, %struct.stat* %16)
store i32 %185, i32* %15
%186 = load i32, i32* %15
%187 = icmp eq i32 %186, 0
br i1 %187, label %188, label %194
188: ; preds = %182
%189 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%190 = load i32, i32* %189
%191 = call i64 @S_ISDIR(i32 %190)
%192 = icmp ne i64 %191, 0
br i1 %192, label %193, label %194
193: ; preds = %188
store i32 0, i32* %4
br label %299
194: ; preds = %188, %182
%195 = load i32, i32* %15
%196 = icmp eq i32 %195, -1
br i1 %196, label %197, label %221
197: ; preds = %194
%198 = load i64, i64* @errno
%199 = load i64, i64* @ENOENT
%200 = icmp eq i64 %198, %199
br i1 %200, label %201, label %221
201: ; preds = %197
%202 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%203 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%204 = call i32 @create_link(i8* %202, i8* %203)
store i32 %204, i32* %15
%205 = load i32, i32* %15
%206 = icmp eq i32 %205, 0
br i1 %206, label %207, label %208
207: ; preds = %201
store i32 0, i32* %4
br label %299
208: ; preds = %201
%209 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%210 = call i32 @unlink(i8* %209)
%211 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%212 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%213 = call i32 @strlen(i8* %212)
%214 = sub nsw i32 4096, %213
%215 = call i32 @strncat(i8* %211, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %214)
%216 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%217 = call i32 @mktemp(i8* %216)
%218 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%219 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%220 = call i32 @create_link(i8* %218, i8* %219)
store i32 %220, i32* %4
br label %299
221: ; preds = %197, %194
%222 = load i32, i32* %15
%223 = icmp eq i32 %222, -1
br i1 %223, label %229, label %224
224: ; preds = %221
%225 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%226 = load i32, i32* %225
%227 = call i32 @S_ISLNK(i32 %226)
%228 = icmp ne i32 %227, 0
br i1 %228, label %233, label %229
229: ; preds = %224, %221
%230 = load i32, i32* @stderr
%231 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%232 = call i32 (i32, i8*, ...) @fprintf(i32 %230, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.12, i64 0, i64 0), i8* %231)
store i32 1, i32* %4
br label %299
233: ; preds = %224
%234 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%235 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%236 = call i32 @readlink(i8* %234, i8* %235, i32 4096)
store i32 %236, i32* %15
%237 = load i32, i32* %15
%238 = icmp eq i32 %237, -1
br i1 %238, label %239, label %243
239: ; preds = %233
%240 = load i32, i32* @stderr
%241 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%242 = call i32 (i32, i8*, ...) @fprintf(i32 %240, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0), i8* %241)
store i32 1, i32* %4
br label %299
243: ; preds = %233
%244 = load i32, i32* %15
%245 = sext i32 %244 to i64
%246 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 %245
store i8 0, i8* %246
%247 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%248 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%249 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%250 = call i32 @strlen(i8* %249)
%251 = call i64 @strncmp(i8* %247, i8* %248, i32 %250)
%252 = icmp ne i64 %251, 0
br i1 %252, label %253, label %280
253: ; preds = %243
%254 = load i32, i32* @stderr
%255 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%256 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%257 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%258 = call i32 (i32, i8*, ...) @fprintf(i32 %254, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.14, i64 0, i64 0), i8* %255, i8* %256, i8* %257)
%259 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%260 = call i32 @unlink(i8* %259)
%261 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%262 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%263 = call i32 @create_link(i8* %261, i8* %262)
store i32 %263, i32* %15
%264 = load i32, i32* %15
%265 = icmp eq i32 %264, 0
br i1 %265, label %266, label %267
266: ; preds = %253
store i32 0, i32* %4
br label %299
267: ; preds = %253
%268 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%269 = call i32 @unlink(i8* %268)
%270 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%271 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%272 = call i32 @strlen(i8* %271)
%273 = sub nsw i32 4096, %272
%274 = call i32 @strncat(i8* %270, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %273)
%275 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%276 = call i32 @mktemp(i8* %275)
%277 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%278 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%279 = call i32 @create_link(i8* %277, i8* %278)
store i32 %279, i32* %4
br label %299
280: ; preds = %243
%281 = getelementptr inbounds [4097 x i8], [4097 x i8]* %11, i64 0, i64 0
%282 = call i32 @check_tmp_dir(i8* %281)
store i32 %282, i32* %15
%283 = load i32, i32* %15
%284 = icmp eq i32 %283, 0
br i1 %284, label %285, label %286
285: ; preds = %280
store i32 0, i32* %4
br label %299
286: ; preds = %280
%287 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%288 = call i32 @unlink(i8* %287)
%289 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%290 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%291 = call i32 @strlen(i8* %290)
%292 = sub nsw i32 4096, %291
%293 = call i32 @strncat(i8* %289, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %292)
%294 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%295 = call i32 @mktemp(i8* %294)
%296 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%297 = getelementptr inbounds [4097 x i8], [4097 x i8]* %10, i64 0, i64 0
%298 = call i32 @create_link(i8* %296, i8* %297)
store i32 %298, i32* %4
br label %299
299: ; preds = %286, %285, %267, %266, %239, %229, %208, %207, %193, %179, %165, %139, %93, %86, %32
%300 = load i32, i32* %4
ret i32 %300
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.passwd = type { i8*, i8* }
@.str = [5 x i8] c"HOME\00"
@.str.1 = [8 x i8] c"TDEHOME\00"
@.str.2 = [12 x i8] c"TDEROOTHOME\00"
@stderr = global i32 0
@.str.3 = [61 x i8] c"[lnusertemp] Error: Can not find password entry for uid %d.\0A\00"
@.str.4 = [12 x i8] c"~/.trinity/\00"
@.str.5 = [6 x i8] c"/root\00"
@.str.6 = [39 x i8] c"[lnusertemp] Aborting. $HOME not set!\0A\00"
@.str.7 = [54 x i8] c"[lnusertemp] Aborting. Home directory path too long!\0A\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.8 = [28 x i8] c"[lnusertemp] mkdir failed: \00"
@.str.9 = [19 x i8] c"XAUTHLOCALHOSTNAME\00"
@.str.10 = [44 x i8] c"[lnusertemp] Could not determine hostname: \00"
@.str.11 = [7 x i8] c"XXXXXX\00"
@.str.12 = [56 x i8] c"[lnusertemp] Error: \22%s\22 is not a link or a directory.\0A\00"
@.str.13 = [45 x i8] c"[lnusertemp] Error: \22%s\22 could not be read.\0A\00"
@.str.14 = [58 x i8] c"[lnusertemp] Error: \22%s\22 points to \22%s\22 instead of \22%s\22.\0A\00"
define i32 @build_link(i8* %0, i8* %1, i32 %2) {
%4 = alloca [4097 x i8]
%5 = alloca [4097 x i8]
%6 = alloca [4097 x i8]
%7 = alloca %struct.stat
%8 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 0
%11 = tail call i32 (...) @getuid()
%12 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i32 %11, 0
%14 = select i1 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0)
%15 = tail call i8* @getenv(i8* %14)
%16 = bitcast %struct.stat* %7 to i8*
store i8 0, i8* %8
%17 = tail call %struct.passwd* @getpwuid(i32 %11)
%18 = icmp eq %struct.passwd* %17, null
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = tail call i32 (...) @getuid()
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.3, i64 0, i64 0), i32 %21)
br label %182
23: ; preds = %3
%24 = call i32 @strncpy(i8* %9, i8* %0, i32 4096)
%25 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 4096
store i8 0, i8* %25
%26 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %0)
%29 = sub nsw i32 4096, %28
%30 = call i32 @strncat(i8* %9, i8* %27, i32 %29)
%31 = icmp eq i8* %15, null
br i1 %31, label %35, label %32
32: ; preds = %23
%33 = load i8, i8* %15
switch i8 %33, label %61 [
i8 0, label %35
i8 126, label %34
]
34: ; preds = %32
br label %35
35: ; preds = %32, %34, %23
%36 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %23 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), %32 ], [ %15, %34 ]
br i1 %13, label %37, label %42
37: ; preds = %35
%38 = getelementptr inbounds %struct.passwd, %struct.passwd* %17, i64 0, i32 1
%39 = load i8*, i8** %38
%40 = icmp eq i8* %39, null
%41 = select i1 %40, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %39
br label %44
42: ; preds = %35
%43 = icmp eq i8* %12, null
br i1 %43, label %48, label %44
44: ; preds = %37, %42
%45 = phi i8* [ %12, %42 ], [ %41, %37 ]
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 0
br i1 %47, label %48, label %51
48: ; preds = %44, %42
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0))
br label %182
51: ; preds = %44
%52 = call i32 @strlen(i8* %45)
%53 = icmp sgt i32 %52, 3996
br i1 %53, label %54, label %57
54: ; preds = %51
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.7, i64 0, i64 0))
br label %182
57: ; preds = %51
%58 = getelementptr inbounds i8, i8* %36, i64 1
%59 = call i32 @strncpy(i8* %8, i8* %45, i32 4096)
%60 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 4096
store i8 0, i8* %60
br label %61
61: ; preds = %32, %57
%62 = phi i8* [ %58, %57 ], [ %15, %32 ]
%63 = call i32 @strlen(i8* %8)
%64 = sub nsw i32 4096, %63
%65 = call i32 @strncat(i8* %8, i8* %62, i32 %64)
%66 = call i32 @strlen(i8* %8)
%67 = add nsw i32 %66, -1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = icmp eq i8 %70, 47
br i1 %71, label %72, label %77
72: ; preds = %61
%73 = call i32 @strlen(i8* %8)
%74 = add nsw i32 %73, -1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 %75
store i8 0, i8* %76
br label %77
77: ; preds = %72, %61
%78 = call i32 @stat(i8* %8, %struct.stat* %7)
%79 = icmp eq i32 %78, -1
br i1 %79, label %80, label %89
80: ; preds = %77
%81 = load i64, i64* @errno
%82 = load i64, i64* @ENOENT
%83 = icmp eq i64 %81, %82
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = call i32 @mkdir(i8* %8, i32 448)
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %89
87: ; preds = %80, %84
%88 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0))
br label %182
89: ; preds = %77, %84
%90 = call i32 @strlen(i8* %8)
%91 = sub nsw i32 4096, %90
%92 = call i32 @strncat(i8* %8, i8* %1, i32 %91)
%93 = icmp eq i32 %2, 0
br i1 %93, label %105, label %94
94: ; preds = %89
%95 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%96 = icmp eq i8* %95, null
br i1 %96, label %182, label %97
97: ; preds = %94
%98 = call i32 @strlen(i8* %8)
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 %99
%101 = call i8* @getenv(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%102 = call i32 @strlen(i8* %8)
%103 = sub i32 4095, %102
%104 = call i32 @strncat(i8* %100, i8* %101, i32 %103)
br label %115
105: ; preds = %89
%106 = call i32 @strlen(i8* %8)
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 %107
%109 = call i32 @strlen(i8* %8)
%110 = sub i32 4095, %109
%111 = call i64 @gethostname(i8* %108, i32 %110)
%112 = icmp eq i64 %111, 0
br i1 %112, label %115, label %113
113: ; preds = %105
%114 = call i32 @perror(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.10, i64 0, i64 0))
br label %182
115: ; preds = %105, %97
%116 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 4096
store i8 0, i8* %116
%117 = call i32 @lstat(i8* %8, %struct.stat* %7)
switch i32 %117, label %118 [
i32 0, label %121
i32 -1, label %126
]
118: ; preds = %115
%119 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%120 = load i32, i32* %119
br label %140
121: ; preds = %115
%122 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%123 = load i32, i32* %122
%124 = call i64 @S_ISDIR(i32 %123)
%125 = icmp eq i64 %124, 0
br i1 %125, label %140, label %182
126: ; preds = %115
%127 = load i64, i64* @errno
%128 = load i64, i64* @ENOENT
%129 = icmp eq i64 %127, %128
br i1 %129, label %130, label %144
130: ; preds = %126
%131 = call i32 @create_link(i8* %8, i8* %9)
%132 = icmp eq i32 %131, 0
br i1 %132, label %182, label %133
133: ; preds = %130
%134 = call i32 @unlink(i8* %8)
%135 = call i32 @strlen(i8* %9)
%136 = sub nsw i32 4096, %135
%137 = call i32 @strncat(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %136)
%138 = call i32 @mktemp(i8* %9)
%139 = call i32 @create_link(i8* %8, i8* %9)
br label %182
140: ; preds = %118, %121
%141 = phi i32 [ %120, %118 ], [ %123, %121 ]
%142 = call i32 @S_ISLNK(i32 %141)
%143 = icmp eq i32 %142, 0
br i1 %143, label %144, label %147
144: ; preds = %126, %140
%145 = load i32, i32* @stderr
%146 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.12, i64 0, i64 0), i8* %8)
br label %182
147: ; preds = %140
%148 = call i32 @readlink(i8* %8, i8* %10, i32 4096)
%149 = icmp eq i32 %148, -1
br i1 %149, label %150, label %153
150: ; preds = %147
%151 = load i32, i32* @stderr
%152 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0), i8* %8)
br label %182
153: ; preds = %147
%154 = sext i32 %148 to i64
%155 = getelementptr inbounds [4097 x i8], [4097 x i8]* %6, i64 0, i64 %154
store i8 0, i8* %155
%156 = call i32 @strlen(i8* %9)
%157 = call i64 @strncmp(i8* %10, i8* %9, i32 %156)
%158 = icmp eq i64 %157, 0
br i1 %158, label %172, label %159
159: ; preds = %153
%160 = load i32, i32* @stderr
%161 = call i32 (i32, i8*, ...) @fprintf(i32 %160, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.14, i64 0, i64 0), i8* %8, i8* %10, i8* %9)
%162 = call i32 @unlink(i8* %8)
%163 = call i32 @create_link(i8* %8, i8* %9)
%164 = icmp eq i32 %163, 0
br i1 %164, label %182, label %165
165: ; preds = %159
%166 = call i32 @unlink(i8* %8)
%167 = call i32 @strlen(i8* %9)
%168 = sub nsw i32 4096, %167
%169 = call i32 @strncat(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %168)
%170 = call i32 @mktemp(i8* %9)
%171 = call i32 @create_link(i8* %8, i8* %9)
br label %182
172: ; preds = %153
%173 = call i32 @check_tmp_dir(i8* %10)
%174 = icmp eq i32 %173, 0
br i1 %174, label %182, label %175
175: ; preds = %172
%176 = call i32 @unlink(i8* %8)
%177 = call i32 @strlen(i8* %9)
%178 = sub nsw i32 4096, %177
%179 = call i32 @strncat(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.11, i64 0, i64 0), i32 %178)
%180 = call i32 @mktemp(i8* %9)
%181 = call i32 @create_link(i8* %8, i8* %9)
br label %182
182: ; preds = %172, %159, %130, %121, %94, %175, %165, %150, %144, %133, %113, %87, %54, %48, %19
%183 = phi i32 [ 1, %54 ], [ 1, %87 ], [ %139, %133 ], [ 1, %144 ], [ 1, %150 ], [ %171, %165 ], [ %181, %175 ], [ 1, %113 ], [ 1, %48 ], [ 1, %19 ], [ 0, %94 ], [ 0, %121 ], [ 0, %130 ], [ 0, %159 ], [ 0, %172 ]
ret i32 %183
}