#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*/ sizes;
typedef int /*<<< orphan*/ sizeof_code;

/* Variables and functions */
scalar_t__ chaz_CC_test_compile(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char const *, char const *, char const *,
                           int);
int strlen(char const *);
int chaz_HeadCheck_size_of_type(const char *type, const char *includes,
                                int hint) {
  static const char sizeof_code[] = "#include <stddef.h>"
                                    "\n"
                                    "%s"
                                    "\n"
                                    "int a[sizeof(%s)==%d?1:-1];"
                                    "\n";
  size_t needed = sizeof(sizeof_code) + strlen(type) + strlen(includes) + 10;
  char *buf = (char *)malloc(needed);
  static const int sizes[] = {4, 8, 2, 1};
  int retval = 0;
  int i;
  for (i = -1; i < (int)(sizeof(sizes) / sizeof(sizes[0])); i++) {
    int size;
    if (i < 0) {
      if (hint != 0) {
        size = hint;
      } else {
        continue;
      }
    } else {
      if (sizes[i] != hint) {
        size = sizes[i];
      } else {
        continue;
      }
    }
    sprintf(buf, sizeof_code, includes, type, size);
    if (chaz_CC_test_compile(buf)) {
      retval = size;
      break;
    }
  }
  free(buf);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_HeadCheck_size_of_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x34,%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xa,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0xffffffff,-0x30(%rbp)
cmpl   $0x4,-0x30(%rbp)
jge    1265 <chaz_HeadCheck_size_of_type+0x115>
cmpl   $0x0,-0x30(%rbp)
jge    11e1 <chaz_HeadCheck_size_of_type+0x91>
cmpl   $0x0,-0x14(%rbp)
je     11d7 <chaz_HeadCheck_size_of_type+0x87>
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    11dc <chaz_HeadCheck_size_of_type+0x8c>
jmp    1257 <chaz_HeadCheck_size_of_type+0x107>
jmp    1218 <chaz_HeadCheck_size_of_type+0xc8>
movslq -0x30(%rbp),%rcx
lea    0xe54(%rip),%rax
mov    (%rax,%rcx,4),%eax
cmp    -0x14(%rbp),%eax
je     120e <chaz_HeadCheck_size_of_type+0xbe>
movslq -0x30(%rbp),%rcx
lea    0xe3d(%rip),%rax
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x34(%rbp)
jmp    1213 <chaz_HeadCheck_size_of_type+0xc3>
jmp    1257 <chaz_HeadCheck_size_of_type+0x107>
jmp    1218 <chaz_HeadCheck_size_of_type+0xc8>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x34(%rbp),%r8d
lea    0xdd1(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <chaz_CC_test_compile@plt>
cmp    $0x0,%rax
je     1252 <chaz_HeadCheck_size_of_type+0x102>
mov    -0x34(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1265 <chaz_HeadCheck_size_of_type+0x115>
jmp    1257 <chaz_HeadCheck_size_of_type+0x107>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11ae <chaz_HeadCheck_size_of_type+0x5e>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_HeadCheck_size_of_type>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %rsi,%r15
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x3e,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
test   %r12d,%r12d
je     11bb <chaz_HeadCheck_size_of_type+0x6b>
lea    0xe71(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12d,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <chaz_CC_test_compile@plt>
test   %rax,%rax
je     11b5 <chaz_HeadCheck_size_of_type+0x65>
mov    %r12d,%ebp
jmp    1286 <chaz_HeadCheck_size_of_type+0x136>
cmp    $0x4,%r12d
je     11f2 <chaz_HeadCheck_size_of_type+0xa2>
lea    0xe3e(%rip),%rsi
mov    $0x4,%ebp
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x4,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <chaz_CC_test_compile@plt>
test   %rax,%rax
jne    1286 <chaz_HeadCheck_size_of_type+0x136>
cmp    $0x8,%r12d
je     1225 <chaz_HeadCheck_size_of_type+0xd5>
lea    0xe07(%rip),%rsi
mov    $0x8,%ebp
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x8,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <chaz_CC_test_compile@plt>
test   %rax,%rax
jne    1286 <chaz_HeadCheck_size_of_type+0x136>
cmp    $0x2,%r12d
je     125a <chaz_HeadCheck_size_of_type+0x10a>
lea    0xdd4(%rip),%rsi
mov    $0x2,%ebp
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x2,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <chaz_CC_test_compile@plt>
test   %rax,%rax
jne    1286 <chaz_HeadCheck_size_of_type+0x136>
xor    %ebp,%ebp
cmp    $0x1,%r12d
je     1286 <chaz_HeadCheck_size_of_type+0x136>
lea    0xd9f(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
mov    $0x1,%r8d
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <chaz_CC_test_compile@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@chaz_HeadCheck_size_of_type.sizeof_code = internal constant [52 x i8] c"#include <stddef.h>\0A%s\0Aint a[sizeof(%s)==%d?1:-1];\0A\00"
@chaz_HeadCheck_size_of_type.sizes = internal constant [4 x i32] [i32 4, i32 8, i32 2, i32 1]
define i32 @chaz_HeadCheck_size_of_type(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%12 = load i8*, i8** %4
%13 = call i32 @strlen(i8* %12)
%14 = sext i32 %13 to i64
%15 = add i64 52, %14
%16 = load i8*, i8** %5
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = add i64 %15, %18
%20 = add i64 %19, 10
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = call i64 @malloc(i64 %21)
%23 = inttoptr i64 %22 to i8*
store i8* %23, i8** %8
store i32 0, i32* %9
store i32 -1, i32* %10
br label %24
24: ; preds = %63, %3
%25 = load i32, i32* %10
%26 = icmp slt i32 %25, 4
br i1 %26, label %27, label %66
27: ; preds = %24
%28 = load i32, i32* %10
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %27
%31 = load i32, i32* %6
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = load i32, i32* %6
store i32 %34, i32* %11
br label %36
35: ; preds = %30
br label %63
36: ; preds = %33
br label %51
37: ; preds = %27
%38 = load i32, i32* %10
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [4 x i32], [4 x i32]* @chaz_HeadCheck_size_of_type.sizes, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = load i32, i32* %6
%43 = icmp ne i32 %41, %42
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = load i32, i32* %10
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [4 x i32], [4 x i32]* @chaz_HeadCheck_size_of_type.sizes, i64 0, i64 %46
%48 = load i32, i32* %47
store i32 %48, i32* %11
br label %50
49: ; preds = %37
br label %63
50: ; preds = %44
br label %51
51: ; preds = %50, %36
%52 = load i8*, i8** %8
%53 = load i8*, i8** %5
%54 = load i8*, i8** %4
%55 = load i32, i32* %11
%56 = call i32 @sprintf(i8* %52, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @chaz_HeadCheck_size_of_type.sizeof_code, i64 0, i64 0), i8* %53, i8* %54, i32 %55)
%57 = load i8*, i8** %8
%58 = call i64 @chaz_CC_test_compile(i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %62
60: ; preds = %51
%61 = load i32, i32* %11
store i32 %61, i32* %9
br label %66
62: ; preds = %51
br label %63
63: ; preds = %62, %49, %35
%64 = load i32, i32* %10
%65 = add nsw i32 %64, 1
store i32 %65, i32* %10
br label %24
66: ; preds = %60, %24
%67 = load i8*, i8** %8
%68 = call i32 @free(i8* %67)
%69 = load i32, i32* %9
ret i32 %69
}

LLVM IR (-O2):
@chaz_HeadCheck_size_of_type.sizeof_code = internal constant [52 x i8] c"#include <stddef.h>\0A%s\0Aint a[sizeof(%s)==%d?1:-1];\0A\00"
define i32 @chaz_HeadCheck_size_of_type(i8* %0, i8* %1, i32 %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = sext i32 %4 to i64
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = add nsw i64 %5, 62
%9 = add nsw i64 %8, %7
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = icmp eq i32 %2, 0
br i1 %12, label %19, label %13
13: ; preds = %3
%14 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @chaz_HeadCheck_size_of_type.sizeof_code, i64 0, i64 0), i8* %1, i8* %0, i32 %2)
%15 = tail call i64 @chaz_CC_test_compile(i8* %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %42
17: ; preds = %13
%18 = icmp eq i32 %2, 4
br i1 %18, label %25, label %19
19: ; preds = %3, %17
%20 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @chaz_HeadCheck_size_of_type.sizeof_code, i64 0, i64 0), i8* %1, i8* %0, i32 4)
%21 = tail call i64 @chaz_CC_test_compile(i8* %11)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %42
23: ; preds = %19
%24 = icmp eq i32 %2, 8
br i1 %24, label %31, label %25
25: ; preds = %17, %23
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @chaz_HeadCheck_size_of_type.sizeof_code, i64 0, i64 0), i8* %1, i8* %0, i32 8)
%27 = tail call i64 @chaz_CC_test_compile(i8* %11)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = icmp eq i32 %2, 2
br i1 %30, label %37, label %31
31: ; preds = %23, %29
%32 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @chaz_HeadCheck_size_of_type.sizeof_code, i64 0, i64 0), i8* %1, i8* %0, i32 2)
%33 = tail call i64 @chaz_CC_test_compile(i8* %11)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %42
35: ; preds = %31
%36 = icmp eq i32 %2, 1
br i1 %36, label %42, label %37
37: ; preds = %29, %35
%38 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @chaz_HeadCheck_size_of_type.sizeof_code, i64 0, i64 0), i8* %1, i8* %0, i32 1)
%39 = tail call i64 @chaz_CC_test_compile(i8* %11)
%40 = icmp ne i64 %39, 0
%41 = zext i1 %40 to i32
br label %42
42: ; preds = %37, %35, %31, %25, %19, %13
%43 = phi i32 [ %2, %13 ], [ 4, %19 ], [ 8, %25 ], [ 2, %31 ], [ %41, %37 ], [ 0, %35 ]
%44 = tail call i32 @free(i8* %11)
ret i32 %43
}