#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;
  int st_nlink;
  int st_uid;
  int st_gid;
  int st_dev;
  int st_size;
  int /*<<< orphan*/ st_mtime;
};

/* Variables and functions */
int S_IFBLK;
int S_IFCHR;
int S_IFMT;
int ilog10(int);
int /*<<< orphan*/ print_date(int /*<<< orphan*/);
int /*<<< orphan*/ print_file_color(int, char *);
int /*<<< orphan*/ print_permissions(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
void list_file_long(char *name, char *path, int maxsize) {
  struct stat stat_buf;
  int padding, i;
  char full_path[256];
  int mode;
  if (path == NULL) {
    snprintf(full_path, 256, "%s", name);
  } else {
    snprintf(full_path, 256, "%s/%s", path, name);
  }
  stat(full_path, &stat_buf);
  mode = stat_buf.st_mode & S_IFMT;
  print_permissions(stat_buf.st_mode);
  printf(" %2d %d %d ", stat_buf.st_nlink, stat_buf.st_uid, stat_buf.st_gid);
  if ((mode == S_IFCHR) || (mode == S_IFBLK)) {
    printf("%d, %d ", (stat_buf.st_dev) >> 16, (stat_buf.st_dev & 0xffff));
  } else {
    padding = ilog10(maxsize) - ilog10(stat_buf.st_size);
    for (i = 0; i < padding; i++)
      printf(" ");
    printf("%lld ", stat_buf.st_size);
  }
  print_date(stat_buf.st_mtime);
  printf(" ");
  print_file_color(stat_buf.st_mode, name);
  printf("\n");
}


x86 assembly (clang, -O0):
<list_file_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <list_file_long+0x44>
lea    -0x140(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe5b(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
jmp    11d6 <list_file_long+0x66>
lea    -0x140(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%r8
mov    $0x100,%esi
lea    0xe31(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    -0x140(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x30(%rbp),%eax
mov    0x2df0(%rip),%rcx
and    (%rcx),%eax
mov    %eax,-0x144(%rbp)
mov    -0x30(%rbp),%edi
call   1090 <print_permissions@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x144(%rbp),%eax
mov    0x2dac(%rip),%rcx
cmp    (%rcx),%eax
je     1241 <list_file_long+0xd1>
mov    -0x144(%rbp),%eax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%eax
jne    1263 <list_file_long+0xf3>
mov    -0x20(%rbp),%esi
sar    $0x10,%esi
mov    -0x20(%rbp),%edx
and    $0xffff,%edx
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12c6 <list_file_long+0x156>
mov    -0x14(%rbp),%edi
call   1030 <ilog10@plt>
mov    %eax,-0x148(%rbp)
mov    -0x1c(%rbp),%edi
call   1030 <ilog10@plt>
mov    %eax,%ecx
mov    -0x148(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    12b5 <list_file_long+0x145>
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    128d <list_file_long+0x11d>
mov    -0x1c(%rbp),%esi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%edi
call   1060 <print_date@plt>
lea    0xd43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1080 <print_file_color@plt>
lea    0xd31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_file_long>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x128,%rsp
mov    %edx,%r14d
mov    %rdi,%r15
test   %rsi,%rsi
je     11b8 <list_file_long+0x38>
mov    %rsi,%rcx
lea    0xe5e(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
mov    %r15,%r8
xor    %eax,%eax
call   1060 <snprintf@plt>
jmp    11d3 <list_file_long+0x53>
lea    0xe44(%rip),%rdx
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1060 <snprintf@plt>
lea    0x20(%rsp),%rdi
mov    %rsp,%rsi
call   1080 <stat@plt>
mov    (%rsp),%ebp
mov    0x2df6(%rip),%rax
mov    (%rax),%ebx
and    %ebp,%ebx
mov    %ebp,%edi
call   10a0 <print_permissions@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0xc(%rsp),%ecx
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2dba(%rip),%rax
cmp    (%rax),%ebx
je     1272 <list_file_long+0xf2>
mov    0x2db7(%rip),%rax
cmp    (%rax),%ebx
je     1272 <list_file_long+0xf2>
mov    %r14d,%edi
call   1040 <ilog10@plt>
mov    %eax,%ebx
mov    0x14(%rsp),%r14d
mov    %r14d,%edi
call   1040 <ilog10@plt>
sub    %eax,%ebx
test   %ebx,%ebx
jle    125f <list_file_long+0xdf>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x20,%edi
call   1030 <putchar@plt>
add    $0xffffffff,%ebx
jne    1250 <list_file_long+0xd0>
lea    0xdb4(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    128a <list_file_long+0x10a>
mov    0x10(%rsp),%esi
movzwl %si,%edx
sar    $0x10,%esi
lea    0xd8f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x18(%rsp),%edi
call   1070 <print_date@plt>
mov    $0x20,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
mov    %r15,%rsi
call   1090 <print_file_color@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32, i32, i32, i32, i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@S_IFMT = global i32 0
@.str.2 = [12 x i8] c" %2d %d %d \00"
@S_IFCHR = global i32 0
@S_IFBLK = global i32 0
@.str.3 = [8 x i8] c"%d, %d \00"
@.str.4 = [2 x i8] c" \00"
@.str.5 = [6 x i8] c"%lld \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @list_file_long(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.stat
%8 = alloca i32
%9 = alloca i32
%10 = alloca [256 x i8]
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %5
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%16 = load i8*, i8** %4
%17 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %23
18: ; preds = %3
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%20 = load i8*, i8** %5
%21 = load i8*, i8** %4
%22 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21)
br label %23
23: ; preds = %18, %14
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%25 = call i32 @stat(i8* %24, %struct.stat* %7)
%26 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @S_IFMT
%29 = and i32 %27, %28
store i32 %29, i32* %11
%30 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%31 = load i32, i32* %30
%32 = call i32 @print_permissions(i32 %31)
%33 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 2
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 3
%38 = load i32, i32* %37
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %34, i32 %36, i32 %38)
%40 = load i32, i32* %11
%41 = load i32, i32* @S_IFCHR
%42 = icmp eq i32 %40, %41
br i1 %42, label %47, label %43
43: ; preds = %23
%44 = load i32, i32* %11
%45 = load i32, i32* @S_IFBLK
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %55
47: ; preds = %43, %23
%48 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 4
%49 = load i32, i32* %48
%50 = ashr i32 %49, 16
%51 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 4
%52 = load i32, i32* %51
%53 = and i32 %52, 65535
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %50, i32 %53)
br label %75
55: ; preds = %43
%56 = load i32, i32* %6
%57 = call i32 @ilog10(i32 %56)
%58 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 5
%59 = load i32, i32* %58
%60 = call i32 @ilog10(i32 %59)
%61 = sub nsw i32 %57, %60
store i32 %61, i32* %8
store i32 0, i32* %9
br label %62
62: ; preds = %68, %55
%63 = load i32, i32* %9
%64 = load i32, i32* %8
%65 = icmp slt i32 %63, %64
br i1 %65, label %66, label %71
66: ; preds = %62
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66
%69 = load i32, i32* %9
%70 = add nsw i32 %69, 1
store i32 %70, i32* %9
br label %62
71: ; preds = %62
%72 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 5
%73 = load i32, i32* %72
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %71, %47
%76 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 6
%77 = load i32, i32* %76
%78 = call i32 @print_date(i32 %77)
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%80 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%81 = load i32, i32* %80
%82 = load i8*, i8** %4
%83 = call i32 @print_file_color(i32 %81, i8* %82)
%84 = call i32 (i8*, ...) @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, i32, i32, i32, i32, i32, i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@S_IFMT = global i32 0
@.str.2 = [12 x i8] c" %2d %d %d \00"
@S_IFCHR = global i32 0
@S_IFBLK = global i32 0
@.str.3 = [8 x i8] c"%d, %d \00"
@.str.5 = [6 x i8] c"%lld \00"
define void @list_file_long(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = alloca [256 x i8]
%6 = bitcast %struct.stat* %4 to i8*
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %1, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %13
11: ; preds = %3
%12 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0)
br label %13
13: ; preds = %11, %9
%14 = call i32 @stat(i8* %7, %struct.stat* %4)
%15 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @S_IFMT
%18 = and i32 %17, %16
%19 = call i32 @print_permissions(i32 %16)
%20 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 3
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %23, i32 %25)
%27 = load i32, i32* @S_IFCHR
%28 = icmp eq i32 %18, %27
%29 = load i32, i32* @S_IFBLK
%30 = icmp eq i32 %18, %29
%31 = select i1 %28, i1 true, i1 %30
br i1 %31, label %32, label %38
32: ; preds = %13
%33 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 4
%34 = load i32, i32* %33
%35 = ashr i32 %34, 16
%36 = and i32 %34, 65535
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %35, i32 %36)
br label %52
38: ; preds = %13
%39 = call i32 @ilog10(i32 %2)
%40 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 5
%41 = load i32, i32* %40
%42 = call i32 @ilog10(i32 %41)
%43 = sub i32 %39, %42
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %38, %45
%46 = phi i32 [ %48, %45 ], [ 0, %38 ]
%47 = call i32 @putchar(i32 32)
%48 = add nuw nsw i32 %46, 1
%49 = icmp eq i32 %48, %43
br i1 %49, label %50, label %45
50: ; preds = %45, %38
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i32 %41)
br label %52
52: ; preds = %50, %32
%53 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 6
%54 = load i32, i32* %53
%55 = call i32 @print_date(i32 %54)
%56 = call i32 @putchar(i32 32)
%57 = call i32 @print_file_color(i32 %16, i8* %0)
%58 = call i32 @putchar(i32 10)
ret void
}