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

/* Variables and functions */
int chaz_CC_test_compile(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ sprintf(char *, char const *, char const *);
int strlen(char const *);
int chaz_CC_has_macro(const char *macro) {
  static const char template[] = "#ifdef %s"
                                 "\n"
                                 "int i;"
                                 "\n"
                                 "#else"
                                 "\n"
                                 "#error \"nope\""
                                 "\n"
                                 "#endif"
                                 "\n";
  size_t size = sizeof(template) + strlen(macro) + 20;
  char *code = (char *)malloc(size);
  int retval = 0;
  sprintf(code, template, macro);
  retval = chaz_CC_test_compile(code);
  free(code);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_CC_has_macro>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x2d,%rax
add    $0x14,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe6a(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <chaz_CC_test_compile@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_CC_has_macro>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
movslq %eax,%rdi
add    $0x41,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe8e(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
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
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@chaz_CC_has_macro.template = internal constant [45 x i8] c"#ifdef %s\0Aint i;\0A#else\0A#error \22nope\22\0A#endif\0A\00"
define i32 @chaz_CC_has_macro(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sext i32 %7 to i64
%9 = add i64 45, %8
%10 = add i64 %9, 20
store i64 %10, i64* %3
%11 = load i64, i64* %3
%12 = call i64 @malloc(i64 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %4
store i32 0, i32* %5
%14 = load i8*, i8** %4
%15 = load i8*, i8** %2
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @chaz_CC_has_macro.template, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %4
%18 = call i32 @chaz_CC_test_compile(i8* %17)
store i32 %18, i32* %5
%19 = load i8*, i8** %4
%20 = call i32 @free(i8* %19)
%21 = load i32, i32* %5
ret i32 %21
}

LLVM IR (-O2):
@chaz_CC_has_macro.template = internal constant [45 x i8] c"#ifdef %s\0Aint i;\0A#else\0A#error \22nope\22\0A#endif\0A\00"
define i32 @chaz_CC_has_macro(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = add nsw i64 %3, 65
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @sprintf(i8* dereferenceable(1) %6, i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @chaz_CC_has_macro.template, i64 0, i64 0), i8* %0)
%8 = tail call i32 @chaz_CC_test_compile(i8* %6)
%9 = tail call i32 @free(i8* %6)
ret i32 %8
}