#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;
int PATH_MAX;
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*/ exit(int);
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) {
  struct passwd *pw_ent;
  char kde_tmp_dir[PATH_MAX + 1];
  char user_tmp_dir[PATH_MAX + 1];
  char tmp_buf[PATH_MAX + 1];
  int uid = getuid();
  const char *home_dir = getenv("HOME");
  const char *kde_home = uid ? getenv("KDEHOME") : getenv("KDEROOTHOME");
  int result;
  struct stat stat_buf;
  kde_tmp_dir[0] = 0;
  pw_ent = getpwuid(uid);
  if (!pw_ent) {
    fprintf(stderr, "Error: Can not find password entry for uid %d.\n",
            getuid());
    return 1;
  }
  strncpy(user_tmp_dir, tmp_prefix, PATH_MAX);
  user_tmp_dir[PATH_MAX] = '\0';
  strncat(user_tmp_dir, pw_ent->pw_name, PATH_MAX - strlen(tmp_prefix));
  if (!kde_home || !kde_home[0]) {
    kde_home = "~/.kde/";
  }
  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, "Aborting. $HOME not set!\n");
      return 1;
    }
    if (strlen(home_dir) > (PATH_MAX - 100)) {
      fprintf(stderr, "Aborting. Home directory path too long!\n");
      return 1;
    }
    kde_home++;
    strncpy(kde_tmp_dir, home_dir, PATH_MAX);
    kde_tmp_dir[PATH_MAX] = '\0';
  }
  strncat(kde_tmp_dir, kde_home, PATH_MAX - 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("mkdir failed: ");
    return 1;
  }
  strncat(kde_tmp_dir, kde_prefix, PATH_MAX - strlen(kde_tmp_dir));
  if (gethostname(kde_tmp_dir + strlen(kde_tmp_dir),
                  PATH_MAX - strlen(kde_tmp_dir) - 1) != 0) {
    perror("Aborting. Could not determine hostname: ");
    exit(255);
  }
  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", PATH_MAX - 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, "Error: \"%s\" is not a link or a directory.\n",
            kde_tmp_dir);
    return 1;
  }
  result = readlink(kde_tmp_dir, tmp_buf, PATH_MAX);
  if (result == -1) {
    fprintf(stderr, "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, "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", PATH_MAX - 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", PATH_MAX - 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    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rcx,-0x88(%rbp)
mov    %rsp,%rdx
mov    %rdx,-0x28(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x80(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x30(%rbp)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x78(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x70(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   10c0 <getuid@plt>
mov    %eax,-0x44(%rbp)
lea    0xd17(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x50(%rbp)
cmpl   $0x0,-0x44(%rbp)
je     1317 <build_link+0xc7>
lea    0xcfa(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x90(%rbp)
jmp    132a <build_link+0xda>
lea    0xcea(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x90(%rbp)
mov    -0x80(%rbp),%rax
mov    -0x90(%rbp),%rcx
mov    %rcx,-0x58(%rbp)
movb   $0x0,(%rax)
mov    -0x44(%rbp),%edi
call   10a0 <getpwuid@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1392 <build_link+0x142>
mov    0x2c7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    $0x0,%al
call   10c0 <getuid@plt>
mov    -0x94(%rbp),%edi
mov    %eax,%edx
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x78(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2c4f(%rip),%rax
mov    (%rax),%edx
call   1050 <strncpy@plt>
mov    -0x78(%rbp),%rax
mov    0x2c3d(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0xa0(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0xa4(%rbp),%edx
mov    -0x78(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
sub    %eax,%edx
call   10e0 <strncat@plt>
cmpq   $0x0,-0x58(%rbp)
je     1410 <build_link+0x1c0>
mov    -0x58(%rbp),%rax
cmpb   $0x0,(%rax)
jne    141b <build_link+0x1cb>
lea    0xc2d(%rip),%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    1533 <build_link+0x2e3>
cmpl   $0x0,-0x44(%rbp)
jne    1476 <build_link+0x226>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     1458 <build_link+0x208>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xb0(%rbp)
jmp    146b <build_link+0x21b>
lea    0xbed(%rip),%rax
mov    %rax,-0xb0(%rbp)
jmp    146b <build_link+0x21b>
mov    -0xb0(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     148e <build_link+0x23e>
mov    -0x50(%rbp),%rax
cmpb   $0x0,(%rax)
jne    14b8 <build_link+0x268>
mov    0x2b43(%rip),%rax
mov    (%rax),%edi
lea    0xbb4(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x50(%rbp),%rdi
call   10b0 <strlen@plt>
mov    0x2b28(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x64,%ecx
cmp    %ecx,%eax
jle    14ff <build_link+0x2af>
mov    0x2afc(%rip),%rax
mov    (%rax),%edi
lea    0xb87(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x80(%rbp),%rdi
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x50(%rbp),%rsi
mov    0x2ad6(%rip),%rax
mov    (%rax),%edx
call   1050 <strncpy@plt>
mov    -0x80(%rbp),%rax
mov    0x2ac4(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x80(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    0x2aa7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
call   10b0 <strlen@plt>
mov    -0xbc(%rbp),%edx
mov    -0xb8(%rbp),%rsi
mov    -0x80(%rbp),%rdi
sub    %eax,%edx
call   10e0 <strncat@plt>
mov    -0x80(%rbp),%rdi
call   10b0 <strlen@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    15a9 <build_link+0x359>
mov    -0x80(%rbp),%rdi
call   10b0 <strlen@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1110 <stat@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    15ee <build_link+0x39e>
mov    0x2a06(%rip),%rax
mov    (%rax),%rax
mov    0x29ec(%rip),%rcx
cmp    (%rcx),%rax
jne    15ee <build_link+0x39e>
mov    -0x80(%rbp),%rdi
mov    $0x1c0,%esi
call   1080 <mkdir@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    1617 <build_link+0x3c7>
lea    0xa96(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    %rax,-0xd8(%rbp)
mov    0x29c3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdc(%rbp)
call   10b0 <strlen@plt>
mov    -0xdc(%rbp),%edx
mov    -0xd8(%rbp),%rsi
mov    -0x80(%rbp),%rdi
sub    %eax,%edx
call   10e0 <strncat@plt>
mov    -0x80(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x80(%rbp),%rdi
movslq %eax,%rcx
mov    %rdi,%rax
add    %rcx,%rax
mov    %rax,-0xc8(%rbp)
mov    0x297a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xcc(%rbp)
call   10b0 <strlen@plt>
mov    -0xcc(%rbp),%esi
mov    -0xc8(%rbp),%rdi
sub    %eax,%esi
sub    $0x1,%esi
call   1150 <gethostname@plt>
cmp    $0x0,%rax
je     16ba <build_link+0x46a>
lea    0x9f9(%rip),%rdi
call   1130 <perror@plt>
mov    $0xff,%edi
call   1160 <exit@plt>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,(%rdi,%rax,1)
lea    -0x60(%rbp),%rsi
call   10f0 <lstat@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1708 <build_link+0x4b8>
mov    -0x60(%rbp),%edi
call   10d0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1708 <build_link+0x4b8>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
cmpl   $0xffffffff,-0x5c(%rbp)
jne    17b7 <build_link+0x567>
mov    0x28b7(%rip),%rax
mov    (%rax),%rax
mov    0x289d(%rip),%rcx
cmp    (%rcx),%rax
jne    17b7 <build_link+0x567>
mov    -0x78(%rbp),%rsi
mov    -0x80(%rbp),%rdi
call   1120 <create_link@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    1759 <build_link+0x509>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x80(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x78(%rbp),%rdi
mov    0x2883(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe0(%rbp)
call   10b0 <strlen@plt>
mov    -0xe0(%rbp),%edx
mov    -0x78(%rbp),%rdi
sub    %eax,%edx
lea    0x940(%rip),%rsi
call   10e0 <strncat@plt>
mov    -0x78(%rbp),%rdi
call   1170 <mktemp@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
cmpl   $0xffffffff,-0x5c(%rbp)
je     17d2 <build_link+0x582>
mov    -0x60(%rbp),%edi
call   1070 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    1800 <build_link+0x5b0>
mov    -0x80(%rbp),%rdx
mov    0x27fb(%rip),%rax
mov    (%rax),%edi
lea    0x8ee(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x70(%rbp),%rsi
mov    -0x80(%rbp),%rdi
mov    0x27e1(%rip),%rax
mov    (%rax),%edx
call   1090 <readlink@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    1851 <build_link+0x601>
mov    -0x80(%rbp),%rdx
mov    0x27aa(%rip),%rax
mov    (%rax),%edi
lea    0x8c8(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x78(%rbp),%rdi
mov    -0x70(%rbp),%rax
movslq -0x5c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
call   10b0 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
je     1936 <build_link+0x6e6>
mov    -0x78(%rbp),%r8
mov    -0x80(%rbp),%rdx
mov    -0x70(%rbp),%rcx
mov    0x2746(%rip),%rax
mov    (%rax),%edi
lea    0x884(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
mov    -0x80(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    18d8 <build_link+0x688>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x80(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x78(%rbp),%rdi
mov    0x2704(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
call   10b0 <strlen@plt>
mov    -0xe4(%rbp),%edx
mov    -0x78(%rbp),%rdi
sub    %eax,%edx
lea    0x7c1(%rip),%rsi
call   10e0 <strncat@plt>
mov    -0x78(%rbp),%rdi
call   1170 <mktemp@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x70(%rbp),%rdi
call   1140 <check_tmp_dir@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jne    195f <build_link+0x70f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
jmp    19b8 <build_link+0x768>
mov    -0x80(%rbp),%rdi
call   1040 <unlink@plt>
mov    -0x78(%rbp),%rdi
mov    0x267d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe8(%rbp)
call   10b0 <strlen@plt>
mov    -0xe8(%rbp),%edx
mov    -0x78(%rbp),%rdi
sub    %eax,%edx
lea    0x73a(%rip),%rsi
call   10e0 <strncat@plt>
mov    -0x78(%rbp),%rdi
call   1170 <mktemp@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_link>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,-0x60(%rbp)
mov    %rdi,-0x38(%rbp)
mov    0x2d80(%rip),%r14
mov    (%r14),%eax
add    $0x1,%eax
mov    %rsp,%rbx
mov    %rax,-0x58(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    %rsp,%rcx
sub    %rax,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
xor    %eax,%eax
call   10c0 <getuid@plt>
mov    %eax,%r15d
lea    0xd51(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x70(%rbp)
test   %r15d,%r15d
lea    0xd43(%rip),%rax
lea    0xd34(%rip),%rdi
cmove  %rax,%rdi
call   1030 <getenv@plt>
mov    %rax,%r13
movb   $0x0,(%rbx)
mov    %r15d,%edi
call   10a0 <getpwuid@plt>
test   %rax,%rax
je     139b <build_link+0x14b>
mov    %rbx,-0x40(%rbp)
mov    (%r14),%edx
mov    %r12,%rdi
mov    %r13,-0x68(%rbp)
mov    -0x38(%rbp),%r13
mov    %r13,%rsi
mov    %r14,%rbx
mov    %rax,%r14
call   1050 <strncpy@plt>
movslq (%rbx),%rbx
movb   $0x0,(%r12,%rbx,1)
mov    %r14,-0x48(%rbp)
mov    (%r14),%r14
mov    %r13,%rdi
mov    -0x68(%rbp),%r13
call   10b0 <strlen@plt>
sub    %eax,%ebx
mov    %r12,-0x38(%rbp)
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   10e0 <strncat@plt>
lea    0xd03(%rip),%r12
test   %r13,%r13
je     13c2 <build_link+0x172>
mov    0x0(%r13),%al
test   %al,%al
mov    0x2c9d(%rip),%r14
je     1360 <build_link+0x110>
cmp    $0x7e,%al
jne    1405 <build_link+0x1b5>
mov    %r13,%r12
test   %r15d,%r15d
je     13ce <build_link+0x17e>
mov    -0x70(%rbp),%rbx
test   %rbx,%rbx
je     13e9 <build_link+0x199>
cmpb   $0x0,(%rbx)
je     13e9 <build_link+0x199>
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    (%r14),%edx
lea    -0x64(%rdx),%ecx
cmp    %ecx,%eax
jle    140e <build_link+0x1be>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
lea    0xcd3(%rip),%rsi
jmp    13f9 <build_link+0x1a9>
mov    0x2c36(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10c0 <getuid@plt>
lea    0xc62(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1100 <fprintf@plt>
jmp    1663 <build_link+0x413>
mov    0x2c27(%rip),%r14
test   %r15d,%r15d
jne    1365 <build_link+0x115>
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rax
test   %rax,%rax
lea    0xc6c(%rip),%rbx
cmovne %rax,%rbx
cmpb   $0x0,(%rbx)
jne    1373 <build_link+0x123>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
lea    0xc59(%rip),%rsi
xor    %eax,%eax
call   1100 <fprintf@plt>
jmp    1663 <build_link+0x413>
mov    (%r14),%ebx
mov    -0x40(%rbp),%r15
jmp    142c <build_link+0x1dc>
add    $0x1,%r12
mov    -0x40(%rbp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strncpy@plt>
movslq (%r14),%rbx
movb   $0x0,(%r15,%rbx,1)
mov    %r12,%r13
mov    %r15,%rdi
call   10b0 <strlen@plt>
sub    %eax,%ebx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %ebx,%edx
call   10e0 <strncat@plt>
mov    %r15,%rdi
call   10b0 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
mov    -0x38(%rbp),%r12
jne    1469 <build_link+0x219>
mov    %r15,%rdi
call   10b0 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r15,1)
lea    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   1110 <stat@plt>
cmp    $0xffffffff,%eax
jne    14aa <build_link+0x25a>
mov    0x2b4f(%rip),%rax
mov    (%rax),%rax
mov    0x2b35(%rip),%rcx
cmp    (%rcx),%rax
jne    1698 <build_link+0x448>
mov    %r15,%rdi
mov    $0x1c0,%esi
call   1080 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1698 <build_link+0x448>
mov    (%r14),%ebx
mov    %r15,%rdi
call   10b0 <strlen@plt>
sub    %eax,%ebx
mov    %r15,%rdi
mov    -0x60(%rbp),%rsi
mov    %ebx,%edx
call   10e0 <strncat@plt>
mov    %r15,%rdi
call   10b0 <strlen@plt>
mov    %r14,%rcx
movslq %eax,%r14
add    %r15,%r14
mov    (%rcx),%ebx
mov    %r15,%rdi
call   10b0 <strlen@plt>
not    %eax
add    %eax,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1150 <gethostname@plt>
test   %rax,%rax
jne    16a6 <build_link+0x456>
mov    -0x58(%rbp),%rax
movb   $0x0,-0x1(%rax,%r15,1)
lea    -0x30(%rbp),%rsi
mov    %r15,%rdi
call   10f0 <lstat@plt>
cmp    $0xffffffff,%eax
je     152f <build_link+0x2df>
test   %eax,%eax
jne    1561 <build_link+0x311>
mov    -0x30(%rbp),%r14d
mov    %r14d,%edi
call   10d0 <S_ISDIR@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    1668 <build_link+0x418>
jmp    1565 <build_link+0x315>
mov    0x2a9a(%rip),%rax
mov    (%rax),%rax
mov    0x2a80(%rip),%rcx
cmp    (%rcx),%rax
jne    1637 <build_link+0x3e7>
mov    %r15,%rdi
mov    %r12,%rsi
call   1120 <create_link@plt>
test   %eax,%eax
jne    15f4 <build_link+0x3a4>
jmp    1694 <build_link+0x444>
mov    -0x30(%rbp),%r14d
mov    %r14d,%edi
call   1070 <S_ISLNK@plt>
test   %eax,%eax
je     1637 <build_link+0x3e7>
mov    0x2a74(%rip),%rbx
mov    (%rbx),%edx
mov    %r15,%rdi
mov    -0x50(%rbp),%r14
mov    %r14,%rsi
call   1090 <readlink@plt>
cmp    $0xffffffff,%eax
je     1649 <build_link+0x3f9>
cltq
movb   $0x0,(%r14,%rax,1)
mov    %r12,%rdi
call   10b0 <strlen@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
test   %rax,%rax
je     1679 <build_link+0x429>
mov    0x2a16(%rip),%rax
mov    (%rax),%edi
lea    0xb54(%rip),%rsi
xor    %ebx,%ebx
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    %r15,%rdi
call   1040 <unlink@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1120 <create_link@plt>
test   %eax,%eax
je     1668 <build_link+0x418>
mov    %r15,%rdi
call   1040 <unlink@plt>
mov    0x29ed(%rip),%rax
mov    (%rax),%ebx
mov    %r12,%rdi
call   10b0 <strlen@plt>
sub    %eax,%ebx
lea    0xab7(%rip),%rsi
mov    %r12,%rdi
mov    %ebx,%edx
call   10e0 <strncat@plt>
mov    %r12,%rdi
call   1170 <mktemp@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1120 <create_link@plt>
mov    %eax,%ebx
jmp    1668 <build_link+0x418>
mov    0x299a(%rip),%rax
mov    (%rax),%edi
lea    0xa8d(%rip),%rsi
jmp    1659 <build_link+0x409>
mov    0x2988(%rip),%rax
mov    (%rax),%edi
lea    0xaa6(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1100 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1140 <check_tmp_dir@plt>
test   %eax,%eax
je     1694 <build_link+0x444>
mov    %r15,%rdi
call   1040 <unlink@plt>
mov    (%rbx),%ebx
jmp    1605 <build_link+0x3b5>
xor    %ebx,%ebx
jmp    1668 <build_link+0x418>
lea    0x9f6(%rip),%rdi
call   1130 <perror@plt>
jmp    1663 <build_link+0x413>
lea    0x9f7(%rip),%rdi
call   1130 <perror@plt>
mov    $0xff,%edi
call   1160 <exit@plt>

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

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