#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 mode_t;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISREG(int);
scalar_t__ S_ISSOCK(int);
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ sprintf(char *, char *, char *);
void print_perms(mode_t st, char buf[1024]) {
  char perms[11];
  if (st && S_ISREG(st))
    perms[0] = '-';
  else if (st && S_ISDIR(st))
    perms[0] = 'd';
  else if (st && S_ISFIFO(st))
    perms[0] = '|';
  else if (st && S_ISSOCK(st))
    perms[0] = 's';
  else if (st && S_ISCHR(st))
    perms[0] = 'c';
  else if (st && S_ISBLK(st))
    perms[0] = 'b';
  else
    perms[0] = 'l';
  perms[1] = (st & S_IRUSR) ? 'r' : '-';
  perms[2] = (st & S_IWUSR) ? 'w' : '-';
  perms[3] = (st & S_IXUSR) ? 'x' : '-';
  perms[4] = (st & S_IRGRP) ? 'r' : '-';
  perms[5] = (st & S_IWGRP) ? 'w' : '-';
  perms[6] = (st & S_IXGRP) ? 'x' : '-';
  perms[7] = (st & S_IROTH) ? 'r' : '-';
  perms[8] = (st & S_IWOTH) ? 'w' : '-';
  perms[9] = (st & S_IXOTH) ? 'x' : '-';
  perms[10] = '\0';
  sprintf(buf, "%s", perms);
}


x86 assembly (clang, -O0):
<print_perms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11a4 <print_perms+0x34>
mov    -0x4(%rbp),%edi
call   1060 <S_ISREG@plt>
cmp    $0x0,%rax
je     11a4 <print_perms+0x34>
movb   $0x2d,-0x1b(%rbp)
jmp    127a <print_perms+0x10a>
cmpl   $0x0,-0x4(%rbp)
je     11c9 <print_perms+0x59>
mov    -0x4(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     11c9 <print_perms+0x59>
movb   $0x64,-0x1b(%rbp)
jmp    1275 <print_perms+0x105>
cmpl   $0x0,-0x4(%rbp)
je     11ee <print_perms+0x7e>
mov    -0x4(%rbp),%edi
call   1030 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     11ee <print_perms+0x7e>
movb   $0x7c,-0x1b(%rbp)
jmp    1270 <print_perms+0x100>
cmpl   $0x0,-0x4(%rbp)
je     1213 <print_perms+0xa3>
mov    -0x4(%rbp),%edi
call   1040 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     1213 <print_perms+0xa3>
movb   $0x73,-0x1b(%rbp)
jmp    126b <print_perms+0xfb>
cmpl   $0x0,-0x4(%rbp)
je     1238 <print_perms+0xc8>
mov    -0x4(%rbp),%edi
call   1070 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1238 <print_perms+0xc8>
movb   $0x63,-0x1b(%rbp)
jmp    1266 <print_perms+0xf6>
cmpl   $0x0,-0x4(%rbp)
je     125d <print_perms+0xed>
mov    -0x4(%rbp),%edi
call   1080 <S_ISBLK@plt>
cmp    $0x0,%rax
je     125d <print_perms+0xed>
movb   $0x62,-0x1b(%rbp)
jmp    1261 <print_perms+0xf1>
movb   $0x6c,-0x1b(%rbp)
jmp    1266 <print_perms+0xf6>
jmp    126b <print_perms+0xfb>
jmp    1270 <print_perms+0x100>
jmp    1275 <print_perms+0x105>
jmp    127a <print_perms+0x10a>
mov    -0x4(%rbp),%edx
mov    0x2d24(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x1a(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2d2d(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x19(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2d1e(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x18(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2cd7(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x17(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2cd8(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x16(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2ca9(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x15(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2c72(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x14(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2c3b(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x13(%rbp)
mov    -0x4(%rbp),%edx
mov    0x2c6c(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,-0x12(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x1b(%rbp),%rdx
lea    0xc5c(%rip),%rsi
call   1090 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_perms>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
test   %edi,%edi
je     11f1 <print_perms+0x81>
mov    %ebp,%edi
call   1070 <S_ISREG@plt>
test   %rax,%rax
je     1192 <print_perms+0x22>
movb   $0x2d,0xd(%rsp)
jmp    11f6 <print_perms+0x86>
mov    %ebp,%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     11a5 <print_perms+0x35>
movb   $0x64,0xd(%rsp)
jmp    11f6 <print_perms+0x86>
mov    %ebp,%edi
call   1040 <S_ISFIFO@plt>
test   %rax,%rax
je     11b8 <print_perms+0x48>
movb   $0x7c,0xd(%rsp)
jmp    11f6 <print_perms+0x86>
mov    %ebp,%edi
call   1050 <S_ISSOCK@plt>
test   %rax,%rax
je     11cb <print_perms+0x5b>
movb   $0x73,0xd(%rsp)
jmp    11f6 <print_perms+0x86>
mov    %ebp,%edi
call   1080 <S_ISCHR@plt>
test   %rax,%rax
je     11de <print_perms+0x6e>
movb   $0x63,0xd(%rsp)
jmp    11f6 <print_perms+0x86>
mov    %ebp,%edi
call   1090 <S_ISBLK@plt>
test   %rax,%rax
je     11f1 <print_perms+0x81>
movb   $0x62,0xd(%rsp)
jmp    11f6 <print_perms+0x86>
movb   $0x6c,0xd(%rsp)
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
and    %ebp,%eax
mov    $0x2d,%eax
mov    $0x72,%ecx
mov    $0x72,%edx
cmove  %eax,%edx
mov    %dl,0xe(%rsp)
mov    0x2db2(%rip),%rdx
mov    (%rdx),%edx
and    %ebp,%edx
mov    $0x77,%edx
mov    $0x77,%esi
cmove  %eax,%esi
mov    %sil,0xf(%rsp)
mov    0x2da5(%rip),%rsi
mov    (%rsi),%esi
and    %ebp,%esi
mov    $0x78,%esi
cmove  %eax,%esi
mov    0x2d6a(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
mov    $0x72,%edi
cmove  %eax,%edi
mov    %sil,0x10(%rsp)
mov    %dil,0x11(%rsp)
mov    0x2d6d(%rip),%rsi
mov    (%rsi),%esi
and    %ebp,%esi
mov    $0x77,%edi
cmove  %eax,%edi
mov    $0x78,%esi
mov    %dil,0x12(%rsp)
mov    0x2d40(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
mov    $0x78,%edi
cmove  %eax,%edi
mov    %dil,0x13(%rsp)
mov    0x2d10(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
cmove  %eax,%ecx
mov    %cl,0x14(%rsp)
mov    0x2ce6(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
cmove  %eax,%edx
mov    %dl,0x15(%rsp)
mov    0x2d24(%rip),%rcx
and    (%rcx),%ebp
cmove  %eax,%esi
mov    %sil,0x16(%rsp)
movb   $0x0,0x17(%rsp)
lea    0xd(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
@.str = [3 x i8] c"%s\00"
define void @print_perms(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [11 x i8]
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* %3
%10 = call i64 @S_ISREG(i32 %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 45, i8* %13
br label %66
14: ; preds = %8, %2
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* %3
%19 = call i64 @S_ISDIR(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 100, i8* %22
br label %65
23: ; preds = %17, %14
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i32, i32* %3
%28 = call i64 @S_ISFIFO(i32 %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 124, i8* %31
br label %64
32: ; preds = %26, %23
%33 = load i32, i32* %3
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load i32, i32* %3
%37 = call i64 @S_ISSOCK(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 115, i8* %40
br label %63
41: ; preds = %35, %32
%42 = load i32, i32* %3
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load i32, i32* %3
%46 = call i64 @S_ISCHR(i32 %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 99, i8* %49
br label %62
50: ; preds = %44, %41
%51 = load i32, i32* %3
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i32, i32* %3
%55 = call i64 @S_ISBLK(i32 %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 98, i8* %58
br label %61
59: ; preds = %53, %50
%60 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
store i8 108, i8* %60
br label %61
61: ; preds = %59, %57
br label %62
62: ; preds = %61, %48
br label %63
63: ; preds = %62, %39
br label %64
64: ; preds = %63, %30
br label %65
65: ; preds = %64, %21
br label %66
66: ; preds = %65, %12
%67 = load i32, i32* %3
%68 = load i32, i32* @S_IRUSR
%69 = and i32 %67, %68
%70 = icmp ne i32 %69, 0
%71 = zext i1 %70 to i64
%72 = select i1 %70, i32 114, i32 45
%73 = trunc i32 %72 to i8
%74 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 1
store i8 %73, i8* %74
%75 = load i32, i32* %3
%76 = load i32, i32* @S_IWUSR
%77 = and i32 %75, %76
%78 = icmp ne i32 %77, 0
%79 = zext i1 %78 to i64
%80 = select i1 %78, i32 119, i32 45
%81 = trunc i32 %80 to i8
%82 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 2
store i8 %81, i8* %82
%83 = load i32, i32* %3
%84 = load i32, i32* @S_IXUSR
%85 = and i32 %83, %84
%86 = icmp ne i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i32 120, i32 45
%89 = trunc i32 %88 to i8
%90 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 3
store i8 %89, i8* %90
%91 = load i32, i32* %3
%92 = load i32, i32* @S_IRGRP
%93 = and i32 %91, %92
%94 = icmp ne i32 %93, 0
%95 = zext i1 %94 to i64
%96 = select i1 %94, i32 114, i32 45
%97 = trunc i32 %96 to i8
%98 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 4
store i8 %97, i8* %98
%99 = load i32, i32* %3
%100 = load i32, i32* @S_IWGRP
%101 = and i32 %99, %100
%102 = icmp ne i32 %101, 0
%103 = zext i1 %102 to i64
%104 = select i1 %102, i32 119, i32 45
%105 = trunc i32 %104 to i8
%106 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 5
store i8 %105, i8* %106
%107 = load i32, i32* %3
%108 = load i32, i32* @S_IXGRP
%109 = and i32 %107, %108
%110 = icmp ne i32 %109, 0
%111 = zext i1 %110 to i64
%112 = select i1 %110, i32 120, i32 45
%113 = trunc i32 %112 to i8
%114 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 6
store i8 %113, i8* %114
%115 = load i32, i32* %3
%116 = load i32, i32* @S_IROTH
%117 = and i32 %115, %116
%118 = icmp ne i32 %117, 0
%119 = zext i1 %118 to i64
%120 = select i1 %118, i32 114, i32 45
%121 = trunc i32 %120 to i8
%122 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 7
store i8 %121, i8* %122
%123 = load i32, i32* %3
%124 = load i32, i32* @S_IWOTH
%125 = and i32 %123, %124
%126 = icmp ne i32 %125, 0
%127 = zext i1 %126 to i64
%128 = select i1 %126, i32 119, i32 45
%129 = trunc i32 %128 to i8
%130 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 8
store i8 %129, i8* %130
%131 = load i32, i32* %3
%132 = load i32, i32* @S_IXOTH
%133 = and i32 %131, %132
%134 = icmp ne i32 %133, 0
%135 = zext i1 %134 to i64
%136 = select i1 %134, i32 120, i32 45
%137 = trunc i32 %136 to i8
%138 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 9
store i8 %137, i8* %138
%139 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 10
store i8 0, i8* %139
%140 = load i8*, i8** %4
%141 = getelementptr inbounds [11 x i8], [11 x i8]* %5, i64 0, i64 0
%142 = call i32 @sprintf(i8* %140, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %141)
ret void
}

LLVM IR (-O2):
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IXUSR = global i32 0
@S_IRGRP = global i32 0
@S_IWGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IWOTH = global i32 0
@S_IXOTH = global i32 0
define void @print_perms(i32 %0, i8* %1) {
%3 = alloca [11 x i8]
%4 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 0
br i1 %5, label %30, label %6
6: ; preds = %2
%7 = tail call i64 @S_ISREG(i32 %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %10, label %9
9: ; preds = %6
store i8 45, i8* %4
br label %31
10: ; preds = %6
%11 = tail call i64 @S_ISDIR(i32 %0)
%12 = icmp eq i64 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10
store i8 100, i8* %4
br label %31
14: ; preds = %10
%15 = tail call i64 @S_ISFIFO(i32 %0)
%16 = icmp eq i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %14
store i8 124, i8* %4
br label %31
18: ; preds = %14
%19 = tail call i64 @S_ISSOCK(i32 %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %22, label %21
21: ; preds = %18
store i8 115, i8* %4
br label %31
22: ; preds = %18
%23 = tail call i64 @S_ISCHR(i32 %0)
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22
store i8 99, i8* %4
br label %31
26: ; preds = %22
%27 = tail call i64 @S_ISBLK(i32 %0)
%28 = icmp eq i64 %27, 0
br i1 %28, label %30, label %29
29: ; preds = %26
store i8 98, i8* %4
br label %31
30: ; preds = %2, %26
store i8 108, i8* %4
br label %31
31: ; preds = %13, %21, %29, %30, %25, %17, %9
%32 = load i32, i32* @S_IRUSR
%33 = and i32 %32, %0
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i8 45, i8 114
%36 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 1
store i8 %35, i8* %36
%37 = load i32, i32* @S_IWUSR
%38 = and i32 %37, %0
%39 = icmp eq i32 %38, 0
%40 = select i1 %39, i8 45, i8 119
%41 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 2
store i8 %40, i8* %41
%42 = load i32, i32* @S_IXUSR
%43 = and i32 %42, %0
%44 = icmp eq i32 %43, 0
%45 = select i1 %44, i8 45, i8 120
%46 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 3
store i8 %45, i8* %46
%47 = load i32, i32* @S_IRGRP
%48 = and i32 %47, %0
%49 = icmp eq i32 %48, 0
%50 = select i1 %49, i8 45, i8 114
%51 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 4
store i8 %50, i8* %51
%52 = load i32, i32* @S_IWGRP
%53 = and i32 %52, %0
%54 = icmp eq i32 %53, 0
%55 = select i1 %54, i8 45, i8 119
%56 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 5
store i8 %55, i8* %56
%57 = load i32, i32* @S_IXGRP
%58 = and i32 %57, %0
%59 = icmp eq i32 %58, 0
%60 = select i1 %59, i8 45, i8 120
%61 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 6
store i8 %60, i8* %61
%62 = load i32, i32* @S_IROTH
%63 = and i32 %62, %0
%64 = icmp eq i32 %63, 0
%65 = select i1 %64, i8 45, i8 114
%66 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 7
store i8 %65, i8* %66
%67 = load i32, i32* @S_IWOTH
%68 = and i32 %67, %0
%69 = icmp eq i32 %68, 0
%70 = select i1 %69, i8 45, i8 119
%71 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 8
store i8 %70, i8* %71
%72 = load i32, i32* @S_IXOTH
%73 = and i32 %72, %0
%74 = icmp eq i32 %73, 0
%75 = select i1 %74, i8 45, i8 120
%76 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 9
store i8 %75, i8* %76
%77 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 10
store i8 0, i8* %77
%78 = call i8* @strcpy(i8* dereferenceable(1) %1, i8* %4)
ret void
}