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

/* Variables and functions */
int /*<<< orphan*/ ad_have_feature(char *);
int /*<<< orphan*/ ad_unlink(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
char *gmk_alloc(int);
int /*<<< orphan*/ gmk_free(char *);
char *run_cmd(char *, char *);
int /*<<< orphan*/ strchr(char *, char);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ unlink(char *);
char *make_ad_fn_c_check_header_compile(__attribute__((unused)) char const *nm,
                                        unsigned int argc, char **argv) {
  unsigned int i;
  char *result;
  FILE *fp;
  fp = fopen(argv[0], "w+");
  if (!fp) {
    return NULL;
  }
  for (i = 2; i < argc; i++) {
    if (!strchr(argv[i], '\n')) {
      fprintf(fp, "#include <%s>\n", argv[i]);
    } else {
      fprintf(fp, "%s\n", argv[i]);
    }
  }
  fprintf(fp, "#include <%s>\n", argv[1]);
  fclose(fp);
  result = run_cmd("${CC} -c ${CFLAGS} ${CPPFLAGS}", argv[0]);
  if (!result)
    goto done;
  if (strcmp(result, "0") == 0) {
    ad_have_feature(argv[1]);
  }
  gmk_free(result);
done:
  (void)unlink(argv[0]);
  ad_unlink(argv[0], ".so");
  result = gmk_alloc(1);
  if (!result)
    return NULL;
  *result = '\0';
  return result;
}


x86 assembly (clang, -O0):
<make_ad_fn_c_check_header_compile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11f2 <make_ad_fn_c_check_header_compile+0x42>
movq   $0x0,-0x8(%rbp)
jmp    133d <make_ad_fn_c_check_header_compile+0x18d>
movl   $0x2,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jae    1271 <make_ad_fn_c_check_header_compile+0xc1>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
cmp    $0x0,%eax
jne    1243 <make_ad_fn_c_check_header_compile+0x93>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdx
lea    0xdca(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    125e <make_ad_fn_c_check_header_compile+0xae>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    (%rax,%rcx,8),%rdx
lea    0xdb9(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1263 <make_ad_fn_c_check_header_compile+0xb3>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f9 <make_ad_fn_c_check_header_compile+0x49>
mov    -0x38(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd7f(%rip),%rsi
call   10a0 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xd76(%rip),%rdi
call   10d0 <run_cmd@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12b9 <make_ad_fn_c_check_header_compile+0x109>
jmp    12e9 <make_ad_fn_c_check_header_compile+0x139>
mov    -0x30(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12e0 <make_ad_fn_c_check_header_compile+0x130>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <ad_have_feature@plt>
mov    -0x30(%rbp),%rdi
call   1070 <gmk_free@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1030 <unlink@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd34(%rip),%rsi
call   10b0 <ad_unlink@plt>
mov    $0x1,%edi
call   1080 <gmk_alloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    132e <make_ad_fn_c_check_header_compile+0x17e>
movq   $0x0,-0x8(%rbp)
jmp    133d <make_ad_fn_c_check_header_compile+0x18d>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_ad_fn_c_check_header_compile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%ebp
mov    (%rdx),%rdi
lea    0xe36(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12ae <make_ad_fn_c_check_header_compile+0xfe>
mov    %rax,%r14
cmp    $0x3,%ebp
jb     122c <make_ad_fn_c_check_header_compile+0x7c>
mov    %ebp,%r15d
mov    $0x2,%ebp
lea    0xe14(%rip),%r12
lea    0xe1c(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%rdi
mov    $0xa,%esi
call   1060 <strchr@plt>
test   %eax,%eax
mov    (%rbx,%rbp,8),%rdx
mov    %r13,%rsi
cmove  %r12,%rsi
mov    %r14,%rdi
call   10a0 <fprintf@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1200 <make_ad_fn_c_check_header_compile+0x50>
mov    0x8(%rbx),%rdx
lea    0xdcc(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fprintf@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    (%rbx),%rsi
lea    0xdc5(%rip),%rdi
call   10d0 <run_cmd@plt>
test   %rax,%rax
je     1283 <make_ad_fn_c_check_header_compile+0xd3>
mov    %rax,%r14
lea    0xdd0(%rip),%rsi
mov    %rax,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    127b <make_ad_fn_c_check_header_compile+0xcb>
mov    0x8(%rbx),%rdi
call   1040 <ad_have_feature@plt>
mov    %r14,%rdi
call   1070 <gmk_free@plt>
mov    (%rbx),%rdi
call   1030 <unlink@plt>
mov    (%rbx),%rdi
lea    0xda2(%rip),%rsi
call   10b0 <ad_unlink@plt>
mov    $0x1,%edi
call   1080 <gmk_alloc@plt>
test   %rax,%rax
je     12ae <make_ad_fn_c_check_header_compile+0xfe>
movb   $0x0,(%rax)
jmp    12b0 <make_ad_fn_c_check_header_compile+0x100>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
@.str.1 = [15 x i8] c"#include <%s>\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [31 x i8] c"${CC} -c ${CFLAGS} ${CPPFLAGS}\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [4 x i8] c".so\00"
define i8* @make_ad_fn_c_check_header_compile(i8* %0, i32 %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8** %2, i8*** %7
%11 = load i8**, i8*** %7
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %14, i32** %10
%15 = load i32*, i32** %10
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
store i8* null, i8** %4
br label %94
18: ; preds = %3
store i32 2, i32* %8
br label %19
19: ; preds = %48, %18
%20 = load i32, i32* %8
%21 = load i32, i32* %6
%22 = icmp ult i32 %20, %21
br i1 %22, label %23, label %51
23: ; preds = %19
%24 = load i8**, i8*** %7
%25 = load i32, i32* %8
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = call i32 @strchr(i8* %28, i8 signext 10)
%30 = icmp ne i32 %29, 0
br i1 %30, label %39, label %31
31: ; preds = %23
%32 = load i32*, i32** %10
%33 = load i8**, i8*** %7
%34 = load i32, i32* %8
%35 = zext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @fprintf(i32* %32, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %47
39: ; preds = %23
%40 = load i32*, i32** %10
%41 = load i8**, i8*** %7
%42 = load i32, i32* %8
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %45)
br label %47
47: ; preds = %39, %31
br label %48
48: ; preds = %47
%49 = load i32, i32* %8
%50 = add i32 %49, 1
store i32 %50, i32* %8
br label %19
51: ; preds = %19
%52 = load i32*, i32** %10
%53 = load i8**, i8*** %7
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i32 @fprintf(i32* %52, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %55)
%57 = load i32*, i32** %10
%58 = call i32 @fclose(i32* %57)
%59 = load i8**, i8*** %7
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = call i8* @run_cmd(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %61)
store i8* %62, i8** %9
%63 = load i8*, i8** %9
%64 = icmp ne i8* %63, null
br i1 %64, label %66, label %65
65: ; preds = %51
br label %78
66: ; preds = %51
%67 = load i8*, i8** %9
%68 = call i64 @strcmp(i8* %67, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%69 = icmp eq i64 %68, 0
br i1 %69, label %70, label %75
70: ; preds = %66
%71 = load i8**, i8*** %7
%72 = getelementptr inbounds i8*, i8** %71, i64 1
%73 = load i8*, i8** %72
%74 = call i32 @ad_have_feature(i8* %73)
br label %75
75: ; preds = %70, %66
%76 = load i8*, i8** %9
%77 = call i32 @gmk_free(i8* %76)
br label %78
78: ; preds = %75, %65
%79 = load i8**, i8*** %7
%80 = getelementptr inbounds i8*, i8** %79, i64 0
%81 = load i8*, i8** %80
%82 = call i32 @unlink(i8* %81)
%83 = load i8**, i8*** %7
%84 = getelementptr inbounds i8*, i8** %83, i64 0
%85 = load i8*, i8** %84
%86 = call i32 @ad_unlink(i8* %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%87 = call i8* @gmk_alloc(i32 1)
store i8* %87, i8** %9
%88 = load i8*, i8** %9
%89 = icmp ne i8* %88, null
br i1 %89, label %91, label %90
90: ; preds = %78
store i8* null, i8** %4
br label %94
91: ; preds = %78
%92 = load i8*, i8** %9
store i8 0, i8* %92
%93 = load i8*, i8** %9
store i8* %93, i8** %4
br label %94
94: ; preds = %91, %90, %17
%95 = load i8*, i8** %4
ret i8* %95
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
@.str.1 = [15 x i8] c"#include <%s>\0A\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [31 x i8] c"${CC} -c ${CFLAGS} ${CPPFLAGS}\00"
@.str.4 = [2 x i8] c"0\00"
@.str.5 = [4 x i8] c".so\00"
define i8* @make_ad_fn_c_check_header_compile(i8* nocapture readnone %0, i32 %1, i8** nocapture %2) {
%4 = load i8*, i8** %2
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %46, label %7
7: ; preds = %3
%8 = icmp ugt i32 %1, 2
br i1 %8, label %9, label %22
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %11
11: ; preds = %9, %11
%12 = phi i64 [ 2, %9 ], [ %20, %11 ]
%13 = getelementptr inbounds i8*, i8** %2, i64 %12
%14 = load i8*, i8** %13
%15 = tail call i32 @strchr(i8* %14, i8 signext 10)
%16 = icmp eq i32 %15, 0
%17 = load i8*, i8** %13
%18 = select i1 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%19 = tail call i32 @fprintf(i32* %5, i8* %18, i8* %17)
%20 = add nuw nsw i64 %12, 1
%21 = icmp eq i64 %20, %10
br i1 %21, label %22, label %11
22: ; preds = %11, %7
%23 = getelementptr inbounds i8*, i8** %2, i64 1
%24 = load i8*, i8** %23
%25 = tail call i32 @fprintf(i32* %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %24)
%26 = tail call i32 @fclose(i32* %5)
%27 = load i8*, i8** %2
%28 = tail call i8* @run_cmd(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %38, label %30
30: ; preds = %22
%31 = tail call i64 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i8*, i8** %23
%35 = tail call i32 @ad_have_feature(i8* %34)
br label %36
36: ; preds = %33, %30
%37 = tail call i32 @gmk_free(i8* %28)
br label %38
38: ; preds = %22, %36
%39 = load i8*, i8** %2
%40 = tail call i32 @unlink(i8* %39)
%41 = load i8*, i8** %2
%42 = tail call i32 @ad_unlink(i8* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%43 = tail call i8* @gmk_alloc(i32 1)
%44 = icmp eq i8* %43, null
br i1 %44, label %46, label %45
45: ; preds = %38
store i8 0, i8* %43
br label %46
46: ; preds = %38, %3, %45
%47 = phi i8* [ %43, %45 ], [ null, %3 ], [ null, %38 ]
ret i8* %47
}