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

/* Variables and functions */
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISLNK(int);
int /*<<< orphan*/ printf(char *);
void file__print_mode(struct stat *st) {
  if (S_ISDIR(st->st_mode))
    printf("d");
  else if (S_ISLNK(st->st_mode))
    printf("l");
  else
    printf("-");
  for (int i = 8; i >= 0; i--)
    if ((st->st_mode >> i) & 1) {
      if (i % 3 == 2)
        printf("r");
      else if (i % 3 == 1)
        printf("w");
      else
        printf("x");
    } else
      printf("-");
  printf(" ");
}


x86 assembly (clang, -O0):
<file__print_mode>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1162 <file__print_mode+0x32>
lea    0xea8(%rip),%rdi
call   1040 <printf@plt>
jmp    1199 <file__print_mode+0x69>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1188 <file__print_mode+0x58>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
jmp    1194 <file__print_mode+0x64>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
jmp    1199 <file__print_mode+0x69>
movl   $0x8,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1240 <file__print_mode+0x110>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0xc(%rbp),%ecx
sar    %cl,%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1221 <file__print_mode+0xf1>
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x2,%edx
jne    11e6 <file__print_mode+0xb6>
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
jmp    121c <file__print_mode+0xec>
mov    -0xc(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x1,%edx
jne    120b <file__print_mode+0xdb>
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
jmp    1217 <file__print_mode+0xe7>
lea    0xdf8(%rip),%rdi
call   1040 <printf@plt>
jmp    121c <file__print_mode+0xec>
jmp    122d <file__print_mode+0xfd>
lea    0xddc(%rip),%rdi
call   1040 <printf@plt>
jmp    1232 <file__print_mode+0x102>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11a0 <file__print_mode+0x70>
lea    0xdc5(%rip),%rdi
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file__print_mode>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    (%rdi),%edi
call   1050 <S_ISDIR@plt>
mov    $0x64,%edi
test   %rax,%rax
jne    1164 <file__print_mode+0x34>
mov    (%r14),%edi
call   1040 <S_ISLNK@plt>
test   %rax,%rax
mov    $0x2d,%eax
mov    $0x6c,%edi
cmove  %eax,%edi
call   1030 <putchar@plt>
mov    $0x8,%ebp
xor    %ebx,%ebx
mov    $0xaaaaaaab,%r15d
mov    $0x72,%r12d
jmp    11b7 <file__print_mode+0x87>
xchg   %ax,%ax
mov    %ebp,%eax
imul   %r15,%rax
shr    $0x21,%rax
lea    (%rax,%rax,2),%eax
add    $0xfffffff9,%eax
lea    0x1(%rax),%ecx
xor    %edx,%edx
cmp    %ebx,%eax
sete   %dl
mov    $0x78,%edi
sub    %edx,%edi
cmp    %ebx,%ecx
cmove  %r12d,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebp
add    $0xffffffff,%ebx
cmp    $0xfffffff7,%ebx
je     11cc <file__print_mode+0x9c>
mov    (%r14),%eax
lea    0x8(%rbx),%ecx
movzbl %cl,%ecx
bt     %ecx,%eax
jb     1180 <file__print_mode+0x50>
mov    $0x2d,%edi
jmp    11a7 <file__print_mode+0x77>
mov    $0x20,%edi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [2 x i8] c"d\00"
@.str.1 = [2 x i8] c"l\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [2 x i8] c"x\00"
@.str.6 = [2 x i8] c" \00"
define void @file__print_mode(%struct.stat* %0) {
%2 = alloca %struct.stat*
%3 = alloca i32
store %struct.stat* %0, %struct.stat** %2
%4 = load %struct.stat*, %struct.stat** %2
%5 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%6 = load i32, i32* %5
%7 = call i64 @S_ISDIR(i32 %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %22
11: ; preds = %1
%12 = load %struct.stat*, %struct.stat** %2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @S_ISLNK(i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %21
19: ; preds = %11
%20 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %17
br label %22
22: ; preds = %21, %9
store i32 8, i32* %3
br label %23
23: ; preds = %53, %22
%24 = load i32, i32* %3
%25 = icmp sge i32 %24, 0
br i1 %25, label %26, label %56
26: ; preds = %23
%27 = load %struct.stat*, %struct.stat** %2
%28 = getelementptr inbounds %struct.stat, %struct.stat* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i32, i32* %3
%31 = ashr i32 %29, %30
%32 = and i32 %31, 1
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %50
34: ; preds = %26
%35 = load i32, i32* %3
%36 = srem i32 %35, 3
%37 = icmp eq i32 %36, 2
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %49
40: ; preds = %34
%41 = load i32, i32* %3
%42 = srem i32 %41, 3
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %46
44: ; preds = %40
%45 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %48
46: ; preds = %40
%47 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %44
br label %49
49: ; preds = %48, %38
br label %52
50: ; preds = %26
%51 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %52
52: ; preds = %50, %49
br label %53
53: ; preds = %52
%54 = load i32, i32* %3
%55 = add nsw i32 %54, -1
store i32 %55, i32* %3
br label %23
56: ; preds = %23
%57 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define void @file__print_mode(%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 @S_ISDIR(i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = load i32, i32* %2
%8 = tail call i64 @S_ISLNK(i32 %7)
%9 = icmp eq i64 %8, 0
%10 = select i1 %9, i32 45, i32 108
br label %11
11: ; preds = %6, %1
%12 = phi i32 [ 100, %1 ], [ %10, %6 ]
%13 = tail call i32 @putchar(i32 %12)
br label %16
14: ; preds = %28
%15 = tail call i32 @putchar(i32 32)
ret void
16: ; preds = %11, %28
%17 = phi i32 [ 8, %11 ], [ %31, %28 ]
%18 = load i32, i32* %2
%19 = shl nuw i32 1, %17
%20 = and i32 %18, %19
%21 = icmp eq i32 %20, 0
br i1 %21, label %28, label %22
22: ; preds = %16
%23 = urem i32 %17, 3
%24 = icmp eq i32 %23, 1
%25 = select i1 %24, i32 119, i32 120
%26 = icmp eq i32 %23, 2
%27 = select i1 %26, i32 114, i32 %25
br label %28
28: ; preds = %16, %22
%29 = phi i32 [ %27, %22 ], [ 45, %16 ]
%30 = tail call i32 @putchar(i32 %29)
%31 = add nsw i32 %17, -1
%32 = icmp eq i32 %17, 0
br i1 %32, label %14, label %16
}