#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 */

/* Variables and functions */
char ftypelet(long);
int /*<<< orphan*/ rwx(unsigned short, char *);
int /*<<< orphan*/ setst(unsigned short, char *);
void mode_string(short unsigned int mode, char *str) {
  str[0] = ftypelet((long)mode);
  rwx((mode & 0700) << 0, &str[1]);
  rwx((mode & 0070) << 3, &str[4]);
  rwx((mode & 0007) << 6, &str[7]);
  setst(mode, str);
}


x86 assembly (clang, -O0):
<mode_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
movzwl -0x2(%rbp),%eax
mov    %eax,%edi
call   1040 <ftypelet@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
movzwl -0x2(%rbp),%eax
and    $0x1c0,%eax
shl    $0x0,%eax
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
movzwl %ax,%edi
call   1050 <rwx@plt>
movzwl -0x2(%rbp),%eax
and    $0x38,%eax
shl    $0x3,%eax
mov    -0x10(%rbp),%rsi
add    $0x4,%rsi
movzwl %ax,%edi
call   1050 <rwx@plt>
movzwl -0x2(%rbp),%eax
and    $0x7,%eax
shl    $0x6,%eax
mov    -0x10(%rbp),%rsi
add    $0x7,%rsi
movzwl %ax,%edi
call   1050 <rwx@plt>
mov    -0x2(%rbp),%ax
mov    -0x10(%rbp),%rsi
movzwl %ax,%edi
call   1030 <setst@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mode_string>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %edi,%edi
call   1040 <ftypelet@plt>
mov    %al,(%rbx)
lea    0x1(%rbx),%rsi
mov    %ebp,%edi
and    $0x1c0,%edi
call   1050 <rwx@plt>
mov    %ebp,%edi
and    $0x38,%edi
shl    $0x3,%edi
lea    0x4(%rbx),%rsi
call   1050 <rwx@plt>
mov    %ebp,%edi
and    $0x7,%edi
shl    $0x6,%edi
lea    0x7(%rbx),%rsi
call   1050 <rwx@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <setst@plt>

LLVM IR (-O0):
define void @mode_string(i16 zeroext %0, i8* %1) {
%3 = alloca i16
%4 = alloca i8*
store i16 %0, i16* %3
store i8* %1, i8** %4
%5 = load i16, i16* %3
%6 = zext i16 %5 to i64
%7 = call signext i8 @ftypelet(i64 %6)
%8 = load i8*, i8** %4
%9 = getelementptr inbounds i8, i8* %8, i64 0
store i8 %7, i8* %9
%10 = load i16, i16* %3
%11 = zext i16 %10 to i32
%12 = and i32 %11, 448
%13 = shl i32 %12, 0
%14 = trunc i32 %13 to i16
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = call i32 @rwx(i16 zeroext %14, i8* %16)
%18 = load i16, i16* %3
%19 = zext i16 %18 to i32
%20 = and i32 %19, 56
%21 = shl i32 %20, 3
%22 = trunc i32 %21 to i16
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 4
%25 = call i32 @rwx(i16 zeroext %22, i8* %24)
%26 = load i16, i16* %3
%27 = zext i16 %26 to i32
%28 = and i32 %27, 7
%29 = shl i32 %28, 6
%30 = trunc i32 %29 to i16
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i64 7
%33 = call i32 @rwx(i16 zeroext %30, i8* %32)
%34 = load i16, i16* %3
%35 = load i8*, i8** %4
%36 = call i32 @setst(i16 zeroext %34, i8* %35)
ret void
}

LLVM IR (-O2):
define void @mode_string(i16 zeroext %0, i8* %1) {
%3 = zext i16 %0 to i64
%4 = tail call signext i8 @ftypelet(i64 %3)
store i8 %4, i8* %1
%5 = and i16 %0, 448
%6 = getelementptr inbounds i8, i8* %1, i64 1
%7 = tail call i32 @rwx(i16 zeroext %5, i8* %6)
%8 = shl i16 %0, 3
%9 = and i16 %8, 448
%10 = getelementptr inbounds i8, i8* %1, i64 4
%11 = tail call i32 @rwx(i16 zeroext %9, i8* %10)
%12 = shl i16 %0, 6
%13 = and i16 %12, 448
%14 = getelementptr inbounds i8, i8* %1, i64 7
%15 = tail call i32 @rwx(i16 zeroext %13, i8* %14)
%16 = tail call i32 @setst(i16 zeroext %0, i8* %1)
ret void
}