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

/* Variables and functions */
int INT_MAX;
int PATH_MAX;
int S_IFDIR;
int S_IFMT;
int S_IFREG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ lstat(char *, struct stat *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void smallest(char **paths, int num_paths, char expr) {
  int smallest = INT_MAX;
  char *l = malloc(sizeof(char) * PATH_MAX);
  int i;
  for (i = 0; i < num_paths; i++) {
    DIR *direct = opendir(paths[i]);
    struct dirent *item;
    while ((item = readdir(direct)) != NULL) {
      char *it = malloc(sizeof(char) * PATH_MAX);
      strcpy(it, paths[i]);
      strcat(it, "/");
      strcat(it, item->d_name);
      struct stat sts;
      lstat(it, &sts);
      if (strcmp(item->d_name, ".") != 0 && strcmp(item->d_name, "..") != 0) {
        if (expr == 'd' && S_IFDIR == (sts.st_mode & S_IFMT)) {
          if (sts.st_size < smallest) {
            strcpy(l, it);
            smallest = sts.st_size;
          }
        } else if (expr == 'f' && S_IFREG == (sts.st_mode & S_IFMT)) {
          if (sts.st_size < smallest) {
            strcpy(l, it);
            smallest = sts.st_size;
          }
        }
      }
      free(it);
    }
    closedir(direct);
  }
  printf("The smallest file found was %s\n", l);
  free(l);
}


x86 assembly (clang, -O0):
<smallest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e29(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1378 <smallest+0x1d8>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1361 <smallest+0x1c1>
mov    0x2dd1(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
call   10c0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   1080 <lstat@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd82(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1353 <smallest+0x1b3>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd64(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1353 <smallest+0x1b3>
movsbl -0xd(%rbp),%eax
cmp    $0x64,%eax
jne    12fb <smallest+0x15b>
mov    0x2cf7(%rip),%rax
mov    (%rax),%eax
mov    -0x48(%rbp),%ecx
mov    0x2cfb(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
jne    12fb <smallest+0x15b>
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    12f6 <smallest+0x156>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    134e <smallest+0x1ae>
movsbl -0xd(%rbp),%eax
cmp    $0x66,%eax
jne    1349 <smallest+0x1a9>
mov    0x2cc9(%rip),%rax
mov    (%rax),%eax
mov    -0x48(%rbp),%ecx
mov    0x2cad(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
jne    1349 <smallest+0x1a9>
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1344 <smallest+0x1a4>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1349 <smallest+0x1a9>
jmp    134e <smallest+0x1ae>
jmp    1353 <smallest+0x1b3>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    1201 <smallest+0x61>
mov    -0x30(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11e0 <smallest+0x40>
mov    -0x20(%rbp),%rsi
lea    0xc82(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<smallest>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edx,0x14(%rsp)
mov    %esi,%r14d
mov    %rdi,%rbx
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %r14d,%r14d
jle    1328 <smallest+0x188>
mov    %r14d,%eax
mov    %rax,0x20(%rsp)
xor    %r13d,%r13d
jmp    1207 <smallest+0x67>
xchg   %ax,%ax
mov    %r14,%rdi
call   1070 <closedir@plt>
add    $0x1,%r13
cmp    0x20(%rsp),%r13
je     1328 <smallest+0x188>
mov    (%rbx,%r13,8),%rdi
call   1050 <opendir@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     11f0 <smallest+0x50>
mov    %rax,%r12
jmp    1248 <smallest+0xa8>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     11f0 <smallest+0x50>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,%r15
mov    (%rbx,%r13,8),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r15,%rdi
lea    0xd91(%rip),%rsi
call   10c0 <strcat@plt>
mov    (%r12),%rsi
mov    %r15,%rdi
call   10c0 <strcat@plt>
mov    %r15,%rdi
lea    0x8(%rsp),%rsi
call   1080 <lstat@plt>
mov    (%r12),%rdi
lea    0xd6b(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1230 <smallest+0x90>
mov    (%r12),%rdi
lea    0xd55(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1230 <smallest+0x90>
mov    0x14(%rsp),%eax
cmp    $0x66,%al
je     12e8 <smallest+0x148>
cmp    $0x64,%al
jne    1230 <smallest+0x90>
mov    0x2cf6(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2cd9(%rip),%rcx
cmp    %eax,(%rcx)
je     1304 <smallest+0x164>
jmp    1230 <smallest+0x90>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2cdc(%rip),%rcx
cmp    %eax,(%rcx)
jne    1230 <smallest+0x90>
mov    0xc(%rsp),%ebp
cmp    0x4(%rsp),%ebp
jge    1230 <smallest+0x90>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %ebp,0x4(%rsp)
jmp    1230 <smallest+0x90>
lea    0xcd6(%rip),%rdi
mov    0x18(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <printf@plt>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32 }
@INT_MAX = global i32 0
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@S_IFDIR = global i32 0
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@.str.3 = [32 x i8] c"The smallest file found was %s\0A\00"
define void @smallest(i8** %0, i32 %1, i8 signext %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca i8*
%13 = alloca %struct.stat
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i8 %2, i8* %6
%14 = load i32, i32* @INT_MAX
store i32 %14, i32* %7
%15 = load i32, i32* @PATH_MAX
%16 = sext i32 %15 to i64
%17 = mul i64 1, %16
%18 = trunc i64 %17 to i32
%19 = call i8* @malloc(i32 %18)
store i8* %19, i8** %8
store i32 0, i32* %9
br label %20
20: ; preds = %122, %3
%21 = load i32, i32* %9
%22 = load i32, i32* %5
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %125
24: ; preds = %20
%25 = load i8**, i8*** %4
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32* @opendir(i8* %29)
store i32* %30, i32** %10
br label %31
31: ; preds = %116, %24
%32 = load i32*, i32** %10
%33 = call %struct.dirent* @readdir(i32* %32)
store %struct.dirent* %33, %struct.dirent** %11
%34 = icmp ne %struct.dirent* %33, null
br i1 %34, label %35, label %119
35: ; preds = %31
%36 = load i32, i32* @PATH_MAX
%37 = sext i32 %36 to i64
%38 = mul i64 1, %37
%39 = trunc i64 %38 to i32
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %12
%41 = load i8*, i8** %12
%42 = load i8**, i8*** %4
%43 = load i32, i32* %9
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %42, i64 %44
%46 = load i8*, i8** %45
%47 = call i32 @strcpy(i8* %41, i8* %46)
%48 = load i8*, i8** %12
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%50 = load i8*, i8** %12
%51 = load %struct.dirent*, %struct.dirent** %11
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = call i32 @strcat(i8* %50, i8* %53)
%55 = load i8*, i8** %12
%56 = call i32 @lstat(i8* %55, %struct.stat* %13)
%57 = load %struct.dirent*, %struct.dirent** %11
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %116
62: ; preds = %35
%63 = load %struct.dirent*, %struct.dirent** %11
%64 = getelementptr inbounds %struct.dirent, %struct.dirent* %63, i32 0, i32 0
%65 = load i8*, i8** %64
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %116
68: ; preds = %62
%69 = load i8, i8* %6
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 100
br i1 %71, label %72, label %91
72: ; preds = %68
%73 = load i32, i32* @S_IFDIR
%74 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%75 = load i32, i32* %74
%76 = load i32, i32* @S_IFMT
%77 = and i32 %75, %76
%78 = icmp eq i32 %73, %77
br i1 %78, label %79, label %91
79: ; preds = %72
%80 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%81 = load i32, i32* %80
%82 = load i32, i32* %7
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %90
84: ; preds = %79
%85 = load i8*, i8** %8
%86 = load i8*, i8** %12
%87 = call i32 @strcpy(i8* %85, i8* %86)
%88 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%89 = load i32, i32* %88
store i32 %89, i32* %7
br label %90
90: ; preds = %84, %79
br label %115
91: ; preds = %72, %68
%92 = load i8, i8* %6
%93 = sext i8 %92 to i32
%94 = icmp eq i32 %93, 102
br i1 %94, label %95, label %114
95: ; preds = %91
%96 = load i32, i32* @S_IFREG
%97 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%98 = load i32, i32* %97
%99 = load i32, i32* @S_IFMT
%100 = and i32 %98, %99
%101 = icmp eq i32 %96, %100
br i1 %101, label %102, label %114
102: ; preds = %95
%103 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%104 = load i32, i32* %103
%105 = load i32, i32* %7
%106 = icmp slt i32 %104, %105
br i1 %106, label %107, label %113
107: ; preds = %102
%108 = load i8*, i8** %8
%109 = load i8*, i8** %12
%110 = call i32 @strcpy(i8* %108, i8* %109)
%111 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%112 = load i32, i32* %111
store i32 %112, i32* %7
br label %113
113: ; preds = %107, %102
br label %114
114: ; preds = %113, %95, %91
br label %115
115: ; preds = %114, %90
br label %116
116: ; preds = %115, %62, %35
%117 = load i8*, i8** %12
%118 = call i32 @free(i8* %117)
br label %31
119: ; preds = %31
%120 = load i32*, i32** %10
%121 = call i32 @closedir(i32* %120)
br label %122
122: ; preds = %119
%123 = load i32, i32* %9
%124 = add nsw i32 %123, 1
store i32 %124, i32* %9
br label %20
125: ; preds = %20
%126 = load i8*, i8** %8
%127 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %126)
%128 = load i8*, i8** %8
%129 = call i32 @free(i8* %128)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.dirent = type { i8* }
@INT_MAX = global i32 0
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@S_IFDIR = global i32 0
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@.str.3 = [32 x i8] c"The smallest file found was %s\0A\00"
define void @smallest(i8** nocapture %0, i32 %1, i8 signext %2) {
%4 = alloca %struct.stat
%5 = load i32, i32* @INT_MAX
%6 = load i32, i32* @PATH_MAX
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %73
9: ; preds = %3
%10 = bitcast %struct.stat* %4 to i8*
%11 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%13 = zext i32 %1 to i64
br label %14
14: ; preds = %9, %68
%15 = phi i64 [ 0, %9 ], [ %71, %68 ]
%16 = phi i32 [ %5, %9 ], [ %69, %68 ]
%17 = getelementptr inbounds i8*, i8** %0, i64 %15
%18 = load i8*, i8** %17
%19 = tail call i32* @opendir(i8* %18)
%20 = tail call %struct.dirent* @readdir(i32* %19)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %68, label %22
22: ; preds = %14, %63
%23 = phi %struct.dirent* [ %66, %63 ], [ %20, %14 ]
%24 = phi i32 [ %64, %63 ], [ %16, %14 ]
%25 = load i32, i32* @PATH_MAX
%26 = tail call i8* @malloc(i32 %25)
%27 = load i8*, i8** %17
%28 = tail call i32 @strcpy(i8* %26, i8* %27)
%29 = tail call i32 @strcat(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%31 = load i8*, i8** %30
%32 = tail call i32 @strcat(i8* %26, i8* %31)
%33 = call i32 @lstat(i8* %26, %struct.stat* %4)
%34 = load i8*, i8** %30
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %63, label %37
37: ; preds = %22
%38 = load i8*, i8** %30
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %63, label %41
41: ; preds = %37
switch i8 %2, label %63 [
i8 100, label %42
i8 102, label %51
]
42: ; preds = %41
%43 = load i32, i32* @S_IFDIR
%44 = load i32, i32* %11
%45 = load i32, i32* @S_IFMT
%46 = and i32 %45, %44
%47 = icmp eq i32 %43, %46
%48 = load i32, i32* %12
%49 = icmp slt i32 %48, %24
%50 = select i1 %47, i1 %49, i1 false
br i1 %50, label %60, label %63
51: ; preds = %41
%52 = load i32, i32* @S_IFREG
%53 = load i32, i32* %11
%54 = load i32, i32* @S_IFMT
%55 = and i32 %54, %53
%56 = icmp eq i32 %52, %55
%57 = load i32, i32* %12
%58 = icmp slt i32 %57, %24
%59 = select i1 %56, i1 %58, i1 false
br i1 %59, label %60, label %63
60: ; preds = %51, %42
%61 = phi i32 [ %48, %42 ], [ %57, %51 ]
%62 = tail call i32 @strcpy(i8* %7, i8* %26)
br label %63
63: ; preds = %60, %42, %41, %51, %37, %22
%64 = phi i32 [ %24, %51 ], [ %24, %37 ], [ %24, %22 ], [ %24, %41 ], [ %24, %42 ], [ %61, %60 ]
%65 = tail call i32 @free(i8* %26)
%66 = tail call %struct.dirent* @readdir(i32* %19)
%67 = icmp eq %struct.dirent* %66, null
br i1 %67, label %68, label %22
68: ; preds = %63, %14
%69 = phi i32 [ %16, %14 ], [ %64, %63 ]
%70 = tail call i32 @closedir(i32* %19)
%71 = add nuw nsw i64 %15, 1
%72 = icmp eq i64 %71, %13
br i1 %72, label %73, label %14
73: ; preds = %68, %3
%74 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%75 = tail call i32 @free(i8* %7)
ret void
}