#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 dirent {
  int /*<<< orphan*/ d_name;
};

/* Variables and functions */
int strlen(int /*<<< orphan*/);
int getMaxNameSize(struct dirent **allFiles) {
  struct dirent **fileHolder;
  int largestNameSize = 0;
  for (fileHolder = allFiles; *fileHolder != NULL; ++fileHolder) {
    int templength = strlen((*fileHolder)->d_name);
    if (templength > largestNameSize)
      largestNameSize = templength;
  }
  return largestNameSize;
}


x86 assembly (clang, -O0):
<getMaxNameSize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1172 <getMaxNameSize+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jle    115c <getMaxNameSize+0x4c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1161 <getMaxNameSize+0x51>
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
jmp    112b <getMaxNameSize+0x1b>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMaxNameSize>:
push   %rbp
push   %rbx
push   %rax
mov    (%rdi),%rax
test   %rax,%rax
je     114a <getMaxNameSize+0x3a>
mov    %rdi,%rbx
add    $0x8,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rax),%edi
call   1030 <strlen@plt>
cmp    %ebp,%eax
cmovg  %eax,%ebp
mov    (%rbx),%rax
add    $0x8,%rbx
test   %rax,%rax
jne    1130 <getMaxNameSize+0x20>
jmp    114c <getMaxNameSize+0x3c>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
define i32 @getMaxNameSize(%struct.dirent** %0) {
%2 = alloca %struct.dirent**
%3 = alloca %struct.dirent**
%4 = alloca i32
%5 = alloca i32
store %struct.dirent** %0, %struct.dirent*** %2
store i32 0, i32* %4
%6 = load %struct.dirent**, %struct.dirent*** %2
store %struct.dirent** %6, %struct.dirent*** %3
br label %7
7: ; preds = %23, %1
%8 = load %struct.dirent**, %struct.dirent*** %3
%9 = load %struct.dirent*, %struct.dirent** %8
%10 = icmp ne %struct.dirent* %9, null
br i1 %10, label %11, label %26
11: ; preds = %7
%12 = load %struct.dirent**, %struct.dirent*** %3
%13 = load %struct.dirent*, %struct.dirent** %12
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @strlen(i32 %15)
store i32 %16, i32* %5
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = load i32, i32* %5
store i32 %21, i32* %4
br label %22
22: ; preds = %20, %11
br label %23
23: ; preds = %22
%24 = load %struct.dirent**, %struct.dirent*** %3
%25 = getelementptr inbounds %struct.dirent*, %struct.dirent** %24, i32 1
store %struct.dirent** %25, %struct.dirent*** %3
br label %7
26: ; preds = %7
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
define i32 @getMaxNameSize(%struct.dirent** nocapture %0) {
%2 = load %struct.dirent*, %struct.dirent** %0
%3 = icmp eq %struct.dirent* %2, null
br i1 %3, label %16, label %4
4: ; preds = %1, %4
%5 = phi %struct.dirent* [ %14, %4 ], [ %2, %1 ]
%6 = phi %struct.dirent** [ %13, %4 ], [ %0, %1 ]
%7 = phi i32 [ %12, %4 ], [ 0, %1 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @strlen(i32 %9)
%11 = icmp sgt i32 %10, %7
%12 = select i1 %11, i32 %10, i32 %7
%13 = getelementptr inbounds %struct.dirent*, %struct.dirent** %6, i64 1
%14 = load %struct.dirent*, %struct.dirent** %13
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %16, label %4
16: ; preds = %4, %1
%17 = phi i32 [ 0, %1 ], [ %12, %4 ]
ret i32 %17
}