#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;
int /*<<< orphan*/ printf(char *, int, int, int);
void print_perm_number(struct stat file_stat) {
  int user = 0, group = 0, others = 0;
  mode_t mode = file_stat.st_mode;
  if (mode & S_IRUSR)
    (user += 4);
  if (mode & S_IWUSR)
    (user += 2);
  if (mode & S_IXUSR)
    (user += 1);
  if (mode & S_IRGRP)
    (group += 4);
  if (mode & S_IWGRP)
    (group += 2);
  if (mode & S_IXGRP)
    (group += 1);
  if (mode & S_IROTH)
    (others += 4);
  if (mode & S_IWOTH)
    (others += 2);
  if (mode & S_IXOTH)
    (others += 1);
  printf("%d%d%d\n", user, group, others);
}


x86 assembly (clang, -O0):
<print_perm_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e68(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1154 <print_perm_number+0x44>
mov    -0xc(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e72(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1172 <print_perm_number+0x62>
mov    -0xc(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e64(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1190 <print_perm_number+0x80>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e1e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ae <print_perm_number+0x9e>
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e20(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11cc <print_perm_number+0xbc>
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2df2(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11ea <print_perm_number+0xda>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2dbc(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1208 <print_perm_number+0xf8>
mov    -0x14(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2d86(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1226 <print_perm_number+0x116>
mov    -0x14(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2db8(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1244 <print_perm_number+0x134>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xdac(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_perm_number>:
mov    0x2e91(%rip),%rax
xor    %ecx,%ecx
mov    (%rax),%eax
and    %edi,%eax
setne  %cl
lea    0x0(,%rcx,4),%eax
mov    0x2ea2(%rip),%rdx
mov    (%rdx),%edx
and    %edi,%edx
lea    0x2(,%rcx,4),%ecx
cmove  %eax,%ecx
mov    0x2e9d(%rip),%rax
xor    %esi,%esi
mov    (%rax),%eax
and    %edi,%eax
setne  %sil
or     %ecx,%esi
mov    0x2e62(%rip),%rax
xor    %ecx,%ecx
mov    (%rax),%eax
and    %edi,%eax
setne  %cl
lea    0x0(,%rcx,4),%eax
mov    0x2e6b(%rip),%rdx
mov    (%rdx),%edx
and    %edi,%edx
lea    0x2(,%rcx,4),%ecx
cmove  %eax,%ecx
mov    0x2e46(%rip),%rax
xor    %edx,%edx
mov    (%rax),%eax
and    %edi,%eax
setne  %dl
or     %ecx,%edx
mov    0x2e1c(%rip),%rax
xor    %ecx,%ecx
mov    (%rax),%eax
and    %edi,%eax
setne  %cl
lea    0x0(,%rcx,4),%r8d
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
and    %edi,%eax
lea    0x2(,%rcx,4),%eax
cmove  %r8d,%eax
mov    0x2e26(%rip),%r8
xor    %ecx,%ecx
and    (%r8),%edi
setne  %cl
or     %eax,%ecx
lea    0xe2d(%rip),%rdi
jmp    1030 <printf@plt>

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
@.str = [8 x i8] c"%d%d%d\0A\00"
define void @print_perm_number(i32 %0) {
%2 = alloca %struct.stat
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
store i32 %0, i32* %7
store i32 0, i32* %3
store i32 0, i32* %4
store i32 0, i32* %5
%8 = getelementptr inbounds %struct.stat, %struct.stat* %2, i32 0, i32 0
%9 = load i32, i32* %8
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @S_IRUSR
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 4
store i32 %16, i32* %3
br label %17
17: ; preds = %14, %1
%18 = load i32, i32* %6
%19 = load i32, i32* @S_IWUSR
%20 = and i32 %18, %19
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 2
store i32 %24, i32* %3
br label %25
25: ; preds = %22, %17
%26 = load i32, i32* %6
%27 = load i32, i32* @S_IXUSR
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %3
%32 = add nsw i32 %31, 1
store i32 %32, i32* %3
br label %33
33: ; preds = %30, %25
%34 = load i32, i32* %6
%35 = load i32, i32* @S_IRGRP
%36 = and i32 %34, %35
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 4
store i32 %40, i32* %4
br label %41
41: ; preds = %38, %33
%42 = load i32, i32* %6
%43 = load i32, i32* @S_IWGRP
%44 = and i32 %42, %43
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %4
%48 = add nsw i32 %47, 2
store i32 %48, i32* %4
br label %49
49: ; preds = %46, %41
%50 = load i32, i32* %6
%51 = load i32, i32* @S_IXGRP
%52 = and i32 %50, %51
%53 = icmp ne i32 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %49
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %57
57: ; preds = %54, %49
%58 = load i32, i32* %6
%59 = load i32, i32* @S_IROTH
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %57
%63 = load i32, i32* %5
%64 = add nsw i32 %63, 4
store i32 %64, i32* %5
br label %65
65: ; preds = %62, %57
%66 = load i32, i32* %6
%67 = load i32, i32* @S_IWOTH
%68 = and i32 %66, %67
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %65
%71 = load i32, i32* %5
%72 = add nsw i32 %71, 2
store i32 %72, i32* %5
br label %73
73: ; preds = %70, %65
%74 = load i32, i32* %6
%75 = load i32, i32* @S_IXOTH
%76 = and i32 %74, %75
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = load i32, i32* %5
%80 = add nsw i32 %79, 1
store i32 %80, i32* %5
br label %81
81: ; preds = %78, %73
%82 = load i32, i32* %3
%83 = load i32, i32* %4
%84 = load i32, i32* %5
%85 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %82, i32 %83, i32 %84)
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
@.str = [8 x i8] c"%d%d%d\0A\00"
define void @print_perm_number(i32 %0) {
%2 = load i32, i32* @S_IRUSR
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, 0
%5 = select i1 %4, i32 0, i32 4
%6 = load i32, i32* @S_IWUSR
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, 0
%9 = or i32 %5, 2
%10 = select i1 %8, i32 %5, i32 %9
%11 = load i32, i32* @S_IXUSR
%12 = and i32 %11, %0
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i32
%15 = or i32 %10, %14
%16 = load i32, i32* @S_IRGRP
%17 = and i32 %16, %0
%18 = icmp eq i32 %17, 0
%19 = select i1 %18, i32 0, i32 4
%20 = load i32, i32* @S_IWGRP
%21 = and i32 %20, %0
%22 = icmp eq i32 %21, 0
%23 = or i32 %19, 2
%24 = select i1 %22, i32 %19, i32 %23
%25 = load i32, i32* @S_IXGRP
%26 = and i32 %25, %0
%27 = icmp ne i32 %26, 0
%28 = zext i1 %27 to i32
%29 = or i32 %24, %28
%30 = load i32, i32* @S_IROTH
%31 = and i32 %30, %0
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 0, i32 4
%34 = load i32, i32* @S_IWOTH
%35 = and i32 %34, %0
%36 = icmp eq i32 %35, 0
%37 = or i32 %33, 2
%38 = select i1 %36, i32 %33, i32 %37
%39 = load i32, i32* @S_IXOTH
%40 = and i32 %39, %0
%41 = icmp ne i32 %40, 0
%42 = zext i1 %41 to i32
%43 = or i32 %38, %42
%44 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %15, i32 %29, i32 %43)
ret void
}