#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*/ 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[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("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, 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 = "~/.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) > (4096 - 100)) {
      fprintf(stderr, "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("mkdir failed: ");
    return 1;
  }
  strncat(kde_tmp_dir, kde_prefix, 4096 - strlen(kde_tmp_dir));
  if (gethostname(kde_tmp_dir + strlen(kde_tmp_dir),
                  4096 - 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", 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, "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, "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", 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    $0x30f0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    $0x0,%al
call   10c0 <getuid@plt>
mov    %eax,-0x3054(%rbp)
lea    0xd8c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x3060(%rbp)
cmpl   $0x0,-0x3054(%rbp)
je     12a8 <build_link+0x58>
lea    0xd69(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x3078(%rbp)
jmp    12bb <build_link+0x6b>
lea    0xd59(%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,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1322 <build_link+0xd2>
mov    0x2cef(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x307c(%rbp)
mov    $0x0,%al
call   10c0 <getuid@plt>
mov    -0x307c(%rbp),%edi
mov    %eax,%edx
lea    0xd05(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
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    -0x20(%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     139b <build_link+0x14b>
mov    -0x3068(%rbp),%rax
cmpb   $0x0,(%rax)
jne    13a9 <build_link+0x159>
lea    0xca2(%rip),%rax
mov    %rax,-0x3068(%rbp)
mov    -0x3068(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    14b6 <build_link+0x266>
cmpl   $0x0,-0x3054(%rbp)
jne    140d <build_link+0x1bd>
mov    -0x20(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     13ec <build_link+0x19c>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x3098(%rbp)
jmp    13ff <build_link+0x1af>
lea    0xc59(%rip),%rax
mov    %rax,-0x3098(%rbp)
jmp    13ff <build_link+0x1af>
mov    -0x3098(%rbp),%rax
mov    %rax,-0x3060(%rbp)
cmpq   $0x0,-0x3060(%rbp)
je     142b <build_link+0x1db>
mov    -0x3060(%rbp),%rax
cmpb   $0x0,(%rax)
jne    144e <build_link+0x1fe>
mov    0x2bae(%rip),%rax
mov    (%rax),%edi
lea    0xc17(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
mov    -0x3060(%rbp),%rdi
call   10b0 <strlen@plt>
cmp    $0xf9c,%eax
jle    1488 <build_link+0x238>
mov    0x2b74(%rip),%rax
mov    (%rax),%edi
lea    0xbf7(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
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    1533 <build_link+0x2e3>
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    158a <build_link+0x33a>
mov    0x2a78(%rip),%rax
mov    (%rax),%rax
mov    0x2a5e(%rip),%rcx
cmp    (%rcx),%rax
jne    158a <build_link+0x33a>
lea    -0x1030(%rbp),%rdi
mov    $0x1c0,%esi
call   1080 <mkdir@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0xffffffff,-0x306c(%rbp)
jne    15af <build_link+0x35f>
lea    0xaf7(%rip),%rdi
call   1130 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30c8(%rbp)
mov    -0x18(%rbp),%rax
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
call   10e0 <strncat@plt>
lea    -0x1030(%rbp),%rax
mov    %rax,-0x30b8(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    %eax,%ecx
mov    -0x30b8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x30b0(%rbp)
lea    -0x1030(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30b0(%rbp),%rdi
mov    $0x1000,%esi
sub    %eax,%esi
sub    $0x1,%esi
call   1150 <gethostname@plt>
cmp    $0x0,%rax
je     1660 <build_link+0x410>
lea    0xa53(%rip),%rdi
call   1130 <perror@plt>
mov    $0xff,%edi
call   1160 <exit@plt>
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    16ab <build_link+0x45b>
mov    -0x3070(%rbp),%edi
call   10d0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     16ab <build_link+0x45b>
movl   $0x0,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
cmpl   $0xffffffff,-0x306c(%rbp)
jne    176b <build_link+0x51b>
mov    0x2919(%rip),%rax
mov    (%rax),%rax
mov    0x28ff(%rip),%rcx
cmp    (%rcx),%rax
jne    176b <build_link+0x51b>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0x0,-0x306c(%rbp)
jne    1704 <build_link+0x4b4>
movl   $0x0,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
lea    -0x1030(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x30d0(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30d0(%rbp),%rdi
mov    $0x1000,%edx
sub    %eax,%edx
lea    0x98e(%rip),%rsi
call   10e0 <strncat@plt>
lea    -0x2040(%rbp),%rdi
call   1170 <mktemp@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
cmpl   $0xffffffff,-0x306c(%rbp)
je     178c <build_link+0x53c>
mov    -0x3070(%rbp),%edi
call   1070 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    17b6 <build_link+0x566>
mov    0x284d(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    0x931(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
lea    -0x1030(%rbp),%rdi
lea    -0x3050(%rbp),%rsi
mov    $0x1000,%edx
call   1090 <readlink@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0xffffffff,-0x306c(%rbp)
jne    180b <build_link+0x5bb>
mov    0x27f8(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    0x907(%rip),%rsi
mov    $0x0,%al
call   1100 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
movslq -0x306c(%rbp),%rax
movb   $0x0,-0x3050(%rbp,%rax,1)
lea    -0x3050(%rbp),%rax
mov    %rax,-0x30e0(%rbp)
lea    -0x2040(%rbp),%rax
mov    %rax,-0x30d8(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30e0(%rbp),%rdi
mov    -0x30d8(%rbp),%rsi
mov    %eax,%edx
call   1060 <strncmp@plt>
cmp    $0x0,%rax
je     1932 <build_link+0x6e2>
mov    0x2778(%rip),%rax
mov    (%rax),%edi
lea    -0x1030(%rbp),%rdx
lea    -0x3050(%rbp),%rcx
lea    -0x2040(%rbp),%r8
lea    0x899(%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    18cb <build_link+0x67b>
movl   $0x0,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
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    0x7c7(%rip),%rsi
call   10e0 <strncat@plt>
lea    -0x2040(%rbp),%rdi
call   1170 <mktemp@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
lea    -0x3050(%rbp),%rdi
call   1140 <check_tmp_dir@plt>
mov    %eax,-0x306c(%rbp)
cmpl   $0x0,-0x306c(%rbp)
jne    195d <build_link+0x70d>
movl   $0x0,-0x4(%rbp)
jmp    19bf <build_link+0x76f>
lea    -0x1030(%rbp),%rdi
call   1040 <unlink@plt>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x30f0(%rbp)
lea    -0x2040(%rbp),%rdi
call   10b0 <strlen@plt>
mov    -0x30f0(%rbp),%rdi
mov    $0x1000,%edx
sub    %eax,%edx
lea    0x735(%rip),%rsi
call   10e0 <strncat@plt>
lea    -0x2040(%rbp),%rdi
call   1170 <mktemp@plt>
lea    -0x1030(%rbp),%rdi
lea    -0x2040(%rbp),%rsi
call   1120 <create_link@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30f0,%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    %rsi,%r14
mov    %rdi,%r13
xor    %eax,%eax
call   10c0 <getuid@plt>
mov    %eax,%ebp
lea    0xd8c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,%r15
test   %ebp,%ebp
lea    0xd80(%rip),%rax
lea    0xd71(%rip),%rdi
cmove  %rax,%rdi
call   1030 <getenv@plt>
mov    %rax,%r12
movb   $0x0,0x20(%rsp)
mov    %ebp,%edi
call   10a0 <getpwuid@plt>
test   %rax,%rax
je     1355 <build_link+0x105>
mov    %rax,%rbx
mov    %r15,0x10(%rsp)
mov    %r14,0x18(%rsp)
lea    0x1030(%rsp),%rdi
mov    $0x1000,%r15d
mov    %r13,%rsi
mov    $0x1000,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x2030(%rsp)
mov    (%rbx),%r14
mov    %r13,%rdi
call   10b0 <strlen@plt>
sub    %eax,%r15d
lea    0x1030(%rsp),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   10e0 <strncat@plt>
lea    0xd3c(%rip),%r14
test   %r12,%r12
je     137c <build_link+0x12c>
mov    (%r12),%al
test   %al,%al
mov    0x10(%rsp),%r15
je     1325 <build_link+0xd5>
cmp    $0x7e,%al
jne    13da <build_link+0x18a>
mov    %r12,%r14
test   %ebp,%ebp
je     1385 <build_link+0x135>
test   %r15,%r15
je     139d <build_link+0x14d>
cmpb   $0x0,(%r15)
je     139d <build_link+0x14d>
mov    %r15,%rdi
call   10b0 <strlen@plt>
cmp    $0xf9d,%eax
jl     13b9 <build_link+0x169>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
jmp    13ad <build_link+0x15d>
mov    0x2c84(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   10c0 <getuid@plt>
lea    0xca8(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1100 <fprintf@plt>
jmp    1609 <build_link+0x3b9>
mov    0x10(%rsp),%r15
test   %ebp,%ebp
jne    1329 <build_link+0xd9>
mov    0x8(%rbx),%rax
test   %rax,%rax
lea    0xcb9(%rip),%r15
cmovne %rax,%r15
cmpb   $0x0,(%r15)
jne    1334 <build_link+0xe4>
mov    0x2c3c(%rip),%rax
mov    (%rax),%edi
lea    0xca5(%rip),%rsi
xor    %eax,%eax
call   1100 <fprintf@plt>
jmp    1609 <build_link+0x3b9>
add    $0x1,%r14
lea    0x20(%rsp),%rdi
mov    %r15,%rsi
mov    $0x1000,%edx
call   1050 <strncpy@plt>
movb   $0x0,0x1020(%rsp)
mov    %r14,%r12
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    $0x1000,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r12,%rsi
call   10e0 <strncat@plt>
mov    %rbx,%rdi
call   10b0 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
mov    0x18(%rsp),%rbp
jne    141e <build_link+0x1ce>
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    1464 <build_link+0x214>
mov    0x2b9f(%rip),%rax
mov    (%rax),%rax
mov    0x2b85(%rip),%rcx
cmp    (%rcx),%rax
jne    1681 <build_link+0x431>
lea    0x20(%rsp),%rdi
mov    $0x1c0,%esi
call   1080 <mkdir@plt>
cmp    $0xffffffff,%eax
je     1681 <build_link+0x431>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <strlen@plt>
mov    $0x1000,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10e0 <strncat@plt>
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    1692 <build_link+0x442>
movb   $0x0,0x1020(%rsp)
lea    0x20(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   10f0 <lstat@plt>
cmp    $0xffffffff,%eax
je     14ed <build_link+0x29d>
test   %eax,%eax
jne    1526 <build_link+0x2d6>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   10d0 <S_ISDIR@plt>
xor    %ebx,%ebx
test   %rax,%rax
jne    160e <build_link+0x3be>
jmp    152a <build_link+0x2da>
mov    0x2ae4(%rip),%rax
mov    (%rax),%rax
mov    0x2aca(%rip),%rcx
cmp    (%rcx),%rax
jne    15db <build_link+0x38b>
lea    0x20(%rsp),%rdi
lea    0x1030(%rsp),%rsi
call   1120 <create_link@plt>
test   %eax,%eax
jne    1633 <build_link+0x3e3>
jmp    167d <build_link+0x42d>
mov    0x8(%rsp),%ebp
mov    %ebp,%edi
call   1070 <S_ISLNK@plt>
test   %eax,%eax
je     15db <build_link+0x38b>
lea    0x20(%rsp),%rdi
lea    0x2040(%rsp),%rsi
mov    $0x1000,%edx
call   1090 <readlink@plt>
cmp    $0xffffffff,%eax
je     15ed <build_link+0x39d>
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     1622 <build_link+0x3d2>
mov    0x2a4b(%rip),%rax
mov    (%rax),%edi
lea    0xb81(%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    1633 <build_link+0x3e3>
jmp    160e <build_link+0x3be>
mov    0x29fe(%rip),%rax
mov    (%rax),%edi
lea    0xae9(%rip),%rsi
jmp    15fd <build_link+0x3ad>
mov    0x29ec(%rip),%rax
mov    (%rax),%edi
lea    0xb02(%rip),%rsi
lea    0x20(%rsp),%rdx
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
lea    0x2040(%rsp),%rdi
call   1140 <check_tmp_dir@plt>
test   %eax,%eax
je     167d <build_link+0x42d>
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    0xa6f(%rip),%rsi
mov    %rbp,%rdi
call   10e0 <strncat@plt>
mov    %rbp,%rdi
call   1170 <mktemp@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1120 <create_link@plt>
mov    %eax,%ebx
jmp    160e <build_link+0x3be>
xor    %ebx,%ebx
jmp    160e <build_link+0x3be>
lea    0xa0d(%rip),%rdi
call   1130 <perror@plt>
jmp    1609 <build_link+0x3b9>
lea    0xa0b(%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 }
@.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 [4097 x i8]
%8 = alloca [4097 x i8]
%9 = alloca [4097 x i8]
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca %struct.stat
store i8* %0, i8** %4
store i8* %1, i8** %5
%15 = call i32 (...) @getuid()
store i32 %15, i32* %10
%16 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %16, i8** %11
%17 = load i32, i32* %10
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i8* @getenv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
21: ; preds = %2
%22 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = phi i8* [ %20, %19 ], [ %22, %21 ]
store i8* %24, i8** %12
%25 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
store i8 0, i8* %25
%26 = load i32, i32* %10
%27 = call %struct.passwd* @getpwuid(i32 %26)
store %struct.passwd* %27, %struct.passwd** %6
%28 = load %struct.passwd*, %struct.passwd** %6
%29 = icmp ne %struct.passwd* %28, null
br i1 %29, label %34, label %30
30: ; preds = %23
%31 = load i32, i32* @stderr
%32 = call i32 (...) @getuid()
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i32 %32)
store i32 1, i32* %3
br label %277
34: ; preds = %23
%35 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%36 = load i8*, i8** %4
%37 = call i32 @strncpy(i8* %35, i8* %36, i32 4096)
%38 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 4096
store i8 0, i8* %38
%39 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%40 = load %struct.passwd*, %struct.passwd** %6
%41 = getelementptr inbounds %struct.passwd, %struct.passwd* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = load i8*, i8** %4
%44 = call i32 @strlen(i8* %43)
%45 = sub nsw i32 4096, %44
%46 = call i32 @strncat(i8* %39, i8* %42, i32 %45)
%47 = load i8*, i8** %12
%48 = icmp ne i8* %47, null
br i1 %48, label %49, label %54
49: ; preds = %34
%50 = load i8*, i8** %12
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = icmp ne i8 %52, 0
br i1 %53, label %55, label %54
54: ; preds = %49, %34
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %12
br label %55
55: ; preds = %54, %49
%56 = load i8*, i8** %12
%57 = getelementptr inbounds i8, i8* %56, i64 0
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp eq i32 %59, 126
br i1 %60, label %61, label %101
61: ; preds = %55
%62 = load i32, i32* %10
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %76
64: ; preds = %61
%65 = load %struct.passwd*, %struct.passwd** %6
%66 = getelementptr inbounds %struct.passwd, %struct.passwd* %65, i32 0, i32 1
%67 = load i8*, i8** %66
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %73
69: ; preds = %64
%70 = load %struct.passwd*, %struct.passwd** %6
%71 = getelementptr inbounds %struct.passwd, %struct.passwd* %70, i32 0, i32 1
%72 = load i8*, i8** %71
br label %74
73: ; preds = %64
br label %74
74: ; preds = %73, %69
%75 = phi i8* [ %72, %69 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), %73 ]
store i8* %75, i8** %11
br label %76
76: ; preds = %74, %61
%77 = load i8*, i8** %11
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %84
79: ; preds = %76
%80 = load i8*, i8** %11
%81 = getelementptr inbounds i8, i8* %80, i64 0
%82 = load i8, i8* %81
%83 = icmp ne i8 %82, 0
br i1 %83, label %87, label %84
84: ; preds = %79, %76
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
br label %277
87: ; preds = %79
%88 = load i8*, i8** %11
%89 = call i32 @strlen(i8* %88)
%90 = icmp sgt i32 %89, 3996
br i1 %90, label %91, label %94
91: ; preds = %87
%92 = load i32, i32* @stderr
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
store i32 1, i32* %3
br label %277
94: ; preds = %87
%95 = load i8*, i8** %12
%96 = getelementptr inbounds i8, i8* %95, i32 1
store i8* %96, i8** %12
%97 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%98 = load i8*, i8** %11
%99 = call i32 @strncpy(i8* %97, i8* %98, i32 4096)
%100 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 4096
store i8 0, i8* %100
br label %101
101: ; preds = %94, %55
%102 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%103 = load i8*, i8** %12
%104 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%105 = call i32 @strlen(i8* %104)
%106 = sub nsw i32 4096, %105
%107 = call i32 @strncat(i8* %102, i8* %103, i32 %106)
%108 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%109 = call i32 @strlen(i8* %108)
%110 = sub nsw i32 %109, 1
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 %111
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = icmp eq i32 %114, 47
br i1 %115, label %116, label %122
116: ; preds = %101
%117 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%118 = call i32 @strlen(i8* %117)
%119 = sub nsw i32 %118, 1
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 %120
store i8 0, i8* %121
br label %122
122: ; preds = %116, %101
%123 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%124 = call i32 @stat(i8* %123, %struct.stat* %14)
store i32 %124, i32* %13
%125 = load i32, i32* %13
%126 = icmp eq i32 %125, -1
br i1 %126, label %127, label %134
127: ; preds = %122
%128 = load i64, i64* @errno
%129 = load i64, i64* @ENOENT
%130 = icmp eq i64 %128, %129
br i1 %130, label %131, label %134
131: ; preds = %127
%132 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%133 = call i32 @mkdir(i8* %132, i32 448)
store i32 %133, i32* %13
br label %134
134: ; preds = %131, %127, %122
%135 = load i32, i32* %13
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %139
137: ; preds = %134
%138 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %3
br label %277
139: ; preds = %134
%140 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%141 = load i8*, i8** %5
%142 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%143 = call i32 @strlen(i8* %142)
%144 = sub nsw i32 4096, %143
%145 = call i32 @strncat(i8* %140, i8* %141, i32 %144)
%146 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%147 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%148 = call i32 @strlen(i8* %147)
%149 = sext i32 %148 to i64
%150 = getelementptr inbounds i8, i8* %146, i64 %149
%151 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%152 = call i32 @strlen(i8* %151)
%153 = sub nsw i32 4096, %152
%154 = sub nsw i32 %153, 1
%155 = call i64 @gethostname(i8* %150, i32 %154)
%156 = icmp ne i64 %155, 0
br i1 %156, label %157, label %160
157: ; preds = %139
%158 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%159 = call i32 @exit(i32 255)
unreachable
160: ; preds = %139
%161 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 4096
store i8 0, i8* %161
%162 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%163 = call i32 @lstat(i8* %162, %struct.stat* %14)
store i32 %163, i32* %13
%164 = load i32, i32* %13
%165 = icmp eq i32 %164, 0
br i1 %165, label %166, label %172
166: ; preds = %160
%167 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%168 = load i32, i32* %167
%169 = call i64 @S_ISDIR(i32 %168)
%170 = icmp ne i64 %169, 0
br i1 %170, label %171, label %172
171: ; preds = %166
store i32 0, i32* %3
br label %277
172: ; preds = %166, %160
%173 = load i32, i32* %13
%174 = icmp eq i32 %173, -1
br i1 %174, label %175, label %199
175: ; preds = %172
%176 = load i64, i64* @errno
%177 = load i64, i64* @ENOENT
%178 = icmp eq i64 %176, %177
br i1 %178, label %179, label %199
179: ; preds = %175
%180 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%181 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%182 = call i32 @create_link(i8* %180, i8* %181)
store i32 %182, i32* %13
%183 = load i32, i32* %13
%184 = icmp eq i32 %183, 0
br i1 %184, label %185, label %186
185: ; preds = %179
store i32 0, i32* %3
br label %277
186: ; preds = %179
%187 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%188 = call i32 @unlink(i8* %187)
%189 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%190 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%191 = call i32 @strlen(i8* %190)
%192 = sub nsw i32 4096, %191
%193 = call i32 @strncat(i8* %189, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %192)
%194 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%195 = call i32 @mktemp(i8* %194)
%196 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%197 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%198 = call i32 @create_link(i8* %196, i8* %197)
store i32 %198, i32* %3
br label %277
199: ; preds = %175, %172
%200 = load i32, i32* %13
%201 = icmp eq i32 %200, -1
br i1 %201, label %207, label %202
202: ; preds = %199
%203 = getelementptr inbounds %struct.stat, %struct.stat* %14, i32 0, i32 0
%204 = load i32, i32* %203
%205 = call i32 @S_ISLNK(i32 %204)
%206 = icmp ne i32 %205, 0
br i1 %206, label %211, label %207
207: ; preds = %202, %199
%208 = load i32, i32* @stderr
%209 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%210 = call i32 (i32, i8*, ...) @fprintf(i32 %208, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i8* %209)
store i32 1, i32* %3
br label %277
211: ; preds = %202
%212 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%213 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%214 = call i32 @readlink(i8* %212, i8* %213, i32 4096)
store i32 %214, i32* %13
%215 = load i32, i32* %13
%216 = icmp eq i32 %215, -1
br i1 %216, label %217, label %221
217: ; preds = %211
%218 = load i32, i32* @stderr
%219 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%220 = call i32 (i32, i8*, ...) @fprintf(i32 %218, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %219)
store i32 1, i32* %3
br label %277
221: ; preds = %211
%222 = load i32, i32* %13
%223 = sext i32 %222 to i64
%224 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 %223
store i8 0, i8* %224
%225 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%226 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%227 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%228 = call i32 @strlen(i8* %227)
%229 = call i64 @strncmp(i8* %225, i8* %226, i32 %228)
%230 = icmp ne i64 %229, 0
br i1 %230, label %231, label %258
231: ; preds = %221
%232 = load i32, i32* @stderr
%233 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%234 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%235 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%236 = call i32 (i32, i8*, ...) @fprintf(i32 %232, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0), i8* %233, i8* %234, i8* %235)
%237 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%238 = call i32 @unlink(i8* %237)
%239 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%240 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%241 = call i32 @create_link(i8* %239, i8* %240)
store i32 %241, i32* %13
%242 = load i32, i32* %13
%243 = icmp eq i32 %242, 0
br i1 %243, label %244, label %245
244: ; preds = %231
store i32 0, i32* %3
br label %277
245: ; preds = %231
%246 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%247 = call i32 @unlink(i8* %246)
%248 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%249 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%250 = call i32 @strlen(i8* %249)
%251 = sub nsw i32 4096, %250
%252 = call i32 @strncat(i8* %248, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %251)
%253 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%254 = call i32 @mktemp(i8* %253)
%255 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%256 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%257 = call i32 @create_link(i8* %255, i8* %256)
store i32 %257, i32* %3
br label %277
258: ; preds = %221
%259 = getelementptr inbounds [4097 x i8], [4097 x i8]* %9, i64 0, i64 0
%260 = call i32 @check_tmp_dir(i8* %259)
store i32 %260, i32* %13
%261 = load i32, i32* %13
%262 = icmp eq i32 %261, 0
br i1 %262, label %263, label %264
263: ; preds = %258
store i32 0, i32* %3
br label %277
264: ; preds = %258
%265 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%266 = call i32 @unlink(i8* %265)
%267 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%268 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%269 = call i32 @strlen(i8* %268)
%270 = sub nsw i32 4096, %269
%271 = call i32 @strncat(i8* %267, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %270)
%272 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%273 = call i32 @mktemp(i8* %272)
%274 = getelementptr inbounds [4097 x i8], [4097 x i8]* %7, i64 0, i64 0
%275 = getelementptr inbounds [4097 x i8], [4097 x i8]* %8, i64 0, i64 0
%276 = call i32 @create_link(i8* %274, i8* %275)
store i32 %276, i32* %3
br label %277
277: ; preds = %264, %263, %245, %244, %217, %207, %186, %185, %171, %137, %91, %84, %30
%278 = load i32, i32* %3
ret i32 %278
}

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"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 [4097 x i8]
%4 = alloca [4097 x i8]
%5 = alloca [4097 x i8]
%6 = alloca %struct.stat
%7 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 0
%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 = 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* %6 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 %169
22: ; preds = %2
%23 = call i32 @strncpy(i8* %8, i8* %0, i32 4096)
%24 = getelementptr inbounds [4097 x i8], [4097 x i8]* %4, i64 0, i64 4096
store i8 0, i8* %24
%25 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 @strlen(i8* %0)
%28 = sub nsw i32 4096, %27
%29 = call i32 @strncat(i8* %8, i8* %26, i32 %28)
%30 = icmp eq i8* %14, null
br i1 %30, label %34, label %31
31: ; preds = %22
%32 = load i8, i8* %14
switch i8 %32, label %60 [
i8 0, label %34
i8 126, label %33
]
33: ; preds = %31
br label %34
34: ; preds = %31, %33, %22
%35 = 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), %31 ], [ %14, %33 ]
br i1 %12, label %36, label %41
36: ; preds = %34
%37 = getelementptr inbounds %struct.passwd, %struct.passwd* %16, i64 0, i32 1
%38 = load i8*, i8** %37
%39 = icmp eq i8* %38, null
%40 = select i1 %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %38
br label %43
41: ; preds = %34
%42 = icmp eq i8* %11, null
br i1 %42, label %47, label %43
43: ; preds = %36, %41
%44 = phi i8* [ %11, %41 ], [ %40, %36 ]
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43, %41
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i64 0, i64 0))
br label %169
50: ; preds = %43
%51 = call i32 @strlen(i8* %44)
%52 = icmp sgt i32 %51, 3996
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
br label %169
56: ; preds = %50
%57 = getelementptr inbounds i8, i8* %35, i64 1
%58 = call i32 @strncpy(i8* %7, i8* %44, i32 4096)
%59 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 4096
store i8 0, i8* %59
br label %60
60: ; preds = %31, %56
%61 = phi i8* [ %57, %56 ], [ %14, %31 ]
%62 = call i32 @strlen(i8* %7)
%63 = sub nsw i32 4096, %62
%64 = call i32 @strncat(i8* %7, i8* %61, i32 %63)
%65 = call i32 @strlen(i8* %7)
%66 = add nsw i32 %65, -1
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %67
%69 = load i8, i8* %68
%70 = icmp eq i8 %69, 47
br i1 %70, label %71, label %76
71: ; preds = %60
%72 = call i32 @strlen(i8* %7)
%73 = add nsw i32 %72, -1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %71, %60
%77 = call i32 @stat(i8* %7, %struct.stat* %6)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %88
79: ; preds = %76
%80 = load i64, i64* @errno
%81 = load i64, i64* @ENOENT
%82 = icmp eq i64 %80, %81
br i1 %82, label %83, label %86
83: ; preds = %79
%84 = call i32 @mkdir(i8* %7, i32 448)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %88
86: ; preds = %79, %83
%87 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
br label %169
88: ; preds = %76, %83
%89 = call i32 @strlen(i8* %7)
%90 = sub nsw i32 4096, %89
%91 = call i32 @strncat(i8* %7, i8* %1, i32 %90)
%92 = call i32 @strlen(i8* %7)
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 %93
%95 = call i32 @strlen(i8* %7)
%96 = sub i32 4095, %95
%97 = call i64 @gethostname(i8* %94, i32 %96)
%98 = icmp eq i64 %97, 0
br i1 %98, label %102, label %99
99: ; preds = %88
%100 = call i32 @perror(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.9, i64 0, i64 0))
%101 = call i32 @exit(i32 255)
unreachable
102: ; preds = %88
%103 = getelementptr inbounds [4097 x i8], [4097 x i8]* %3, i64 0, i64 4096
store i8 0, i8* %103
%104 = call i32 @lstat(i8* %7, %struct.stat* %6)
switch i32 %104, label %105 [
i32 0, label %108
i32 -1, label %113
]
105: ; preds = %102
%106 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%107 = load i32, i32* %106
br label %127
108: ; preds = %102
%109 = getelementptr inbounds %struct.stat, %struct.stat* %6, i64 0, i32 0
%110 = load i32, i32* %109
%111 = call i64 @S_ISDIR(i32 %110)
%112 = icmp eq i64 %111, 0
br i1 %112, label %127, label %169
113: ; preds = %102
%114 = load i64, i64* @errno
%115 = load i64, i64* @ENOENT
%116 = icmp eq i64 %114, %115
br i1 %116, label %117, label %131
117: ; preds = %113
%118 = call i32 @create_link(i8* %7, i8* %8)
%119 = icmp eq i32 %118, 0
br i1 %119, label %169, label %120
120: ; preds = %117
%121 = call i32 @unlink(i8* %7)
%122 = call i32 @strlen(i8* %8)
%123 = sub nsw i32 4096, %122
%124 = call i32 @strncat(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %123)
%125 = call i32 @mktemp(i8* %8)
%126 = call i32 @create_link(i8* %7, i8* %8)
br label %169
127: ; preds = %105, %108
%128 = phi i32 [ %107, %105 ], [ %110, %108 ]
%129 = call i32 @S_ISLNK(i32 %128)
%130 = icmp eq i32 %129, 0
br i1 %130, label %131, label %134
131: ; preds = %113, %127
%132 = load i32, i32* @stderr
%133 = call i32 (i32, i8*, ...) @fprintf(i32 %132, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.11, i64 0, i64 0), i8* %7)
br label %169
134: ; preds = %127
%135 = call i32 @readlink(i8* %7, i8* %9, i32 4096)
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %140
137: ; preds = %134
%138 = load i32, i32* @stderr
%139 = call i32 (i32, i8*, ...) @fprintf(i32 %138, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i8* %7)
br label %169
140: ; preds = %134
%141 = sext i32 %135 to i64
%142 = getelementptr inbounds [4097 x i8], [4097 x i8]* %5, i64 0, i64 %141
store i8 0, i8* %142
%143 = call i32 @strlen(i8* %8)
%144 = call i64 @strncmp(i8* %9, i8* %8, i32 %143)
%145 = icmp eq i64 %144, 0
br i1 %145, label %159, label %146
146: ; preds = %140
%147 = load i32, i32* @stderr
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %147, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.13, i64 0, i64 0), i8* %7, i8* %9, i8* %8)
%149 = call i32 @unlink(i8* %7)
%150 = call i32 @create_link(i8* %7, i8* %8)
%151 = icmp eq i32 %150, 0
br i1 %151, label %169, label %152
152: ; preds = %146
%153 = call i32 @unlink(i8* %7)
%154 = call i32 @strlen(i8* %8)
%155 = sub nsw i32 4096, %154
%156 = call i32 @strncat(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %155)
%157 = call i32 @mktemp(i8* %8)
%158 = call i32 @create_link(i8* %7, i8* %8)
br label %169
159: ; preds = %140
%160 = call i32 @check_tmp_dir(i8* %9)
%161 = icmp eq i32 %160, 0
br i1 %161, label %169, label %162
162: ; preds = %159
%163 = call i32 @unlink(i8* %7)
%164 = call i32 @strlen(i8* %8)
%165 = sub nsw i32 4096, %164
%166 = call i32 @strncat(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i32 %165)
%167 = call i32 @mktemp(i8* %8)
%168 = call i32 @create_link(i8* %7, i8* %8)
br label %169
169: ; preds = %159, %146, %117, %108, %162, %152, %137, %131, %120, %86, %53, %47, %18
%170 = phi i32 [ 1, %53 ], [ 1, %86 ], [ %126, %120 ], [ 1, %131 ], [ 1, %137 ], [ %158, %152 ], [ %168, %162 ], [ 1, %47 ], [ 1, %18 ], [ 0, %108 ], [ 0, %117 ], [ 0, %146 ], [ 0, %159 ]
ret i32 %170
}