#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_mtime;
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ archivefile(char *, int);
int /*<<< orphan*/ archivejoin(char *, char *, int);
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ writeheader(int, char *, int, int /*<<< orphan*/,
                               int /*<<< orphan*/, int /*<<< orphan*/,
                               int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  DIR *d;
  struct dirent *de;
  struct stat s;
  chdir("/proc");
  archivefile("meminfo", 1);
  archivefile("version", 1);
  d = opendir(".");
  while ((de = readdir(d)))
    if (de->d_name[0] >= '0' && de->d_name[0] <= '9') {
      stat(de->d_name, &s);
      writeheader(1, de->d_name, 0555, s.st_uid, s.st_gid, 0, s.st_mtime, 5);
      archivejoin(de->d_name, "smaps", 1);
      archivejoin(de->d_name, "cmdline", 1);
      archivejoin(de->d_name, "stat", 1);
    }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
call   1040 <chdir@plt>
lea    0xe6d(%rip),%rdi
mov    $0x1,%esi
call   1060 <archivefile@plt>
lea    0xe64(%rip),%rdi
mov    $0x1,%esi
call   1060 <archivefile@plt>
lea    0xe5b(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     128c <main+0x11c>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x30,%eax
jl     1287 <main+0x117>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x39,%eax
jg     1287 <main+0x117>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    -0x30(%rbp),%eax
mov    $0x1,%edi
mov    $0x16d,%edx
xor    %r9d,%r9d
mov    %eax,(%rsp)
movl   $0x5,0x8(%rsp)
call   1050 <writeheader@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcb(%rip),%rsi
mov    $0x1,%edx
call   1090 <archivejoin@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xdb9(%rip),%rsi
mov    $0x1,%edx
call   1090 <archivejoin@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xda9(%rip),%rsi
mov    $0x1,%edx
call   1090 <archivejoin@plt>
jmp    11c4 <main+0x54>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe7b(%rip),%rdi
call   1040 <chdir@plt>
lea    0xe75(%rip),%rdi
mov    $0x1,%esi
call   1060 <archivefile@plt>
lea    0xe6c(%rip),%rdi
mov    $0x1,%esi
call   1060 <archivefile@plt>
lea    0xe63(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     126f <main+0xff>
mov    %rax,%rbx
lea    0x8(%rsp),%r14
lea    0xe3d(%rip),%r15
lea    0xe3c(%rip),%r12
lea    0xe3d(%rip),%rbp
jmp    1200 <main+0x90>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     126f <main+0xff>
mov    (%rbx),%rdi
movzbl (%rdi),%eax
add    $0xd0,%al
cmp    $0x9,%al
ja     11f0 <main+0x80>
mov    %r14,%rsi
call   1070 <stat@plt>
mov    (%rbx),%rsi
mov    0x10(%rsp),%ecx
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%r8d
mov    $0x1,%edi
mov    $0x16d,%edx
xor    %r9d,%r9d
push   $0x5
push   %rax
call   1050 <writeheader@plt>
add    $0x10,%rsp
mov    (%rbx),%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1090 <archivejoin@plt>
mov    (%rbx),%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1090 <archivejoin@plt>
mov    (%rbx),%rdi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1090 <archivejoin@plt>
jmp    11f0 <main+0x80>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32, i32 }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [8 x i8] c"meminfo\00"
@.str.2 = [8 x i8] c"version\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [6 x i8] c"smaps\00"
@.str.5 = [8 x i8] c"cmdline\00"
@.str.6 = [5 x i8] c"stat\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @archivefile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
%11 = call i32 @archivefile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1)
%12 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %12, i32** %6
br label %13
13: ; preds = %60, %2
%14 = load i32*, i32** %6
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %7
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %61
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %7
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = getelementptr inbounds i8, i8* %20, i64 0
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp sge i32 %23, 48
br i1 %24, label %25, label %60
25: ; preds = %17
%26 = load %struct.dirent*, %struct.dirent** %7
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp sle i32 %31, 57
br i1 %32, label %33, label %60
33: ; preds = %25
%34 = load %struct.dirent*, %struct.dirent** %7
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @stat(i8* %36, %struct.stat* %8)
%38 = load %struct.dirent*, %struct.dirent** %7
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 2
%42 = load i32, i32* %41
%43 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 @writeheader(i32 1, i8* %40, i32 365, i32 %42, i32 %44, i32 0, i32 %46, i32 5)
%48 = load %struct.dirent*, %struct.dirent** %7
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = call i32 @archivejoin(i8* %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1)
%52 = load %struct.dirent*, %struct.dirent** %7
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = call i32 @archivejoin(i8* %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1)
%56 = load %struct.dirent*, %struct.dirent** %7
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i32 @archivejoin(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 1)
br label %60
60: ; preds = %33, %25, %17
br label %13
61: ; preds = %13
ret i32 0
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/proc\00"
@.str.1 = [8 x i8] c"meminfo\00"
@.str.2 = [8 x i8] c"version\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [6 x i8] c"smaps\00"
@.str.5 = [8 x i8] c"cmdline\00"
@.str.6 = [5 x i8] c"stat\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @chdir(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @archivefile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 1)
%7 = tail call i32 @archivefile(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 1)
%8 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%9 = tail call %struct.dirent* @readdir(i32* %8)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %38, label %11
11: ; preds = %2
%12 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 2
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 1
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %15
15: ; preds = %11, %35
%16 = phi %struct.dirent* [ %9, %11 ], [ %36, %35 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = add i8 %19, -48
%21 = icmp ult i8 %20, 10
br i1 %21, label %22, label %35
22: ; preds = %15
%23 = call i32 @stat(i8* %18, %struct.stat* %3)
%24 = load i8*, i8** %17
%25 = load i32, i32* %12
%26 = load i32, i32* %13
%27 = load i32, i32* %14
%28 = tail call i32 @writeheader(i32 1, i8* %24, i32 365, i32 %25, i32 %26, i32 0, i32 %27, i32 5)
%29 = load i8*, i8** %17
%30 = tail call i32 @archivejoin(i8* %29, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 1)
%31 = load i8*, i8** %17
%32 = tail call i32 @archivejoin(i8* %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 1)
%33 = load i8*, i8** %17
%34 = tail call i32 @archivejoin(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i32 1)
br label %35
35: ; preds = %22, %15
%36 = tail call %struct.dirent* @readdir(i32* %8)
%37 = icmp eq %struct.dirent* %36, null
br i1 %37, label %38, label %15
38: ; preds = %35, %2
ret i32 0
}