#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 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 largest(char **paths, int num_paths, char expr) {
  int largest = 0;
  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 > largest) {
            strcpy(l, it);
            largest = sts.st_size;
          }
        } else if (expr == 'f' && S_IFREG == (sts.st_mode & S_IFMT)) {
          if (sts.st_size > largest) {
            strcpy(l, it);
            largest = sts.st_size;
          }
        }
      }
      free(it);
    }
    closedir(direct);
  }
  printf("The largest file found was %s\n", l);
  free(l);
}


x86 assembly (clang, -O0):
<largest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
movl   $0x0,-0x14(%rbp)
mov    0x2e2e(%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    1373 <largest+0x1d3>
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     135c <largest+0x1bc>
mov    0x2dd6(%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    0xdb4(%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    0xd87(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     134e <largest+0x1ae>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd69(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     134e <largest+0x1ae>
movsbl -0xd(%rbp),%eax
cmp    $0x64,%eax
jne    12f6 <largest+0x156>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    -0x48(%rbp),%ecx
mov    0x2d08(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
jne    12f6 <largest+0x156>
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    12f1 <largest+0x151>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1349 <largest+0x1a9>
movsbl -0xd(%rbp),%eax
cmp    $0x66,%eax
jne    1344 <largest+0x1a4>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    -0x48(%rbp),%ecx
mov    0x2cba(%rip),%rdx
and    (%rdx),%ecx
cmp    %ecx,%eax
jne    1344 <largest+0x1a4>
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    133f <largest+0x19f>
mov    -0x20(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1344 <largest+0x1a4>
jmp    1349 <largest+0x1a9>
jmp    134e <largest+0x1ae>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
jmp    11fc <largest+0x5c>
mov    -0x30(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11db <largest+0x3b>
mov    -0x20(%rbp),%rsi
lea    0xc87(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<largest>:
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    0x2e31(%rip),%rax
mov    (%rax),%edi
call   10b0 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %r14d,%r14d
jle    1328 <largest+0x188>
mov    %r14d,%eax
mov    %rax,0x20(%rsp)
xor    %r13d,%r13d
movl   $0x0,0x4(%rsp)
jmp    1207 <largest+0x67>
nopl   0x0(%rax)
mov    %r14,%rdi
call   1070 <closedir@plt>
add    $0x1,%r13
cmp    0x20(%rsp),%r13
je     1328 <largest+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 <largest+0x50>
mov    %rax,%r12
jmp    1248 <largest+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 <largest+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 <largest+0x90>
mov    (%r12),%rdi
lea    0xd55(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1230 <largest+0x90>
mov    0x14(%rsp),%eax
cmp    $0x66,%al
je     12e8 <largest+0x148>
cmp    $0x64,%al
jne    1230 <largest+0x90>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2ce1(%rip),%rcx
cmp    %eax,(%rcx)
je     1304 <largest+0x164>
jmp    1230 <largest+0x90>
mov    0x2ce1(%rip),%rax
mov    (%rax),%eax
and    0x8(%rsp),%eax
mov    0x2ce4(%rip),%rcx
cmp    %eax,(%rcx)
jne    1230 <largest+0x90>
mov    0xc(%rsp),%ebp
cmp    0x4(%rsp),%ebp
jle    1230 <largest+0x90>
mov    0x18(%rsp),%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %ebp,0x4(%rsp)
jmp    1230 <largest+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 }
@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 = [31 x i8] c"The largest file found was %s\0A\00"
define void @largest(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
store i32 0, i32* %7
%14 = load i32, i32* @PATH_MAX
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %8
store i32 0, i32* %9
br label %19
19: ; preds = %121, %3
%20 = load i32, i32* %9
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %124
23: ; preds = %19
%24 = load i8**, i8*** %4
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32* @opendir(i8* %28)
store i32* %29, i32** %10
br label %30
30: ; preds = %115, %23
%31 = load i32*, i32** %10
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %11
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %118
34: ; preds = %30
%35 = load i32, i32* @PATH_MAX
%36 = sext i32 %35 to i64
%37 = mul i64 1, %36
%38 = trunc i64 %37 to i32
%39 = call i8* @malloc(i32 %38)
store i8* %39, i8** %12
%40 = load i8*, i8** %12
%41 = load i8**, i8*** %4
%42 = load i32, i32* %9
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @strcpy(i8* %40, i8* %45)
%47 = load i8*, i8** %12
%48 = call i32 @strcat(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%49 = load i8*, i8** %12
%50 = load %struct.dirent*, %struct.dirent** %11
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = call i32 @strcat(i8* %49, i8* %52)
%54 = load i8*, i8** %12
%55 = call i32 @lstat(i8* %54, %struct.stat* %13)
%56 = load %struct.dirent*, %struct.dirent** %11
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %115
61: ; preds = %34
%62 = load %struct.dirent*, %struct.dirent** %11
%63 = getelementptr inbounds %struct.dirent, %struct.dirent* %62, i32 0, i32 0
%64 = load i8*, i8** %63
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %115
67: ; preds = %61
%68 = load i8, i8* %6
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 100
br i1 %70, label %71, label %90
71: ; preds = %67
%72 = load i32, i32* @S_IFDIR
%73 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%74 = load i32, i32* %73
%75 = load i32, i32* @S_IFMT
%76 = and i32 %74, %75
%77 = icmp eq i32 %72, %76
br i1 %77, label %78, label %90
78: ; preds = %71
%79 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%80 = load i32, i32* %79
%81 = load i32, i32* %7
%82 = icmp sgt i32 %80, %81
br i1 %82, label %83, label %89
83: ; preds = %78
%84 = load i8*, i8** %8
%85 = load i8*, i8** %12
%86 = call i32 @strcpy(i8* %84, i8* %85)
%87 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%88 = load i32, i32* %87
store i32 %88, i32* %7
br label %89
89: ; preds = %83, %78
br label %114
90: ; preds = %71, %67
%91 = load i8, i8* %6
%92 = sext i8 %91 to i32
%93 = icmp eq i32 %92, 102
br i1 %93, label %94, label %113
94: ; preds = %90
%95 = load i32, i32* @S_IFREG
%96 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%97 = load i32, i32* %96
%98 = load i32, i32* @S_IFMT
%99 = and i32 %97, %98
%100 = icmp eq i32 %95, %99
br i1 %100, label %101, label %113
101: ; preds = %94
%102 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%103 = load i32, i32* %102
%104 = load i32, i32* %7
%105 = icmp sgt i32 %103, %104
br i1 %105, label %106, label %112
106: ; preds = %101
%107 = load i8*, i8** %8
%108 = load i8*, i8** %12
%109 = call i32 @strcpy(i8* %107, i8* %108)
%110 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 1
%111 = load i32, i32* %110
store i32 %111, i32* %7
br label %112
112: ; preds = %106, %101
br label %113
113: ; preds = %112, %94, %90
br label %114
114: ; preds = %113, %89
br label %115
115: ; preds = %114, %61, %34
%116 = load i8*, i8** %12
%117 = call i32 @free(i8* %116)
br label %30
118: ; preds = %30
%119 = load i32*, i32** %10
%120 = call i32 @closedir(i32* %119)
br label %121
121: ; preds = %118
%122 = load i32, i32* %9
%123 = add nsw i32 %122, 1
store i32 %123, i32* %9
br label %19
124: ; preds = %19
%125 = load i8*, i8** %8
%126 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %125)
%127 = load i8*, i8** %8
%128 = call i32 @free(i8* %127)
ret void
}

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