#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;
int S_IWGRP;
int S_IWOTH;
int S_IWUSR;
int S_IXGRP;
int S_IXOTH;
int S_IXUSR;
char *malloc(int);
int /*<<< orphan*/ traiter(int, char, char, int *, char *);
char *droits(struct stat *pstat) {
  mode_t mode;
  char *modes = malloc(sizeof(10));
  int indice_mode = 0;
  mode = pstat->st_mode;
  traiter(mode & S_IRUSR, 'r', '-', &indice_mode, modes);
  traiter(mode & S_IWUSR, 'w', '-', &indice_mode, modes);
  traiter(mode & S_IXUSR, 'x', '-', &indice_mode, modes);
  traiter(mode & S_IRGRP, 'r', '-', &indice_mode, modes);
  traiter(mode & S_IWGRP, 'w', '-', &indice_mode, modes);
  traiter(mode & S_IXGRP, 'x', '-', &indice_mode, modes);
  traiter(mode & S_IROTH, 'r', '-', &indice_mode, modes);
  traiter(mode & S_IWOTH, 'w', '-', &indice_mode, modes);
  traiter(mode & S_IXOTH, 'x', '-', &indice_mode, modes);
  modes[indice_mode] = '\0';
  return modes;
}


x86 assembly (clang, -O0):
<droits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e54(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x72,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2e59(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x77,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2e46(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x78,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2dfb(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x72,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2df8(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x77,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2dc5(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x78,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2d8a(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x72,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2d4f(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x77,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0xc(%rbp),%edi
mov    0x2d7c(%rip),%rax
and    (%rax),%edi
mov    -0x18(%rbp),%r8
mov    $0x78,%esi
mov    $0x2d,%edx
lea    -0x1c(%rbp),%rcx
call   1030 <traiter@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<droits>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbp
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,0xc(%rsp)
mov    0x0(%rbp),%ebp
mov    0x2e5e(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
lea    0xc(%rsp),%r14
mov    $0x72,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2e61(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x77,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x78,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x72,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x77,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x78,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x72,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
and    %ebp,%edi
mov    $0x77,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
mov    0x2d99(%rip),%rax
and    (%rax),%ebp
mov    %ebp,%edi
mov    $0x78,%esi
mov    $0x2d,%edx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <traiter@plt>
movslq 0xc(%rsp),%rax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@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* @droits(%struct.stat* %0) {
%2 = alloca %struct.stat*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store %struct.stat* %0, %struct.stat** %2
%6 = call i8* @malloc(i32 4)
store i8* %6, i8** %4
store i32 0, i32* %5
%7 = load %struct.stat*, %struct.stat** %2
%8 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%9 = load i32, i32* %8
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = load i32, i32* @S_IRUSR
%12 = and i32 %10, %11
%13 = load i8*, i8** %4
%14 = call i32 @traiter(i32 %12, i8 signext 114, i8 signext 45, i32* %5, i8* %13)
%15 = load i32, i32* %3
%16 = load i32, i32* @S_IWUSR
%17 = and i32 %15, %16
%18 = load i8*, i8** %4
%19 = call i32 @traiter(i32 %17, i8 signext 119, i8 signext 45, i32* %5, i8* %18)
%20 = load i32, i32* %3
%21 = load i32, i32* @S_IXUSR
%22 = and i32 %20, %21
%23 = load i8*, i8** %4
%24 = call i32 @traiter(i32 %22, i8 signext 120, i8 signext 45, i32* %5, i8* %23)
%25 = load i32, i32* %3
%26 = load i32, i32* @S_IRGRP
%27 = and i32 %25, %26
%28 = load i8*, i8** %4
%29 = call i32 @traiter(i32 %27, i8 signext 114, i8 signext 45, i32* %5, i8* %28)
%30 = load i32, i32* %3
%31 = load i32, i32* @S_IWGRP
%32 = and i32 %30, %31
%33 = load i8*, i8** %4
%34 = call i32 @traiter(i32 %32, i8 signext 119, i8 signext 45, i32* %5, i8* %33)
%35 = load i32, i32* %3
%36 = load i32, i32* @S_IXGRP
%37 = and i32 %35, %36
%38 = load i8*, i8** %4
%39 = call i32 @traiter(i32 %37, i8 signext 120, i8 signext 45, i32* %5, i8* %38)
%40 = load i32, i32* %3
%41 = load i32, i32* @S_IROTH
%42 = and i32 %40, %41
%43 = load i8*, i8** %4
%44 = call i32 @traiter(i32 %42, i8 signext 114, i8 signext 45, i32* %5, i8* %43)
%45 = load i32, i32* %3
%46 = load i32, i32* @S_IWOTH
%47 = and i32 %45, %46
%48 = load i8*, i8** %4
%49 = call i32 @traiter(i32 %47, i8 signext 119, i8 signext 45, i32* %5, i8* %48)
%50 = load i32, i32* %3
%51 = load i32, i32* @S_IXOTH
%52 = and i32 %50, %51
%53 = load i8*, i8** %4
%54 = call i32 @traiter(i32 %52, i8 signext 120, i8 signext 45, i32* %5, i8* %53)
%55 = load i8*, i8** %4
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
store i8 0, i8* %58
%59 = load i8*, i8** %4
ret i8* %59
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@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* @droits(%struct.stat* nocapture %0) {
%2 = alloca i32
%3 = tail call dereferenceable_or_null(4) i8* @malloc(i32 4)
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* @S_IRUSR
%8 = and i32 %7, %6
%9 = call i32 @traiter(i32 %8, i8 signext 114, i8 signext 45, i32* %2, i8* %3)
%10 = load i32, i32* @S_IWUSR
%11 = and i32 %10, %6
%12 = call i32 @traiter(i32 %11, i8 signext 119, i8 signext 45, i32* %2, i8* %3)
%13 = load i32, i32* @S_IXUSR
%14 = and i32 %13, %6
%15 = call i32 @traiter(i32 %14, i8 signext 120, i8 signext 45, i32* %2, i8* %3)
%16 = load i32, i32* @S_IRGRP
%17 = and i32 %16, %6
%18 = call i32 @traiter(i32 %17, i8 signext 114, i8 signext 45, i32* %2, i8* %3)
%19 = load i32, i32* @S_IWGRP
%20 = and i32 %19, %6
%21 = call i32 @traiter(i32 %20, i8 signext 119, i8 signext 45, i32* %2, i8* %3)
%22 = load i32, i32* @S_IXGRP
%23 = and i32 %22, %6
%24 = call i32 @traiter(i32 %23, i8 signext 120, i8 signext 45, i32* %2, i8* %3)
%25 = load i32, i32* @S_IROTH
%26 = and i32 %25, %6
%27 = call i32 @traiter(i32 %26, i8 signext 114, i8 signext 45, i32* %2, i8* %3)
%28 = load i32, i32* @S_IWOTH
%29 = and i32 %28, %6
%30 = call i32 @traiter(i32 %29, i8 signext 119, i8 signext 45, i32* %2, i8* %3)
%31 = load i32, i32* @S_IXOTH
%32 = and i32 %31, %6
%33 = call i32 @traiter(i32 %32, i8 signext 120, i8 signext 45, i32* %2, i8* %3)
%34 = load i32, i32* %2
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %3, i64 %35
store i8 0, i8* %36
ret i8* %3
}