#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 int /*<<< orphan*/ test_code;

/* Variables and functions */
int chaz_CC_test_compile(char *);
int /*<<< orphan*/ chaz_HeadCheck_maybe_add_to_cache(char const *, int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strlen(char const *);
int chaz_HeadCheck_check_many_headers(const char **header_names) {
  static const char test_code[] = "int main() { return 0; }\n";
  int success;
  int i;
  char *code_buf;
  size_t needed = sizeof(test_code) + 20;
  for (i = 0; header_names[i] != NULL; i++) {
    needed += strlen(header_names[i]);
    needed += sizeof("#include <>\n");
  }
  code_buf = (char *)malloc(needed);
  code_buf[0] = '\0';
  for (i = 0; header_names[i] != NULL; i++) {
    strcat(code_buf, "#include <");
    strcat(code_buf, header_names[i]);
    strcat(code_buf, ">\n");
  }
  strcat(code_buf, test_code);
  success = chaz_CC_test_compile(code_buf);
  if (success) {
    for (i = 0; header_names[i] != NULL; i++) {
      chaz_HeadCheck_maybe_add_to_cache(header_names[i], 1);
    }
  }
  free(code_buf);
  return success;
}


x86 assembly (clang, -O0):
<chaz_HeadCheck_check_many_headers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x2e,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c1 <chaz_HeadCheck_check_many_headers+0x61>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1040 <strlen@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0xd,%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    117b <chaz_HeadCheck_check_many_headers+0x1b>
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1232 <chaz_HeadCheck_check_many_headers+0xd2>
mov    -0x18(%rbp),%rdi
lea    0xe20(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
lea    0xe06(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11dc <chaz_HeadCheck_check_many_headers+0x7c>
mov    -0x18(%rbp),%rdi
lea    0xdc3(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
call   1060 <chaz_CC_test_compile@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     129b <chaz_HeadCheck_check_many_headers+0x13b>
movl   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1296 <chaz_HeadCheck_check_many_headers+0x136>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x1,%esi
call   1070 <chaz_HeadCheck_maybe_add_to_cache@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    125f <chaz_HeadCheck_check_many_headers+0xff>
jmp    129b <chaz_HeadCheck_check_many_headers+0x13b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_HeadCheck_check_many_headers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    (%rdi),%rdi
test   %rdi,%rdi
je     119a <chaz_HeadCheck_check_many_headers+0x3a>
lea    0x8(%r13),%rbx
mov    $0x2e,%ebp
nop
call   1040 <strlen@plt>
add    %rax,%rbp
add    $0xd,%rbp
mov    (%rbx),%rdi
add    $0x8,%rbx
test   %rdi,%rdi
jne    1180 <chaz_HeadCheck_check_many_headers+0x20>
jmp    119f <chaz_HeadCheck_check_many_headers+0x3f>
mov    $0x2e,%ebp
mov    %rbp,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
movb   $0x0,(%rax)
cmpq   $0x0,0x0(%r13)
je     11fd <chaz_HeadCheck_check_many_headers+0x9d>
lea    0x8(%r13),%rbp
lea    0xe5b(%rip),%r15
lea    0xe5f(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
cmpq   $0x0,0x0(%rbp)
lea    0x8(%rbp),%rbp
jne    11d0 <chaz_HeadCheck_check_many_headers+0x70>
lea    0xdfc(%rip),%rsi
mov    %r14,%rdi
call   1080 <strcat@plt>
mov    %r14,%rdi
call   1060 <chaz_CC_test_compile@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1247 <chaz_HeadCheck_check_many_headers+0xe7>
mov    0x0(%r13),%rdi
test   %rdi,%rdi
je     1247 <chaz_HeadCheck_check_many_headers+0xe7>
add    $0x8,%r13
nopw   0x0(%rax,%rax,1)
mov    $0x1,%esi
call   1070 <chaz_HeadCheck_maybe_add_to_cache@plt>
mov    0x0(%r13),%rdi
add    $0x8,%r13
test   %rdi,%rdi
jne    1230 <chaz_HeadCheck_check_many_headers+0xd0>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@chaz_HeadCheck_check_many_headers.test_code = internal constant [26 x i8] c"int main() { return 0; }\0A\00"
@.str = [11 x i8] c"#include <\00"
@.str.1 = [3 x i8] c">\0A\00"
define i32 @chaz_HeadCheck_check_many_headers(i8** %0) {
%2 = alloca i8**
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
store i8** %0, i8*** %2
store i64 46, i64* %6
store i32 0, i32* %4
br label %7
7: ; preds = %25, %1
%8 = load i8**, i8*** %2
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %28
14: ; preds = %7
%15 = load i8**, i8*** %2
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i64 @strlen(i8* %19)
%21 = load i64, i64* %6
%22 = add i64 %21, %20
store i64 %22, i64* %6
%23 = load i64, i64* %6
%24 = add i64 %23, 13
store i64 %24, i64* %6
br label %25
25: ; preds = %14
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %7
28: ; preds = %7
%29 = load i64, i64* %6
%30 = call i64 @malloc(i64 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %5
%32 = load i8*, i8** %5
%33 = getelementptr inbounds i8, i8* %32, i64 0
store i8 0, i8* %33
store i32 0, i32* %4
br label %34
34: ; preds = %53, %28
%35 = load i8**, i8*** %2
%36 = load i32, i32* %4
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8*, i8** %35, i64 %37
%39 = load i8*, i8** %38
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %56
41: ; preds = %34
%42 = load i8*, i8** %5
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%44 = load i8*, i8** %5
%45 = load i8**, i8*** %2
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = call i32 @strcat(i8* %44, i8* %49)
%51 = load i8*, i8** %5
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
br label %53
53: ; preds = %41
%54 = load i32, i32* %4
%55 = add nsw i32 %54, 1
store i32 %55, i32* %4
br label %34
56: ; preds = %34
%57 = load i8*, i8** %5
%58 = call i32 @strcat(i8* %57, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @chaz_HeadCheck_check_many_headers.test_code, i64 0, i64 0))
%59 = load i8*, i8** %5
%60 = call i32 @chaz_CC_test_compile(i8* %59)
store i32 %60, i32* %3
%61 = load i32, i32* %3
%62 = icmp ne i32 %61, 0
br i1 %62, label %63, label %82
63: ; preds = %56
store i32 0, i32* %4
br label %64
64: ; preds = %78, %63
%65 = load i8**, i8*** %2
%66 = load i32, i32* %4
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = icmp ne i8* %69, null
br i1 %70, label %71, label %81
71: ; preds = %64
%72 = load i8**, i8*** %2
%73 = load i32, i32* %4
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = call i32 @chaz_HeadCheck_maybe_add_to_cache(i8* %76, i32 1)
br label %78
78: ; preds = %71
%79 = load i32, i32* %4
%80 = add nsw i32 %79, 1
store i32 %80, i32* %4
br label %64
81: ; preds = %64
br label %82
82: ; preds = %81, %56
%83 = load i8*, i8** %5
%84 = call i32 @free(i8* %83)
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
@chaz_HeadCheck_check_many_headers.test_code = internal constant [26 x i8] c"int main() { return 0; }\0A\00"
@.str = [11 x i8] c"#include <\00"
@.str.1 = [3 x i8] c">\0A\00"
define i32 @chaz_HeadCheck_check_many_headers(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = icmp eq i8* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %11, %4 ], [ 0, %1 ]
%6 = phi i8* [ %13, %4 ], [ %2, %1 ]
%7 = phi i64 [ %10, %4 ], [ 46, %1 ]
%8 = tail call i64 @strlen(i8* %6)
%9 = add i64 %7, 13
%10 = add i64 %9, %8
%11 = add nuw nsw i64 %5, 1
%12 = getelementptr inbounds i8*, i8** %0, i64 %11
%13 = load i8*, i8** %12
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %4
15: ; preds = %4, %1
%16 = phi i64 [ 46, %1 ], [ %10, %4 ]
%17 = tail call i64 @malloc(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8 0, i8* %18
%19 = load i8*, i8** %0
%20 = icmp eq i8* %19, null
br i1 %20, label %32, label %21
21: ; preds = %15, %21
%22 = phi i64 [ %28, %21 ], [ 0, %15 ]
%23 = phi i8** [ %29, %21 ], [ %0, %15 ]
%24 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %23
%26 = tail call i32 @strcat(i8* %18, i8* %25)
%27 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%28 = add nuw i64 %22, 1
%29 = getelementptr inbounds i8*, i8** %0, i64 %28
%30 = load i8*, i8** %29
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %21
32: ; preds = %21, %15
%33 = tail call i32 @strcat(i8* %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @chaz_HeadCheck_check_many_headers.test_code, i64 0, i64 0))
%34 = tail call i32 @chaz_CC_test_compile(i8* %18)
%35 = icmp eq i32 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %32
%37 = load i8*, i8** %0
%38 = icmp eq i8* %37, null
br i1 %38, label %47, label %39
39: ; preds = %36, %39
%40 = phi i64 [ %43, %39 ], [ 0, %36 ]
%41 = phi i8* [ %45, %39 ], [ %37, %36 ]
%42 = tail call i32 @chaz_HeadCheck_maybe_add_to_cache(i8* %41, i32 1)
%43 = add nuw i64 %40, 1
%44 = getelementptr inbounds i8*, i8** %0, i64 %43
%45 = load i8*, i8** %44
%46 = icmp eq i8* %45, null
br i1 %46, label %47, label %39
47: ; preds = %39, %36, %32
%48 = tail call i32 @free(i8* %18)
ret i32 %34
}