#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 */
typedef int /*<<< orphan*/ uid_t;
struct stat {
  int st_mode;
};
typedef int ssize_t;

/* Variables and functions */
int S_IFDIR;
int S_IFLNK;
int S_IFMT;
int S_IFREG;
int chmod(char *, int);
int /*<<< orphan*/ close(int);
char *dirname(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int full_write(int, char *, size_t);
int lgetxattr(char *, char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int local_set_xattr(char *, struct stat *);
int lstat(char *, struct stat *);
scalar_t__ malloc(size_t);
int mkstemp(char *);
int /*<<< orphan*/ perror(char *);
char *readlink_alloc(char *, size_t *);
int rename(char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
int strlen(char *);
void convert(char *path) {
  ssize_t rv;
  struct stat s;
  rv = lgetxattr(path, "user.virtfs.uid", NULL, 0);
  if (rv == sizeof(uid_t)) {
    fprintf(stderr, "Already converted: %s\n", path);
    return;
  }
  rv = lstat(path, &s);
  if (rv == -1) {
    fprintf(stderr, "File: %s: ", path);
    perror("lstat");
    exit(1);
  }
  if ((s.st_mode & S_IFMT) == S_IFLNK) {
    ssize_t rv;
    size_t len;
    char *link = readlink_alloc(path, &len);
    char *abs_tmpfile;
    {
      char *tmpfile_tpl = "virtfs-convert.tmpXXXXXXXXXX";
      char *t = strdup(path);
      char *dir = dirname(t);
      size_t len = strlen(dir) + strlen(tmpfile_tpl) + 2;
      abs_tmpfile = (char *)malloc(len);
      abs_tmpfile[0] = '\0';
      strcat(abs_tmpfile, dir);
      strcat(abs_tmpfile, "/");
      strcat(abs_tmpfile, tmpfile_tpl);
      free(t);
    }
    int fd = mkstemp(abs_tmpfile);
    if (fd < 0) {
      perror("mkstemp");
      exit(1);
    }
    rv = full_write(fd, link, len);
    if (rv != 0) {
      perror("write");
      exit(1);
    }
    free(link);
    close(fd);
    rv = local_set_xattr(abs_tmpfile, &s);
    if (rv != 0) {
      fprintf(stderr, "File: %s: ", path);
      perror("setxattr");
      exit(1);
    }
    rv = rename(abs_tmpfile, path);
    if (rv < 0) {
      perror("rename");
      exit(1);
    }
  } else if ((s.st_mode & S_IFMT) == S_IFREG ||
             (s.st_mode & S_IFMT) == S_IFDIR) {
    if ((s.st_mode & S_IFMT) == S_IFREG)
      rv = chmod(path, 0600);
    else
      rv = chmod(path, 0700);
    if (rv < 0) {
      perror("chmod");
      exit(1);
    }
    rv = local_set_xattr(path, &s);
    if (rv != 0) {
      fprintf(stderr, "File: %s: ", path);
      perror("setxattr");
      exit(1);
    }
  } else {
    fprintf(stderr, "Warning: Unsupported file type: %s\n", path);
    return;
  }
}


x86 assembly (clang, -O0):
<convert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xdc9(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <lgetxattr@plt>
mov    %eax,-0xc(%rbp)
movslq -0xc(%rbp),%rax
cmp    $0x4,%rax
jne    1271 <convert+0x51>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xda9(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    156e <convert+0x34e>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10a0 <lstat@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    12ba <convert+0x9a>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xd88(%rip),%rsi
call   10b0 <fprintf@plt>
lea    0xd87(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%eax
mov    0x2d0c(%rip),%rcx
and    (%rcx),%eax
mov    0x2d13(%rip),%rcx
cmp    (%rcx),%eax
jne    1465 <convert+0x245>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <readlink_alloc@plt>
mov    %rax,-0x28(%rbp)
lea    0xd4b(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1140 <strdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
call   1070 <dirname@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x58(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x58(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
call   10c0 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1120 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    0xcf9(%rip),%rsi
call   1120 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1120 <strcat@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   10e0 <mkstemp@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    13a3 <convert+0x183>
lea    0xcc3(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x54(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   10d0 <full_write@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     13d6 <convert+0x1b6>
lea    0xc98(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
mov    -0x30(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1090 <local_set_xattr@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1430 <convert+0x210>
mov    0x2bc0(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xc12(%rip),%rsi
call   10b0 <fprintf@plt>
lea    0xc44(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1110 <rename@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1460 <convert+0x240>
lea    0xc1d(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    156e <convert+0x34e>
mov    -0x10(%rbp),%eax
mov    0x2b61(%rip),%rcx
and    (%rcx),%eax
mov    0x2b70(%rip),%rcx
cmp    (%rcx),%eax
je     149b <convert+0x27b>
mov    -0x10(%rbp),%eax
mov    0x2b46(%rip),%rcx
and    (%rcx),%eax
mov    0x2b25(%rip),%rcx
cmp    (%rcx),%eax
jne    154b <convert+0x32b>
mov    -0x10(%rbp),%eax
mov    0x2b2b(%rip),%rcx
and    (%rcx),%eax
mov    0x2b3a(%rip),%rcx
cmp    (%rcx),%eax
jne    14cc <convert+0x2ac>
mov    -0x8(%rbp),%rdi
mov    $0x180,%esi
call   10f0 <chmod@plt>
mov    %eax,-0xc(%rbp)
jmp    14dd <convert+0x2bd>
mov    -0x8(%rbp),%rdi
mov    $0x1c0,%esi
call   10f0 <chmod@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    14fd <convert+0x2dd>
lea    0xb87(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   1090 <local_set_xattr@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1546 <convert+0x326>
mov    0x2aaa(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xafc(%rip),%rsi
call   10b0 <fprintf@plt>
lea    0xb2e(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    1569 <convert+0x349>
mov    0x2a76(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb1c(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    156e <convert+0x34e>
jmp    156e <convert+0x34e>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<convert>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
lea    0xdc8(%rip),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <lgetxattr@plt>
cmp    $0x4,%eax
jne    126c <convert+0x4c>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
mov    %r15,%rdx
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <fprintf@plt>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   10a0 <lstat@plt>
cmp    $0xffffffff,%eax
je     13ec <convert+0x1cc>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2d4a(%rip),%rcx
cmp    (%rcx),%eax
jne    1385 <convert+0x165>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
call   1040 <readlink_alloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1140 <strdup@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1070 <dirname@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
lea    0xd63(%rip),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rdi
call   10c0 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %rbp,%rsi
call   1120 <strcat@plt>
lea    0xd53(%rip),%rsi
mov    %rbx,%rdi
call   1120 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1120 <strcat@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   10e0 <mkstemp@plt>
test   %eax,%eax
js     142e <convert+0x20e>
mov    %eax,%ebp
mov    0x10(%rsp),%rdx
mov    %eax,%edi
mov    %r14,%rsi
call   10d0 <full_write@plt>
test   %eax,%eax
jne    1437 <convert+0x217>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1080 <close@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1090 <local_set_xattr@plt>
test   %eax,%eax
jne    140d <convert+0x1ed>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1110 <rename@plt>
test   %eax,%eax
jns    13dd <convert+0x1bd>
lea    0xcee(%rip),%rdi
jmp    1447 <convert+0x227>
mov    0x2c5c(%rip),%rcx
mov    (%rcx),%ecx
cmp    %ecx,%eax
je     13b2 <convert+0x192>
mov    0x2c1f(%rip),%rdx
cmp    (%rdx),%eax
je     13b2 <convert+0x192>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xcce(%rip),%rsi
jmp    1256 <convert+0x36>
xor    %esi,%esi
cmp    %ecx,%eax
setne  %sil
or     $0x6,%esi
shl    $0x6,%esi
mov    %r15,%rdi
call   10f0 <chmod@plt>
test   %eax,%eax
js     1440 <convert+0x220>
lea    0x8(%rsp),%rsi
mov    %r15,%rdi
call   1090 <local_set_xattr@plt>
test   %eax,%eax
jne    140d <convert+0x1ed>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bd5(%rip),%rax
mov    (%rax),%edi
lea    0xc2b(%rip),%rsi
mov    %r15,%rdx
call   10b0 <fprintf@plt>
lea    0xc27(%rip),%rdi
jmp    1447 <convert+0x227>
mov    0x2bb4(%rip),%rax
mov    (%rax),%edi
lea    0xc0a(%rip),%rsi
mov    %r15,%rdx
call   10b0 <fprintf@plt>
lea    0xc39(%rip),%rdi
jmp    1447 <convert+0x227>
lea    0xc22(%rip),%rdi
jmp    1447 <convert+0x227>
lea    0xc21(%rip),%rdi
jmp    1447 <convert+0x227>
lea    0xc2e(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [16 x i8] c"user.virtfs.uid\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Already converted: %s\0A\00"
@.str.2 = [11 x i8] c"File: %s: \00"
@.str.3 = [6 x i8] c"lstat\00"
@S_IFMT = global i32 0
@S_IFLNK = global i32 0
@.str.4 = [29 x i8] c"virtfs-convert.tmpXXXXXXXXXX\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [8 x i8] c"mkstemp\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [9 x i8] c"setxattr\00"
@.str.9 = [7 x i8] c"rename\00"
@S_IFREG = global i32 0
@S_IFDIR = global i32 0
@.str.10 = [6 x i8] c"chmod\00"
@.str.11 = [36 x i8] c"Warning: Unsupported file type: %s\0A\00"
define void @convert(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.stat
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
store i8* %0, i8** %2
%14 = load i8*, i8** %2
%15 = call i32 @lgetxattr(i8* %14, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* null, i32 0)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = icmp eq i64 %17, 4
br i1 %18, label %19, label %23
19: ; preds = %1
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %2
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %162
23: ; preds = %1
%24 = load i8*, i8** %2
%25 = call i32 @lstat(i8* %24, %struct.stat* %4)
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %34
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %2
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%33 = call i32 @exit(i32 1)
unreachable
34: ; preds = %23
%35 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%36 = load i32, i32* %35
%37 = load i32, i32* @S_IFMT
%38 = and i32 %36, %37
%39 = load i32, i32* @S_IFLNK
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %112
41: ; preds = %34
%42 = load i8*, i8** %2
%43 = call i8* @readlink_alloc(i8* %42, i64* %6)
store i8* %43, i8** %7
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8** %9
%44 = load i8*, i8** %2
%45 = call i8* @strdup(i8* %44)
store i8* %45, i8** %10
%46 = load i8*, i8** %10
%47 = call i8* @dirname(i8* %46)
store i8* %47, i8** %11
%48 = load i8*, i8** %11
%49 = call i32 @strlen(i8* %48)
%50 = load i8*, i8** %9
%51 = call i32 @strlen(i8* %50)
%52 = add nsw i32 %49, %51
%53 = add nsw i32 %52, 2
%54 = sext i32 %53 to i64
store i64 %54, i64* %12
%55 = load i64, i64* %12
%56 = call i64 @malloc(i64 %55)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %8
%58 = load i8*, i8** %8
%59 = getelementptr inbounds i8, i8* %58, i64 0
store i8 0, i8* %59
%60 = load i8*, i8** %8
%61 = load i8*, i8** %11
%62 = call i32 @strcat(i8* %60, i8* %61)
%63 = load i8*, i8** %8
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%65 = load i8*, i8** %8
%66 = load i8*, i8** %9
%67 = call i32 @strcat(i8* %65, i8* %66)
%68 = load i8*, i8** %10
%69 = call i32 @free(i8* %68)
%70 = load i8*, i8** %8
%71 = call i32 @mkstemp(i8* %70)
store i32 %71, i32* %13
%72 = load i32, i32* %13
%73 = icmp slt i32 %72, 0
br i1 %73, label %74, label %77
74: ; preds = %41
%75 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %41
%78 = load i32, i32* %13
%79 = load i8*, i8** %7
%80 = load i64, i64* %6
%81 = call i32 @full_write(i32 %78, i8* %79, i64 %80)
store i32 %81, i32* %5
%82 = load i32, i32* %5
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %77
%85 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %77
%88 = load i8*, i8** %7
%89 = call i32 @free(i8* %88)
%90 = load i32, i32* %13
%91 = call i32 @close(i32 %90)
%92 = load i8*, i8** %8
%93 = call i32 @local_set_xattr(i8* %92, %struct.stat* %4)
store i32 %93, i32* %5
%94 = load i32, i32* %5
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %102
96: ; preds = %87
%97 = load i32, i32* @stderr
%98 = load i8*, i8** %2
%99 = call i32 @fprintf(i32 %97, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %98)
%100 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %87
%103 = load i8*, i8** %8
%104 = load i8*, i8** %2
%105 = call i32 @rename(i8* %103, i8* %104)
store i32 %105, i32* %5
%106 = load i32, i32* %5
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %102
%109 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %102
br label %162
112: ; preds = %34
%113 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%114 = load i32, i32* %113
%115 = load i32, i32* @S_IFMT
%116 = and i32 %114, %115
%117 = load i32, i32* @S_IFREG
%118 = icmp eq i32 %116, %117
br i1 %118, label %126, label %119
119: ; preds = %112
%120 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%121 = load i32, i32* %120
%122 = load i32, i32* @S_IFMT
%123 = and i32 %121, %122
%124 = load i32, i32* @S_IFDIR
%125 = icmp eq i32 %123, %124
br i1 %125, label %126, label %157
126: ; preds = %119, %112
%127 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%128 = load i32, i32* %127
%129 = load i32, i32* @S_IFMT
%130 = and i32 %128, %129
%131 = load i32, i32* @S_IFREG
%132 = icmp eq i32 %130, %131
br i1 %132, label %133, label %136
133: ; preds = %126
%134 = load i8*, i8** %2
%135 = call i32 @chmod(i8* %134, i32 384)
store i32 %135, i32* %3
br label %139
136: ; preds = %126
%137 = load i8*, i8** %2
%138 = call i32 @chmod(i8* %137, i32 448)
store i32 %138, i32* %3
br label %139
139: ; preds = %136, %133
%140 = load i32, i32* %3
%141 = icmp slt i32 %140, 0
br i1 %141, label %142, label %145
142: ; preds = %139
%143 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%144 = call i32 @exit(i32 1)
unreachable
145: ; preds = %139
%146 = load i8*, i8** %2
%147 = call i32 @local_set_xattr(i8* %146, %struct.stat* %4)
store i32 %147, i32* %3
%148 = load i32, i32* %3
%149 = icmp ne i32 %148, 0
br i1 %149, label %150, label %156
150: ; preds = %145
%151 = load i32, i32* @stderr
%152 = load i8*, i8** %2
%153 = call i32 @fprintf(i32 %151, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %152)
%154 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%155 = call i32 @exit(i32 1)
unreachable
156: ; preds = %145
br label %161
157: ; preds = %119
%158 = load i32, i32* @stderr
%159 = load i8*, i8** %2
%160 = call i32 @fprintf(i32 %158, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i8* %159)
br label %162
161: ; preds = %156
br label %162
162: ; preds = %19, %157, %161, %111
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [16 x i8] c"user.virtfs.uid\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Already converted: %s\0A\00"
@.str.2 = [11 x i8] c"File: %s: \00"
@.str.3 = [6 x i8] c"lstat\00"
@S_IFMT = global i32 0
@S_IFLNK = global i32 0
@.str.4 = [29 x i8] c"virtfs-convert.tmpXXXXXXXXXX\00"
@.str.5 = [2 x i8] c"/\00"
@.str.6 = [8 x i8] c"mkstemp\00"
@.str.7 = [6 x i8] c"write\00"
@.str.8 = [9 x i8] c"setxattr\00"
@.str.9 = [7 x i8] c"rename\00"
@S_IFREG = global i32 0
@S_IFDIR = global i32 0
@.str.10 = [6 x i8] c"chmod\00"
@.str.11 = [36 x i8] c"Warning: Unsupported file type: %s\0A\00"
define void @convert(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i64
%4 = bitcast %struct.stat* %2 to i8*
%5 = tail call i32 @lgetxattr(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32* null, i32 0)
%6 = icmp eq i32 %5, 4
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %94
10: ; preds = %1
%11 = call i32 @lstat(i8* %0, %struct.stat* %2)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%16 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%20 = load i32, i32* %19
%21 = load i32, i32* @S_IFMT
%22 = and i32 %21, %20
%23 = load i32, i32* @S_IFLNK
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %70
25: ; preds = %18
%26 = bitcast i64* %3 to i8*
%27 = call i8* @readlink_alloc(i8* %0, i64* %3)
%28 = call i8* @strdup(i8* %0)
%29 = call i8* @dirname(i8* %28)
%30 = call i32 @strlen(i8* %29)
%31 = call i32 @strlen(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%32 = add i32 %30, 2
%33 = add i32 %32, %31
%34 = sext i32 %33 to i64
%35 = call i64 @malloc(i64 %34)
%36 = inttoptr i64 %35 to i8*
store i8 0, i8* %36
%37 = call i32 @strcat(i8* %36, i8* %29)
%38 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%39 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%40 = call i32 @free(i8* %28)
%41 = call i32 @mkstemp(i8* %36)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %25
%44 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %25
%47 = load i64, i64* %3
%48 = call i32 @full_write(i32 %41, i8* %27, i64 %47)
%49 = icmp eq i32 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %46
%54 = call i32 @free(i8* %27)
%55 = call i32 @close(i32 %41)
%56 = call i32 @local_set_xattr(i8* %36, %struct.stat* %2)
%57 = icmp eq i32 %56, 0
br i1 %57, label %63, label %58
58: ; preds = %53
%59 = load i32, i32* @stderr
%60 = call i32 @fprintf(i32 %59, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%61 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %53
%64 = call i32 @rename(i8* %36, i8* %0)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %63
br label %94
70: ; preds = %18
%71 = load i32, i32* @S_IFREG
%72 = icmp eq i32 %22, %71
%73 = load i32, i32* @S_IFDIR
%74 = icmp eq i32 %22, %73
%75 = select i1 %72, i1 true, i1 %74
br i1 %75, label %76, label %91
76: ; preds = %70
%77 = select i1 %72, i32 384, i32 448
%78 = tail call i32 @chmod(i8* %0, i32 %77)
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %83
80: ; preds = %76
%81 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.10, i64 0, i64 0))
%82 = tail call i32 @exit(i32 1)
unreachable
83: ; preds = %76
%84 = call i32 @local_set_xattr(i8* %0, %struct.stat* %2)
%85 = icmp eq i32 %84, 0
br i1 %85, label %94, label %86
86: ; preds = %83
%87 = load i32, i32* @stderr
%88 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%89 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %70
%92 = load i32, i32* @stderr
%93 = tail call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.11, i64 0, i64 0), i8* %0)
br label %94
94: ; preds = %69, %83, %91, %7
ret void
}