#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 S_IXUSR;
int /*<<< orphan*/ printf(char *, ...);
void file__print_filename(struct stat *st, const char *filename) {
  if (S_ISDIR(st->st_mode))
    printf("\x1b[34m");
  else if (S_ISLNK(st->st_mode))
    printf("\x1b[36m");
  else if (st->st_mode & S_IXUSR)
    printf("\x1b[32m");
  printf("%s ", filename);
  printf("\x1b[0m");
}


x86 assembly (clang, -O0):
<file__print_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1168 <file__print_filename+0x38>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11c0 <file__print_filename+0x90>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1190 <file__print_filename+0x60>
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11bb <file__print_filename+0x8b>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    0x2e4b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11b6 <file__print_filename+0x86>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11bb <file__print_filename+0x8b>
jmp    11c0 <file__print_filename+0x90>
mov    -0x10(%rbp),%rsi
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe3d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file__print_filename>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     114f <file__print_filename+0x1f>
lea    0xeb3(%rip),%rdi
jmp    1178 <file__print_filename+0x48>
mov    (%rbx),%edi
call   1030 <S_ISLNK@plt>
test   %rax,%rax
je     1164 <file__print_filename+0x34>
lea    0xea4(%rip),%rdi
jmp    1178 <file__print_filename+0x48>
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rbx)
je     117f <file__print_filename+0x4f>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [6 x i8] c"\1B[34m\00"
@.str.1 = [6 x i8] c"\1B[36m\00"
@S_IXUSR = global i32 0
@.str.2 = [6 x i8] c"\1B[32m\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [5 x i8] c"\1B[0m\00"
define void @file__print_filename(%struct.stat* %0, i8* %1) {
%3 = alloca %struct.stat*
%4 = alloca i8*
store %struct.stat* %0, %struct.stat** %3
store i8* %1, i8** %4
%5 = load %struct.stat*, %struct.stat** %3
%6 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = call i64 @S_ISDIR(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %31
12: ; preds = %2
%13 = load %struct.stat*, %struct.stat** %3
%14 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i64 @S_ISLNK(i32 %15)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %30
20: ; preds = %12
%21 = load %struct.stat*, %struct.stat** %3
%22 = getelementptr inbounds %struct.stat, %struct.stat* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = load i32, i32* @S_IXUSR
%25 = and i32 %23, %24
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %20
br label %30
30: ; preds = %29, %18
br label %31
31: ; preds = %30, %10
%32 = load i8*, i8** %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [6 x i8] c"\1B[34m\00"
@.str.1 = [6 x i8] c"\1B[36m\00"
@S_IXUSR = global i32 0
@.str.2 = [6 x i8] c"\1B[32m\00"
@.str.3 = [4 x i8] c"%s \00"
@.str.4 = [5 x i8] c"\1B[0m\00"
define void @file__print_filename(%struct.stat* nocapture %0, i8* %1) {
%3 = getelementptr inbounds %struct.stat, %struct.stat* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = tail call i64 @S_ISDIR(i32 %4)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %16
7: ; preds = %2
%8 = load i32, i32* %3
%9 = tail call i64 @S_ISLNK(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i32, i32* %3
%13 = load i32, i32* @S_IXUSR
%14 = and i32 %13, %12
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %11, %7, %2
%17 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %11 ]
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %17)
br label %19
19: ; preds = %16, %11
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
ret void
}