#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 */
typedef int /*<<< orphan*/ tmp;

/* Variables and functions */
int listfile_long(char const *, int);
int listfile_size(char const *, char const *, int);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int listfile(const char *dirname, const char *filename, int flags) {
  if ((flags & ((1 << 0) | (1 << 4))) == 0) {
    printf("%s\n", filename);
    return 0;
  }
  char tmp[4096];
  const char *pathname = filename;
  if (dirname != NULL) {
    snprintf(tmp, sizeof(tmp), "%s/%s", dirname, filename);
    pathname = tmp;
  } else {
    pathname = filename;
  }
  if ((flags & (1 << 0)) != 0) {
    return listfile_long(pathname, flags);
  } else {
    return listfile_size(pathname, filename, flags);
  }
}


x86 assembly (clang, -O0):
<listfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x11,%eax
cmp    $0x0,%eax
jne    1181 <listfile+0x41>
mov    -0x18(%rbp),%rsi
lea    0xe90(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1211 <listfile+0xd1>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ca <listfile+0x8a>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%r8
mov    $0x1000,%esi
lea    0xe52(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
jmp    11d5 <listfile+0x95>
mov    -0x18(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11fb <listfile+0xbb>
mov    -0x1028(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <listfile_long@plt>
mov    %eax,-0x4(%rbp)
jmp    1211 <listfile+0xd1>
mov    -0x1028(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <listfile_size@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listfile>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
test   $0x11,%bl
je     118f <listfile+0x4f>
mov    %rdi,%rcx
mov    %r14,%r15
test   %rdi,%rdi
je     117b <listfile+0x3b>
mov    %rsp,%r15
lea    0xe99(%rip),%rdx
mov    %r15,%rdi
mov    $0x1000,%esi
mov    %r14,%r8
call   1040 <snprintf@plt>
mov    %r15,%rdi
test   $0x1,%bl
jne    11a2 <listfile+0x62>
mov    %r14,%rsi
mov    %ebx,%edx
call   1050 <listfile_size@plt>
jmp    11a9 <listfile+0x69>
lea    0xe6a(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    11a9 <listfile+0x69>
mov    %ebx,%esi
call   1060 <listfile_long@plt>
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @listfile(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [4096 x i8]
%9 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = and i32 %10, 17
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %4
br label %41
16: ; preds = %3
%17 = load i8*, i8** %6
store i8* %17, i8** %9
%18 = load i8*, i8** %5
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%22 = load i8*, i8** %5
%23 = load i8*, i8** %6
%24 = call i32 @snprintf(i8* %21, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %22, i8* %23)
%25 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
store i8* %25, i8** %9
br label %28
26: ; preds = %16
%27 = load i8*, i8** %6
store i8* %27, i8** %9
br label %28
28: ; preds = %26, %20
%29 = load i32, i32* %7
%30 = and i32 %29, 1
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8*, i8** %9
%34 = load i32, i32* %7
%35 = call i32 @listfile_long(i8* %33, i32 %34)
store i32 %35, i32* %4
br label %41
36: ; preds = %28
%37 = load i8*, i8** %9
%38 = load i8*, i8** %6
%39 = load i32, i32* %7
%40 = call i32 @listfile_size(i8* %37, i8* %38, i32 %39)
store i32 %40, i32* %4
br label %41
41: ; preds = %36, %32, %13
%42 = load i32, i32* %4
ret i32 %42
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
define i32 @listfile(i8* %0, i8* %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = and i32 %2, 17
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %24
9: ; preds = %3
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%11 = icmp eq i8* %0, null
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @snprintf(i8* %10, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %1)
br label %14
14: ; preds = %9, %12
%15 = phi i8* [ %10, %12 ], [ %1, %9 ]
%16 = and i32 %2, 1
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %14
%19 = call i32 @listfile_long(i8* %15, i32 %2)
br label %22
20: ; preds = %14
%21 = call i32 @listfile_size(i8* %15, i8* %1, i32 %2)
br label %22
22: ; preds = %20, %18
%23 = phi i32 [ %19, %18 ], [ %21, %20 ]
br label %24
24: ; preds = %22, %7
%25 = phi i32 [ 0, %7 ], [ %23, %22 ]
ret i32 %25
}