#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 */
typedef scalar_t__ uint32_t;

/* Variables and functions */
scalar_t__ strlen(char *);
uint32_t get_header_instance_length(char **files, int count) {
  int i;
  uint32_t longest = 0;
  for (i = 0; i < count; i++) {
    uint32_t len = strlen(files[i]) + 1;
    if (len > longest) {
      longest = len;
    }
  }
  return (longest / 16) * 16 + 32;
}


x86 assembly (clang, -O0):
<get_header_instance_length>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117c <get_header_instance_length+0x6c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jle    1169 <get_header_instance_length+0x59>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    116e <get_header_instance_length+0x5e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <get_header_instance_length+0x1e>
mov    -0x18(%rbp),%rax
mov    $0x10,%ecx
cqto
idiv   %rcx
shl    $0x4,%rax
add    $0x20,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header_instance_length>:
test   %esi,%esi
jle    116f <get_header_instance_length+0x5f>
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
mov    %rcx,%r12
mov    (%r14,%rbx,8),%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rcx
cmp    %r12,%rax
cmovl  %r12,%rcx
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <get_header_instance_length+0x20>
lea    0xf(%rcx),%rax
test   %rcx,%rcx
cmovns %rcx,%rax
and    $0xfffffffffffffff0,%rax
add    $0x20,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    $0x20,%eax
ret

LLVM IR (-O0):
define i64 @get_header_instance_length(i8** %0, i32 %1) {
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i8** %0, i8*** %3
store i32 %1, i32* %4
store i64 0, i64* %6
store i32 0, i32* %5
br label %8
8: ; preds = %26, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load i8**, i8*** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 %18, 1
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = load i64, i64* %6
%22 = icmp sgt i64 %20, %21
br i1 %22, label %23, label %25
23: ; preds = %12
%24 = load i64, i64* %7
store i64 %24, i64* %6
br label %25
25: ; preds = %23, %12
br label %26
26: ; preds = %25
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
store i32 %28, i32* %5
br label %8
29: ; preds = %8
%30 = load i64, i64* %6
%31 = sdiv i64 %30, 16
%32 = mul nsw i64 %31, 16
%33 = add nsw i64 %32, 32
ret i64 %33
}

LLVM IR (-O2):
define i64 @get_header_instance_length(i8** nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %21
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %15, %6 ]
%8 = phi i64 [ 0, %4 ], [ %14, %6 ]
%9 = getelementptr inbounds i8*, i8** %0, i64 %7
%10 = load i8*, i8** %9
%11 = tail call i64 @strlen(i8* dereferenceable(1) %10)
%12 = icmp slt i64 %11, %8
%13 = add nsw i64 %11, 1
%14 = select i1 %12, i64 %8, i64 %13
%15 = add nuw nsw i64 %7, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %17, label %6
17: ; preds = %6
%18 = sdiv i64 %14, 16
%19 = shl nsw i64 %18, 4
%20 = add i64 %19, 32
br label %21
21: ; preds = %17, %2
%22 = phi i64 [ 32, %2 ], [ %20, %17 ]
ret i64 %22
}