#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*/ contains_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_contains_member(const char *struct_name, const char *member,
                                   const char *includes) {
  static const char contains_code[] = "#include <stddef.h>"
                                      "\n"
                                      "%s"
                                      "\n"
                                      "int main() { return offsetof(%s, %s); }"
                                      "\n";
  long needed = sizeof(contains_code) + strlen(struct_name) + strlen(member) +
                strlen(includes) + 10;
  char *buf = (char *)malloc(needed);
  int retval;
  sprintf(buf, contains_code, includes, struct_name, member);
  retval = chaz_CC_test_compile(buf);
  free(buf);
  return retval;
}


x86 assembly (clang, -O0):
<chaz_HeadCheck_contains_member>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
cltq
add    $0x40,%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
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%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)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xe2f(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <chaz_CC_test_compile@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x2c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_HeadCheck_contains_member>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
call   1040 <strlen@plt>
movslq %eax,%rbx
mov    %r14,%rdi
call   1040 <strlen@plt>
movslq %eax,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
add    %rbx,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x4a,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe68(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%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
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@chaz_HeadCheck_contains_member.contains_code = internal constant [64 x i8] c"#include <stddef.h>\0A%s\0Aint main() { return offsetof(%s, %s); }\0A\00"
define i32 @chaz_HeadCheck_contains_member(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = add i64 64, %12
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = add i64 %13, %16
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = sext i32 %19 to i64
%21 = add i64 %17, %20
%22 = add i64 %21, 10
store i64 %22, i64* %7
%23 = load i64, i64* %7
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %8
%26 = load i8*, i8** %8
%27 = load i8*, i8** %6
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @chaz_HeadCheck_contains_member.contains_code, i64 0, i64 0), i8* %27, i8* %28, i8* %29)
%31 = load i8*, i8** %8
%32 = call i32 @chaz_CC_test_compile(i8* %31)
store i32 %32, i32* %9
%33 = load i8*, i8** %8
%34 = call i32 @free(i8* %33)
%35 = load i32, i32* %9
ret i32 %35
}

LLVM IR (-O2):
@chaz_HeadCheck_contains_member.contains_code = internal constant [64 x i8] c"#include <stddef.h>\0A%s\0Aint main() { return offsetof(%s, %s); }\0A\00"
define i32 @chaz_HeadCheck_contains_member(i8* %0, i8* %1, i8* %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 = tail call i32 @strlen(i8* %2)
%9 = sext i32 %8 to i64
%10 = add nsw i64 %5, 74
%11 = add nsw i64 %10, %7
%12 = add nsw i64 %11, %9
%13 = tail call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @chaz_HeadCheck_contains_member.contains_code, i64 0, i64 0), i8* %2, i8* %0, i8* %1)
%16 = tail call i32 @chaz_CC_test_compile(i8* %14)
%17 = tail call i32 @free(i8* %14)
ret i32 %16
}