#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*/ *);
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";
  static const char detect__scprintf_code[] =
      "#include <stdio.h>"
      "\n"
      "int main() {"
      "\n"
      "int result;"
      "\n"
      "result = _scprintf(\"%s\", \"12345\");"
      "\n"
      "printf(\"%d\", result);"
      "\n"
      "return 0;"
      "\n"
      "}"
      "\n";
  static const char detect__snprintf_code[] =
      "#include <stdio.h>"
      "\n"
      "int main() {"
      "\n"
      "char buf[6];"
      "\n"
      "int result;"
      "\n"
      "result = _snprintf(buf, 6, \"%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);
  }
  output = chaz_CC_capture_output(detect__scprintf_code, &output_len);
  if (output != NULL) {
    chaz_ConfWriter_add_def("HAS__SCPRINTF", NULL);
    free(output);
  }
  output = chaz_CC_capture_output(detect__snprintf_code, &output_len);
  if (output != NULL) {
    chaz_ConfWriter_add_def("HAS__SNPRINTF", NULL);
    free(output);
  }
}


x86 assembly (clang, -O0):
<chaz_Strings_probe_c99_snprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
lea    0xea9(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <chaz_CC_capture_output@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11a9 <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    11a0 <chaz_Strings_probe_c99_snprintf+0x60>
lea    0x1000(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xee0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <chaz_CC_capture_output@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11e1 <chaz_Strings_probe_c99_snprintf+0xa1>
lea    0xfd9(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xf28(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <chaz_CC_capture_output@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1219 <chaz_Strings_probe_c99_snprintf+0xd9>
lea    0xfaf(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chaz_Strings_probe_c99_snprintf>:
push   %rbx
sub    $0x10,%rsp
lea    0xeb4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <chaz_CC_capture_output@plt>
test   %rax,%rax
je     1189 <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    1181 <chaz_Strings_probe_c99_snprintf+0x41>
lea    0x101d(%rip),%rdi
xor    %esi,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xf00(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <chaz_CC_capture_output@plt>
test   %rax,%rax
je     11b8 <chaz_Strings_probe_c99_snprintf+0x78>
mov    %rax,%rbx
lea    0xfff(%rip),%rdi
xor    %esi,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xf51(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <chaz_CC_capture_output@plt>
test   %rax,%rax
je     11e7 <chaz_Strings_probe_c99_snprintf+0xa7>
mov    %rax,%rbx
lea    0xfde(%rip),%rdi
xor    %esi,%esi
call   1050 <chaz_ConfWriter_add_def@plt>
mov    %rbx,%rdi
call   1030 <free@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"
@chaz_Strings_probe_c99_snprintf.detect__scprintf_code = internal constant [114 x i8] c"#include <stdio.h>\0Aint main() {\0Aint result;\0Aresult = _scprintf(\22%s\22, \2212345\22);\0Aprintf(\22%d\22, result);\0Areturn 0;\0A}\0A\00"
@chaz_Strings_probe_c99_snprintf.detect__snprintf_code = internal constant [135 x i8] c"#include <stdio.h>\0Aint main() {\0Achar buf[6];\0Aint result;\0Aresult = _snprintf(buf, 6, \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 = [14 x i8] c"HAS__SCPRINTF\00"
@.str.2 = [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 i8* @chaz_CC_capture_output(i8* getelementptr inbounds ([114 x i8], [114 x i8]* @chaz_Strings_probe_c99_snprintf.detect__scprintf_code, i64 0, i64 0), i64* %2)
store i8* %18, i8** %1
%19 = load i8*, i8** %1
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %25
21: ; preds = %17
%22 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* null)
%23 = load i8*, i8** %1
%24 = call i32 @free(i8* %23)
br label %25
25: ; preds = %21, %17
%26 = call i8* @chaz_CC_capture_output(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @chaz_Strings_probe_c99_snprintf.detect__snprintf_code, i64 0, i64 0), i64* %2)
store i8* %26, i8** %1
%27 = load i8*, i8** %1
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* null)
%31 = load i8*, i8** %1
%32 = call i32 @free(i8* %31)
br label %33
33: ; preds = %29, %25
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"
@chaz_Strings_probe_c99_snprintf.detect__scprintf_code = internal constant [114 x i8] c"#include <stdio.h>\0Aint main() {\0Aint result;\0Aresult = _scprintf(\22%s\22, \2212345\22);\0Aprintf(\22%d\22, result);\0Areturn 0;\0A}\0A\00"
@chaz_Strings_probe_c99_snprintf.detect__snprintf_code = internal constant [135 x i8] c"#include <stdio.h>\0Aint main() {\0Achar buf[6];\0Aint result;\0Aresult = _snprintf(buf, 6, \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 = [14 x i8] c"HAS__SCPRINTF\00"
@.str.2 = [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 i8* @chaz_CC_capture_output(i8* getelementptr inbounds ([114 x i8], [114 x i8]* @chaz_Strings_probe_c99_snprintf.detect__scprintf_code, i64 0, i64 0), i64* %1)
%14 = icmp eq i8* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32* null)
%17 = call i32 @free(i8* %13)
br label %18
18: ; preds = %15, %12
%19 = call i8* @chaz_CC_capture_output(i8* getelementptr inbounds ([135 x i8], [135 x i8]* @chaz_Strings_probe_c99_snprintf.detect__snprintf_code, i64 0, i64 0), i64* %1)
%20 = icmp eq i8* %19, null
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = call i32 @chaz_ConfWriter_add_def(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32* null)
%23 = call i32 @free(i8* %19)
br label %24
24: ; preds = %21, %18
ret void
}