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

/* Variables and functions */
char *chaz_CC_capture_output(char const *, size_t *);
int /*<<< orphan*/ chaz_ConfWriter_add_def(char *, int /*<<< orphan*/ *);
scalar_t__ chaz_HeadCheck_defines_symbol(char *, char *);
int /*<<< orphan*/ free(char *);
long strtol(char *, int /*<<< orphan*/ *, int);
void chaz_Strings_probe_c99_snprintf(void) {
  static const char snprintf_code[] =
      "#include <stdio.h>"
      "\n"
      "int main() {"
      "\n"
      "char buf[4];"
      "\n"
      "int result;"
      "\n"
      "result = snprintf(buf, 4, \"%s\", \"12345\");"
      "\n"
      "printf(\"%d\", result);"
      "\n"
      "return 0;"
      "\n"
      "}"
      "\n";
  char *output = NULL;
  size_t output_len;
  output = chaz_CC_capture_output(snprintf_code, &output_len);
  if (output != NULL) {
    long result = strtol(output, NULL, 10);
    if (result == 5) {
      chaz_ConfWriter_add_def("HAS_C99_SNPRINTF", NULL);
    }
    free(output);
  }
  if (chaz_HeadCheck_defines_symbol("_scprintf", "#include <stdio.h>")) {
    chaz_ConfWriter_add_def("HAS__SCPRINTF", NULL);
  }
  if (chaz_HeadCheck_defines_symbol("_snprintf", "#include <stdio.h>")) {
    chaz_ConfWriter_add_def("HAS__SNPRINTF", NULL);
  }
}


x86 assembly (clang, -O0):
<chaz_Strings_probe_c99_snprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xe99(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <chaz_CC_capture_output@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b9 <chaz_Strings_probe_c99_snprintf+0x69>
mov    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x5,-0x18(%rbp)
jne    11b0 <chaz_Strings_probe_c99_snprintf+0x60>
lea    0xedf(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xed7(%rip),%rdi
lea    0xeda(%rip),%rsi
call   1070 <chaz_HeadCheck_defines_symbol@plt>
cmp    $0x0,%rax
je     11e6 <chaz_Strings_probe_c99_snprintf+0x96>
lea    0xed7(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
lea    0xed5(%rip),%rdi
lea    0xead(%rip),%rsi
call   1070 <chaz_HeadCheck_defines_symbol@plt>
cmp    $0x0,%rax
je     1213 <chaz_Strings_probe_c99_snprintf+0xc3>
lea    0xec2(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_Strings_probe_c99_snprintf>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <chaz_CC_capture_output@plt>
test   %rax,%rax
je     1199 <chaz_Strings_probe_c99_snprintf+0x49>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
cmp    $0x5,%rax
jne    1191 <chaz_Strings_probe_c99_snprintf+0x41>
lea    0xefc(%rip),%rdi
xor    %esi,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xef7(%rip),%rdi
lea    0xefa(%rip),%rsi
call   1070 <chaz_HeadCheck_defines_symbol@plt>
test   %rax,%rax
je     11bf <chaz_Strings_probe_c99_snprintf+0x6f>
lea    0xefc(%rip),%rdi
xor    %esi,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
lea    0xefc(%rip),%rdi
lea    0xed4(%rip),%rsi
call   1070 <chaz_HeadCheck_defines_symbol@plt>
test   %rax,%rax
je     11e5 <chaz_Strings_probe_c99_snprintf+0x95>
lea    0xeee(%rip),%rdi
xor    %esi,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@chaz_Strings_probe_c99_snprintf.snprintf_code = internal constant [134 x i8] c"#include <stdio.h>\0Aint main() {\0Achar buf[4];\0Aint result;\0Aresult = snprintf(buf, 4, \22%s\22, \2212345\22);\0Aprintf(\22%d\22, result);\0Areturn 0;\0A}\0A\00"
@.str = [17 x i8] c"HAS_C99_SNPRINTF\00"
@.str.1 = [10 x i8] c"_scprintf\00"
@.str.2 = [19 x i8] c"#include <stdio.h>\00"
@.str.3 = [14 x i8] c"HAS__SCPRINTF\00"
@.str.4 = [10 x i8] c"_snprintf\00"
@.str.5 = [14 x i8] c"HAS__SNPRINTF\00"
define void @chaz_Strings_probe_c99_snprintf() {
%1 = alloca i8*
%2 = alloca i64
%3 = alloca i64
store i8* null, i8** %1
%4 = call i8* @chaz_CC_capture_output(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @chaz_Strings_probe_c99_snprintf.snprintf_code, i64 0, i64 0), i64* %2)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
br i1 %6, label %7, label %17
7: ; preds = %0
%8 = load i8*, i8** %1
%9 = call i64 @strtol(i8* %8, i32* null, i32 10)
store i64 %9, i64* %3
%10 = load i64, i64* %3
%11 = icmp eq i64 %10, 5
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* null)
br label %14
14: ; preds = %12, %7
%15 = load i8*, i8** %1
%16 = call i32 @free(i8* %15)
br label %17
17: ; preds = %14, %0
%18 = call i64 @chaz_HeadCheck_defines_symbol(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %22
22: ; preds = %20, %17
%23 = call i64 @chaz_HeadCheck_defines_symbol(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %27
27: ; preds = %25, %22
ret void
}

LLVM IR (-O2):
@chaz_Strings_probe_c99_snprintf.snprintf_code = internal constant [134 x i8] c"#include <stdio.h>\0Aint main() {\0Achar buf[4];\0Aint result;\0Aresult = snprintf(buf, 4, \22%s\22, \2212345\22);\0Aprintf(\22%d\22, result);\0Areturn 0;\0A}\0A\00"
@.str = [17 x i8] c"HAS_C99_SNPRINTF\00"
@.str.1 = [10 x i8] c"_scprintf\00"
@.str.2 = [19 x i8] c"#include <stdio.h>\00"
@.str.3 = [14 x i8] c"HAS__SCPRINTF\00"
@.str.4 = [10 x i8] c"_snprintf\00"
@.str.5 = [14 x i8] c"HAS__SNPRINTF\00"
define void @chaz_Strings_probe_c99_snprintf() {
%1 = alloca i64
%2 = bitcast i64* %1 to i8*
%3 = call i8* @chaz_CC_capture_output(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @chaz_Strings_probe_c99_snprintf.snprintf_code, i64 0, i64 0), i64* %1)
%4 = icmp eq i8* %3, null
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = call i64 @strtol(i8* nocapture %3, i32* null, i32 10)
%7 = icmp eq i64 %6, 5
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32* null)
br label %10
10: ; preds = %8, %5
%11 = call i32 @free(i8* %3)
br label %12
12: ; preds = %10, %0
%13 = call i64 @chaz_HeadCheck_defines_symbol(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %17, label %15
15: ; preds = %12
%16 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32* null)
br label %17
17: ; preds = %15, %12
%18 = call i64 @chaz_HeadCheck_defines_symbol(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %17
%21 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %22
22: ; preds = %20, %17
ret void
}