#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 st_mode;
};
typedef int mode_t;

/* Variables and functions */
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
scalar_t__ S_ISDIR(int);
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
int /*<<< orphan*/ check_buff(char *, char *, int);
scalar_t__ malloc(int);
char *create_mode_to_perm_string(struct stat *stat_buffer) {
  mode_t mode = stat_buffer->st_mode;
  char *res = (char *)malloc(sizeof(char) * 11);
  check_buff(res, "Failed to allocate buffer for permisson string.", 2);
  res[0] = S_ISDIR(mode) ? 'd' : '-';
  res[1] = mode & S_IRUSR ? 'r' : '-';
  res[2] = mode & S_IWUSR ? 'w' : '-';
  res[3] = mode & S_IXUSR ? 'x' : '-';
  res[4] = mode & S_IRGRP ? 'r' : '-';
  res[5] = mode & S_IWGRP ? 'w' : '-';
  res[6] = mode & S_IXGRP ? 'x' : '-';
  res[7] = mode & S_IROTH ? 'r' : '-';
  res[8] = mode & S_IWOTH ? 'w' : '-';
  res[9] = mode & S_IXOTH ? 'x' : '-';
  res[10] = '\0';
  return res;
}


x86 assembly (clang, -O0):
<create_mode_to_perm_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0xb,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea2(%rip),%rsi
mov    $0x2,%edx
call   1040 <check_buff@plt>
mov    -0xc(%rbp),%edi
call   1030 <S_ISDIR@plt>
mov    %rax,%rdx
mov    $0x2d,%eax
mov    $0x64,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0xc(%rbp),%edx
mov    0x2e12(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0xc(%rbp),%edx
mov    0x2e15(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0xc(%rbp),%edx
mov    0x2e00(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0xc(%rbp),%edx
mov    0x2db3(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0xc(%rbp),%edx
mov    0x2dae(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0xc(%rbp),%edx
mov    0x2d79(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0xc(%rbp),%edx
mov    0x2d3c(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x72,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0xc(%rbp),%edx
mov    0x2cff(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x77,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0xc(%rbp),%edx
mov    0x2d2a(%rip),%rax
and    (%rax),%edx
mov    $0x2d,%eax
mov    $0x78,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,0xa(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_mode_to_perm_string>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%ebp
mov    $0xb,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xeb7(%rip),%rsi
mov    %rax,%rdi
mov    $0x2,%edx
call   1040 <check_buff@plt>
mov    %ebp,%edi
call   1030 <S_ISDIR@plt>
test   %rax,%rax
mov    $0x2d,%eax
mov    $0x64,%ecx
cmove  %eax,%ecx
mov    %cl,(%rbx)
mov    0x2e32(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
mov    $0x72,%ecx
cmove  %eax,%ecx
mov    %cl,0x1(%rbx)
mov    0x2e44(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
mov    $0x77,%ecx
cmove  %eax,%ecx
mov    %cl,0x2(%rbx)
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
mov    $0x78,%edx
cmove  %eax,%edx
mov    $0x72,%ecx
mov    %dl,0x3(%rbx)
mov    0x2dfb(%rip),%rdx
mov    (%rdx),%edx
and    %ebp,%edx
mov    $0x72,%esi
cmove  %eax,%esi
mov    $0x77,%edx
mov    %sil,0x4(%rbx)
mov    0x2dff(%rip),%rsi
mov    (%rsi),%esi
and    %ebp,%esi
mov    $0x77,%edi
cmove  %eax,%edi
mov    $0x78,%esi
mov    %dil,0x5(%rbx)
mov    0x2dd3(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
mov    $0x78,%edi
cmove  %eax,%edi
mov    %dil,0x6(%rbx)
mov    0x2da4(%rip),%rdi
mov    (%rdi),%edi
and    %ebp,%edi
cmove  %eax,%ecx
mov    %cl,0x7(%rbx)
mov    0x2d7b(%rip),%rcx
mov    (%rcx),%ecx
and    %ebp,%ecx
cmove  %eax,%edx
mov    %dl,0x8(%rbx)
mov    0x2dba(%rip),%rcx
and    (%rcx),%ebp
cmove  %eax,%esi
mov    %sil,0x9(%rbx)
movb   $0x0,0xa(%rbx)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [48 x i8] c"Failed to allocate buffer for permisson string.\00"
@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 i8* @create_mode_to_perm_string(%struct.stat* %0) {
%2 = alloca %struct.stat*
%3 = alloca i32
%4 = alloca i8*
store %struct.stat* %0, %struct.stat** %2
%5 = load %struct.stat*, %struct.stat** %2
%6 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%7 = load i32, i32* %6
store i32 %7, i32* %3
%8 = call i64 @malloc(i32 11)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
%10 = load i8*, i8** %4
%11 = call i32 @check_buff(i8* %10, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 2)
%12 = load i32, i32* %3
%13 = call i64 @S_ISDIR(i32 %12)
%14 = icmp ne i64 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i32 100, i32 45
%17 = trunc i32 %16 to i8
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 0
store i8 %17, i8* %19
%20 = load i32, i32* %3
%21 = load i32, i32* @S_IRUSR
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
%24 = zext i1 %23 to i64
%25 = select i1 %23, i32 114, i32 45
%26 = trunc i32 %25 to i8
%27 = load i8*, i8** %4
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 %26, i8* %28
%29 = load i32, i32* %3
%30 = load i32, i32* @S_IWUSR
%31 = and i32 %29, %30
%32 = icmp ne i32 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 119, i32 45
%35 = trunc i32 %34 to i8
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 2
store i8 %35, i8* %37
%38 = load i32, i32* %3
%39 = load i32, i32* @S_IXUSR
%40 = and i32 %38, %39
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i64
%43 = select i1 %41, i32 120, i32 45
%44 = trunc i32 %43 to i8
%45 = load i8*, i8** %4
%46 = getelementptr inbounds i8, i8* %45, i64 3
store i8 %44, i8* %46
%47 = load i32, i32* %3
%48 = load i32, i32* @S_IRGRP
%49 = and i32 %47, %48
%50 = icmp ne i32 %49, 0
%51 = zext i1 %50 to i64
%52 = select i1 %50, i32 114, i32 45
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %4
%55 = getelementptr inbounds i8, i8* %54, i64 4
store i8 %53, i8* %55
%56 = load i32, i32* %3
%57 = load i32, i32* @S_IWGRP
%58 = and i32 %56, %57
%59 = icmp ne i32 %58, 0
%60 = zext i1 %59 to i64
%61 = select i1 %59, i32 119, i32 45
%62 = trunc i32 %61 to i8
%63 = load i8*, i8** %4
%64 = getelementptr inbounds i8, i8* %63, i64 5
store i8 %62, i8* %64
%65 = load i32, i32* %3
%66 = load i32, i32* @S_IXGRP
%67 = and i32 %65, %66
%68 = icmp ne i32 %67, 0
%69 = zext i1 %68 to i64
%70 = select i1 %68, i32 120, i32 45
%71 = trunc i32 %70 to i8
%72 = load i8*, i8** %4
%73 = getelementptr inbounds i8, i8* %72, i64 6
store i8 %71, i8* %73
%74 = load i32, i32* %3
%75 = load i32, i32* @S_IROTH
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
%78 = zext i1 %77 to i64
%79 = select i1 %77, i32 114, i32 45
%80 = trunc i32 %79 to i8
%81 = load i8*, i8** %4
%82 = getelementptr inbounds i8, i8* %81, i64 7
store i8 %80, i8* %82
%83 = load i32, i32* %3
%84 = load i32, i32* @S_IWOTH
%85 = and i32 %83, %84
%86 = icmp ne i32 %85, 0
%87 = zext i1 %86 to i64
%88 = select i1 %86, i32 119, i32 45
%89 = trunc i32 %88 to i8
%90 = load i8*, i8** %4
%91 = getelementptr inbounds i8, i8* %90, i64 8
store i8 %89, i8* %91
%92 = load i32, i32* %3
%93 = load i32, i32* @S_IXOTH
%94 = and i32 %92, %93
%95 = icmp ne i32 %94, 0
%96 = zext i1 %95 to i64
%97 = select i1 %95, i32 120, i32 45
%98 = trunc i32 %97 to i8
%99 = load i8*, i8** %4
%100 = getelementptr inbounds i8, i8* %99, i64 9
store i8 %98, i8* %100
%101 = load i8*, i8** %4
%102 = getelementptr inbounds i8, i8* %101, i64 10
store i8 0, i8* %102
%103 = load i8*, i8** %4
ret i8* %103
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [48 x i8] c"Failed to allocate buffer for permisson string.\00"
@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 i8* @create_mode_to_perm_string(%struct.stat* nocapture %0) {
%2 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = tail call i64 @malloc(i32 11)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @check_buff(i8* %5, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i32 2)
%7 = tail call i64 @S_ISDIR(i32 %3)
%8 = icmp eq i64 %7, 0
%9 = select i1 %8, i8 45, i8 100
store i8 %9, i8* %5
%10 = load i32, i32* @S_IRUSR
%11 = and i32 %10, %3
%12 = icmp eq i32 %11, 0
%13 = select i1 %12, i8 45, i8 114
%14 = getelementptr inbounds i8, i8* %5, i64 1
store i8 %13, i8* %14
%15 = load i32, i32* @S_IWUSR
%16 = and i32 %15, %3
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i8 45, i8 119
%19 = getelementptr inbounds i8, i8* %5, i64 2
store i8 %18, i8* %19
%20 = load i32, i32* @S_IXUSR
%21 = and i32 %20, %3
%22 = icmp eq i32 %21, 0
%23 = select i1 %22, i8 45, i8 120
%24 = getelementptr inbounds i8, i8* %5, i64 3
store i8 %23, i8* %24
%25 = load i32, i32* @S_IRGRP
%26 = and i32 %25, %3
%27 = icmp eq i32 %26, 0
%28 = select i1 %27, i8 45, i8 114
%29 = getelementptr inbounds i8, i8* %5, i64 4
store i8 %28, i8* %29
%30 = load i32, i32* @S_IWGRP
%31 = and i32 %30, %3
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i8 45, i8 119
%34 = getelementptr inbounds i8, i8* %5, i64 5
store i8 %33, i8* %34
%35 = load i32, i32* @S_IXGRP
%36 = and i32 %35, %3
%37 = icmp eq i32 %36, 0
%38 = select i1 %37, i8 45, i8 120
%39 = getelementptr inbounds i8, i8* %5, i64 6
store i8 %38, i8* %39
%40 = load i32, i32* @S_IROTH
%41 = and i32 %40, %3
%42 = icmp eq i32 %41, 0
%43 = select i1 %42, i8 45, i8 114
%44 = getelementptr inbounds i8, i8* %5, i64 7
store i8 %43, i8* %44
%45 = load i32, i32* @S_IWOTH
%46 = and i32 %45, %3
%47 = icmp eq i32 %46, 0
%48 = select i1 %47, i8 45, i8 119
%49 = getelementptr inbounds i8, i8* %5, i64 8
store i8 %48, i8* %49
%50 = load i32, i32* @S_IXOTH
%51 = and i32 %50, %3
%52 = icmp eq i32 %51, 0
%53 = select i1 %52, i8 45, i8 120
%54 = getelementptr inbounds i8, i8* %5, i64 9
store i8 %53, i8* %54
%55 = getelementptr inbounds i8, i8* %5, i64 10
store i8 0, i8* %55
ret i8* %5
}