#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*/ defines_code;

/* Variables and functions */
int chaz_CC_test_compile(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(long);
int /*<<< orphan*/ sprintf(char *, char const *, char const *, char const *,
                           char const *);
int strlen(char const *);
int chaz_HeadCheck_defines_symbol(const char *symbol, const char *includes) {
  static const char defines_code[] = "%s"
                                     "\n"
                                     "int main() {"
                                     "\n"
                                     "#ifdef %s"
                                     "\n"
                                     "return 0;"
                                     "\n"
                                     "#else"
                                     "\n"
                                     "return (int)&%s;"
                                     "\n"
                                     "#endif"
                                     "\n"
                                     "}"
                                     "\n";
  long needed =
      sizeof(defines_code) + 2 * strlen(symbol) + strlen(includes) + 10;
  char *buf = (char *)malloc(needed);
  int retval;
  sprintf(buf, defines_code, includes, symbol, symbol);
  retval = chaz_CC_test_compile(buf);
  free(buf);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_HeadCheck_defines_symbol>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
shl    $0x1,%eax
cltq
add    $0x45,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xa,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe49(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rdi
call   1060 <chaz_CC_test_compile@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_HeadCheck_defines_symbol>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
add    %eax,%eax
movslq %eax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0x4f,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe78(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r15,%r8
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <chaz_CC_test_compile@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@chaz_HeadCheck_defines_symbol.defines_code = internal constant [69 x i8] c"%s\0Aint main() {\0A#ifdef %s\0Areturn 0;\0A#else\0Areturn (int)&%s;\0A#endif\0A}\0A\00"
define i32 @chaz_HeadCheck_defines_symbol(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = mul nsw i32 2, %9
%11 = sext i32 %10 to i64
%12 = add i64 69, %11
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = sext i32 %14 to i64
%16 = add i64 %12, %15
%17 = add i64 %16, 10
store i64 %17, i64* %5
%18 = load i64, i64* %5
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8*, i8** %4
%23 = load i8*, i8** %3
%24 = load i8*, i8** %3
%25 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @chaz_HeadCheck_defines_symbol.defines_code, i64 0, i64 0), i8* %22, i8* %23, i8* %24)
%26 = load i8*, i8** %6
%27 = call i32 @chaz_CC_test_compile(i8* %26)
store i32 %27, i32* %7
%28 = load i8*, i8** %6
%29 = call i32 @free(i8* %28)
%30 = load i32, i32* %7
ret i32 %30
}

LLVM IR (-O2):
@chaz_HeadCheck_defines_symbol.defines_code = internal constant [69 x i8] c"%s\0Aint main() {\0A#ifdef %s\0Areturn 0;\0A#else\0Areturn (int)&%s;\0A#endif\0A}\0A\00"
define i32 @chaz_HeadCheck_defines_symbol(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = shl nsw i32 %3, 1
%5 = sext i32 %4 to i64
%6 = tail call i32 @strlen(i8* %1)
%7 = sext i32 %6 to i64
%8 = add nsw i64 %5, 79
%9 = add nsw i64 %8, %7
%10 = tail call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @sprintf(i8* dereferenceable(1) %11, i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @chaz_HeadCheck_defines_symbol.defines_code, i64 0, i64 0), i8* %1, i8* %0, i8* %0)
%13 = tail call i32 @chaz_CC_test_compile(i8* %11)
%14 = tail call i32 @free(i8* %11)
ret i32 %13
}