#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 /*<<< orphan*/ st_ctime;
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_atime;
};
struct dirent {
  scalar_t__ d_type;
  char *d_name;
  int d_fileno;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_REG;
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int, int /*<<< orphan*/,
                          int /*<<< orphan*/, int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int main() {
  DIR *TD;
  struct dirent *dp;
  struct stat inode;
  char path[512];
  if ((TD = opendir("/tmp")) == NULL) {
    perror("/tmp");
  }
  while ((dp = readdir(TD)) != NULL) {
    if (dp->d_type == DT_REG) {
      sprintf(path, "%s/%s", "/tmp", dp->d_name);
      if (stat(path, &inode) != 0) {
        perror(dp->d_name);
      }
      printf("aa %s, %i, %li %li %li\n", dp->d_name, dp->d_fileno,
             inode.st_atime, inode.st_mtime, inode.st_ctime);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1198 <main+0x38>
lea    0xe6d(%rip),%rdi
call   1070 <perror@plt>
jmp    119d <main+0x3d>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     123f <main+0xdf>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    0x2e1e(%rip),%rcx
cmp    (%rcx),%rax
jne    123a <main+0xda>
lea    -0x230(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe24(%rip),%rsi
lea    0xe18(%rip),%rdx
call   1080 <sprintf@plt>
lea    -0x230(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
cmp    $0x0,%rax
je     1214 <main+0xb4>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <perror@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x28(%rbp),%r9d
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
jmp    119d <main+0x3d>
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
lea    0xe88(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     123e <main+0xde>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     122a <main+0xca>
mov    %rax,%r14
mov    0x2e3c(%rip),%r15
lea    0x10(%rsp),%r12
mov    %rsp,%r13
lea    0xe58(%rip),%rbp
jmp    11ed <main+0x8d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%r14),%rsi
mov    0x10(%r14),%edx
mov    0x8(%rsp),%ecx
mov    (%rsp),%r9d
mov    0x4(%rsp),%r8d
mov    %rbp,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     122a <main+0xca>
mov    (%r14),%rax
cmp    (%r15),%rax
jne    11dd <main+0x7d>
mov    0x8(%r14),%rcx
mov    %r12,%rdi
lea    0xe02(%rip),%rsi
lea    0xdf6(%rip),%rdx
call   1080 <sprintf@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1050 <stat@plt>
test   %rax,%rax
je     11c0 <main+0x60>
mov    0x8(%r14),%rdi
call   1070 <perror@plt>
jmp    11c0 <main+0x60>
xor    %eax,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbb(%rip),%rdi
call   1070 <perror@plt>
jmp    1189 <main+0x29>

LLVM IR (-O0):
%struct.dirent = type { i64, i8*, i32 }
%struct.stat = type { i32, i32, i32 }
@.str = [5 x i8] c"/tmp\00"
@DT_REG = global i64 0
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [24 x i8] c"aa %s, %i, %li %li %li\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca %struct.stat
%5 = alloca [512 x i8]
store i32 0, i32* %1
%6 = call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %2
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
br label %11
11: ; preds = %49, %10
%12 = load i32*, i32** %2
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %3
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %50
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %3
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = load i64, i64* @DT_REG
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %49
21: ; preds = %15
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%23 = load %struct.dirent*, %struct.dirent** %3
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 1
%25 = load i8*, i8** %24
%26 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%28 = call i64 @stat(i8* %27, %struct.stat* %4)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %21
%31 = load %struct.dirent*, %struct.dirent** %3
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 1
%33 = load i8*, i8** %32
%34 = call i32 @perror(i8* %33)
br label %35
35: ; preds = %30, %21
%36 = load %struct.dirent*, %struct.dirent** %3
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 1
%38 = load i8*, i8** %37
%39 = load %struct.dirent*, %struct.dirent** %3
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 2
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 1
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.stat, %struct.stat* %4, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %38, i32 %41, i32 %43, i32 %45, i32 %47)
br label %49
49: ; preds = %35, %15
br label %11
50: ; preds = %11
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i64, i8*, i32 }
@.str = [5 x i8] c"/tmp\00"
@DT_REG = global i64 0
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [24 x i8] c"aa %s, %i, %li %li %li\0A\00"
define i32 @main() {
%1 = alloca %struct.stat
%2 = alloca [512 x i8]
%3 = bitcast %struct.stat* %1 to i8*
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @opendir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call %struct.dirent* @readdir(i32* %5)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %42, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
br label %16
16: ; preds = %12, %39
%17 = phi %struct.dirent* [ %10, %12 ], [ %40, %39 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i64, i64* %18
%20 = load i64, i64* @DT_REG
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %16
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 1
%24 = load i8*, i8** %23
%25 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = call i64 @stat(i8* %4, %struct.stat* %1)
%27 = icmp eq i64 %26, 0
br i1 %27, label %31, label %28
28: ; preds = %22
%29 = load i8*, i8** %23
%30 = call i32 @perror(i8* %29)
br label %31
31: ; preds = %28, %22
%32 = load i8*, i8** %23
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 2
%34 = load i32, i32* %33
%35 = load i32, i32* %13
%36 = load i32, i32* %14
%37 = load i32, i32* %15
%38 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %32, i32 %34, i32 %35, i32 %36, i32 %37)
br label %39
39: ; preds = %31, %16
%40 = call %struct.dirent* @readdir(i32* %5)
%41 = icmp eq %struct.dirent* %40, null
br i1 %41, label %42, label %16
42: ; preds = %39, %9
ret i32 0
}