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

/* Variables and functions */
scalar_t__ ECANCELED;
scalar_t__ EINVAL;
scalar_t__ EOVERFLOW;
int /*<<< orphan*/ INT_MAX;
scalar_t__ errno;
int eslib_string_sprintf(char *, int, unsigned int *, char *, ...);
int /*<<< orphan*/ printf(char *, ...);
unsigned int strlen(char const *);
int test_sprintf() {
  char dst[16];
  const char str[] = "abcd";
  const char good_msg[] = "this fits!";
  const char bad_msg[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
  unsigned int len;
  if (eslib_string_sprintf(dst, sizeof(dst), &len, "%s", bad_msg) != -1) {
    printf("bad sprintf 1 did not fail\n");
    return -1;
  }
  if (errno != EOVERFLOW) {
    printf("didn't detect massive string size\n");
    return -1;
  }
  if (dst[0] != 'A')
    return -1;
  if (eslib_string_sprintf(dst, sizeof(dst), &len, "%s", "") != -1) {
    printf("bad sprintf 2 didn't fail\n");
    return -1;
  }
  if (errno != ECANCELED || dst[0] != '\0') {
    printf("didn't detect 0 len write\n");
    return -1;
  }
  if (eslib_string_sprintf(dst, INT_MAX, &len, "%s", good_msg) != -1) {
    printf("bad sprintf 3 did not fail\n");
    return -1;
  }
  if (errno != EINVAL) {
    printf("didn't detect massive string size input\n");
    return -1;
  }
  if (eslib_string_sprintf(dst, sizeof(dst), &len, "%s", good_msg)) {
    printf("good sprintf 1 failed\n");
    return -1;
  }
  if (len != strlen(good_msg)) {
    printf("unexpected len\n");
    return -1;
  }
  if (eslib_string_sprintf(dst, sizeof(dst), &len, "%s5%d%c", str, 678, '9')) {
    printf("good sprintf 2 failed\n");
    return -1;
  }
  if (len != 9) {
    printf("expected {%s} len == 9\n", dst);
    return -1;
  }
  if (eslib_string_sprintf(dst, sizeof(dst), &len, "%d %5.3f\n", 10, 0.10f)) {
    printf("good sprintf3 failed\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_sprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0xeba(%rip),%eax
mov    %eax,-0x25(%rbp)
mov    0xeb5(%rip),%al
mov    %al,-0x21(%rbp)
mov    0xeac(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea9(%rip),%ax
mov    %ax,-0x28(%rbp)
mov    0xea1(%rip),%al
mov    %al,-0x26(%rbp)
lea    -0x60(%rbp),%rdi
lea    0xfdc(%rip),%rsi
mov    $0x2c,%edx
call   1060 <memcpy@plt>
lea    -0x20(%rbp),%rdi
lea    -0x60(%rbp),%r8
mov    $0x10,%esi
lea    -0x64(%rbp),%rdx
lea    0xe72(%rip),%rcx
mov    $0x0,%al
call   1030 <eslib_string_sprintf@plt>
cmp    $0xffffffff,%eax
je     11d0 <test_sprintf+0x90>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
mov    0x2df1(%rip),%rax
mov    (%rax),%rax
mov    0x2e0f(%rip),%rcx
cmp    (%rcx),%rax
je     1204 <test_sprintf+0xc4>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
movsbl -0x20(%rbp),%eax
cmp    $0x41,%eax
je     121d <test_sprintf+0xdd>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
lea    -0x64(%rbp),%rdx
lea    0xde7(%rip),%rcx
lea    0xefa(%rip),%r8
mov    $0x0,%al
call   1030 <eslib_string_sprintf@plt>
cmp    $0xffffffff,%eax
je     1262 <test_sprintf+0x122>
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
mov    0x2d5f(%rip),%rax
mov    (%rax),%rax
mov    0x2d6d(%rip),%rcx
cmp    (%rcx),%rax
jne    1289 <test_sprintf+0x149>
movsbl -0x20(%rbp),%eax
cmp    $0x0,%eax
je     12a3 <test_sprintf+0x163>
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
lea    -0x20(%rbp),%rdi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%r8
lea    -0x64(%rbp),%rdx
lea    0xd59(%rip),%rcx
mov    $0x0,%al
call   1030 <eslib_string_sprintf@plt>
cmp    $0xffffffff,%eax
je     12e9 <test_sprintf+0x1a9>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
mov    0x2cd8(%rip),%rax
mov    (%rax),%rax
mov    0x2cc6(%rip),%rcx
cmp    (%rcx),%rax
je     131d <test_sprintf+0x1dd>
lea    0xda2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%r8
mov    $0x10,%esi
lea    -0x64(%rbp),%rdx
lea    0xce3(%rip),%rcx
mov    $0x0,%al
call   1030 <eslib_string_sprintf@plt>
cmp    $0x0,%eax
je     135f <test_sprintf+0x21f>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
mov    -0x64(%rbp),%eax
mov    %eax,-0x68(%rbp)
lea    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
cmp    %ecx,%eax
je     1395 <test_sprintf+0x255>
lea    0xd6a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
lea    -0x20(%rbp),%rdi
lea    -0x25(%rbp),%r8
mov    $0x10,%esi
lea    -0x64(%rbp),%rdx
lea    0xd4f(%rip),%rcx
mov    $0x2a6,%r9d
movl   $0x39,(%rsp)
mov    $0x0,%al
call   1030 <eslib_string_sprintf@plt>
cmp    $0x0,%eax
je     13e4 <test_sprintf+0x2a4>
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
cmpl   $0x9,-0x64(%rbp)
je     140c <test_sprintf+0x2cc>
lea    -0x20(%rbp),%rsi
lea    0xd22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
lea    -0x20(%rbp),%rdi
mov    $0x10,%esi
lea    -0x64(%rbp),%rdx
lea    0xd13(%rip),%rcx
mov    $0xa,%r8d
movsd  0xbd2(%rip),%xmm0
mov    $0x1,%al
call   1030 <eslib_string_sprintf@plt>
cmp    $0x0,%eax
je     1458 <test_sprintf+0x318>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    145f <test_sprintf+0x31f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_sprintf>:
push   %rbp
push   %r14
push   %rbx
sub    $0x70,%rsp
movb   $0x0,0x1c(%rsp)
movl   $0x64636261,0x18(%rsp)
64
movabs $0x7469662073696874,%rax
66 69 74
mov    %rax,0x30(%rsp)
movl   $0x217374,0x37(%rsp)
movups 0xff9(%rip),%xmm0
movups %xmm0,0x5c(%rsp)
movaps 0xfe1(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xfc5(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
lea    0xe81(%rip),%rcx
lea    0x20(%rsp),%rdi
lea    0x14(%rsp),%rdx
lea    0x40(%rsp),%r8
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <eslib_string_sprintf@plt>
cmp    $0xffffffff,%eax
je     11c0 <test_sprintf+0x80>
lea    0xf70(%rip),%rdi
jmp    121b <test_sprintf+0xdb>
mov    0x2e01(%rip),%r14
mov    (%r14),%rax
mov    0x2e1f(%rip),%rcx
cmp    (%rcx),%rax
jne    1214 <test_sprintf+0xd4>
mov    $0xffffffff,%ebx
cmpb   $0x41,0x20(%rsp)
jne    1225 <test_sprintf+0xe5>
lea    0xe2f(%rip),%rcx
lea    0xe4a(%rip),%r8
lea    0x20(%rsp),%rdi
lea    0x14(%rsp),%rdx
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <eslib_string_sprintf@plt>
cmp    $0xffffffff,%eax
je     1230 <test_sprintf+0xf0>
lea    0xee0(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
lea    0xef1(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x70,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%r14),%rax
mov    0x2da6(%rip),%rcx
cmp    (%rcx),%rax
jne    127a <test_sprintf+0x13a>
cmpb   $0x0,0x20(%rsp)
jne    127a <test_sprintf+0x13a>
mov    0x2d8b(%rip),%rax
mov    (%rax),%esi
lea    0xdc2(%rip),%rcx
lea    0x20(%rsp),%rdi
lea    0x14(%rsp),%rdx
lea    0x30(%rsp),%r8
xor    %eax,%eax
call   1030 <eslib_string_sprintf@plt>
cmp    $0xffffffff,%eax
je     1288 <test_sprintf+0x148>
lea    0xe45(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
jmp    1225 <test_sprintf+0xe5>
mov    (%r14),%rax
mov    0x2d2e(%rip),%rcx
cmp    (%rcx),%rax
jne    12c6 <test_sprintf+0x186>
lea    0xd7a(%rip),%rcx
lea    0x20(%rsp),%rdi
lea    0x14(%rsp),%rdx
lea    0x30(%rsp),%r8
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <eslib_string_sprintf@plt>
test   %eax,%eax
je     12cf <test_sprintf+0x18f>
lea    0xdbb(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
lea    0xdc8(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
mov    0x14(%rsp),%ebp
lea    0x30(%rsp),%rdi
call   1050 <strlen@plt>
cmp    %eax,%ebp
jne    1320 <test_sprintf+0x1e0>
movl   $0x39,(%rsp)
lea    0xd2c(%rip),%rcx
lea    0x20(%rsp),%rdi
lea    0x14(%rsp),%rdx
lea    0x18(%rsp),%r8
mov    $0x10,%esi
mov    $0x2a6,%r9d
xor    %eax,%eax
call   1030 <eslib_string_sprintf@plt>
test   %eax,%eax
je     132c <test_sprintf+0x1ec>
lea    0xd3f(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
lea    0xd49(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
cmpl   $0x9,0x14(%rsp)
jne    136e <test_sprintf+0x22e>
lea    0xd01(%rip),%rcx
lea    0x20(%rsp),%rdi
lea    0x14(%rsp),%rdx
movsd  0xcb4(%rip),%xmm0
mov    $0x10,%esi
mov    $0xa,%r8d
mov    $0x1,%al
call   1030 <eslib_string_sprintf@plt>
test   %eax,%eax
je     1386 <test_sprintf+0x246>
lea    0xcdc(%rip),%rdi
jmp    1281 <test_sprintf+0x141>
lea    0xcae(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1225 <test_sprintf+0xe5>
xor    %ebx,%ebx
jmp    1225 <test_sprintf+0xe5>

LLVM IR (-O0):
@__const.test_sprintf.str = [5 x i8] c"abcd\00"
@__const.test_sprintf.good_msg = [11 x i8] c"this fits!\00"
@__const.test_sprintf.bad_msg = [44 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str = [3 x i8] c"%s\00"
@.str.1 = [28 x i8] c"bad sprintf 1 did not fail\0A\00"
@errno = global i64 0
@EOVERFLOW = global i64 0
@.str.2 = [35 x i8] c"didn't detect massive string size\0A\00"
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [27 x i8] c"bad sprintf 2 didn't fail\0A\00"
@ECANCELED = global i64 0
@.str.5 = [27 x i8] c"didn't detect 0 len write\0A\00"
@INT_MAX = global i32 0
@.str.6 = [28 x i8] c"bad sprintf 3 did not fail\0A\00"
@EINVAL = global i64 0
@.str.7 = [41 x i8] c"didn't detect massive string size input\0A\00"
@.str.8 = [23 x i8] c"good sprintf 1 failed\0A\00"
@.str.9 = [16 x i8] c"unexpected len\0A\00"
@.str.10 = [8 x i8] c"%s5%d%c\00"
@.str.11 = [23 x i8] c"good sprintf 2 failed\0A\00"
@.str.12 = [24 x i8] c"expected {%s} len == 9\0A\00"
@.str.13 = [10 x i8] c"%d %5.3f\0A\00"
@.str.14 = [22 x i8] c"good sprintf3 failed\0A\00"
define i32 @test_sprintf() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [5 x i8]
%4 = alloca [11 x i8]
%5 = alloca [44 x i8]
%6 = alloca i32
%7 = bitcast [5 x i8]* %3 to i8*
%8 = bitcast [11 x i8]* %4 to i8*
%9 = bitcast [44 x i8]* %5 to i8*
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%11 = getelementptr inbounds [44 x i8], [44 x i8]* %5, i64 0, i64 0
%12 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %10, i32 16, i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
16: ; preds = %0
%17 = load i64, i64* @errno
%18 = load i64, i64* @EOVERFLOW
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
22: ; preds = %16
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 65
br i1 %26, label %27, label %28
27: ; preds = %22
store i32 -1, i32* %1
br label %93
28: ; preds = %22
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%30 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %29, i32 16, i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i32 %30, -1
br i1 %31, label %32, label %34
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
34: ; preds = %28
%35 = load i64, i64* @errno
%36 = load i64, i64* @ECANCELED
%37 = icmp ne i64 %35, %36
br i1 %37, label %43, label %38
38: ; preds = %34
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %38, %34
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
45: ; preds = %38
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%47 = load i32, i32* @INT_MAX
%48 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%49 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %46, i32 %47, i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %48)
%50 = icmp ne i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
53: ; preds = %45
%54 = load i64, i64* @errno
%55 = load i64, i64* @EINVAL
%56 = icmp ne i64 %54, %55
br i1 %56, label %57, label %59
57: ; preds = %53
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
59: ; preds = %53
%60 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%61 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%62 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %60, i32 16, i32* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %61)
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %59
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
66: ; preds = %59
%67 = load i32, i32* %6
%68 = getelementptr inbounds [11 x i8], [11 x i8]* %4, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = icmp ne i32 %67, %69
br i1 %70, label %71, label %73
71: ; preds = %66
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
73: ; preds = %66
%74 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%75 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%76 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %74, i32 16, i32* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* %75, i32 678, i32 57)
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
80: ; preds = %73
%81 = load i32, i32* %6
%82 = icmp ne i32 %81, 9
br i1 %82, label %83, label %86
83: ; preds = %80
%84 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %84)
store i32 -1, i32* %1
br label %93
86: ; preds = %80
%87 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%88 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %87, i32 16, i32* %6, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 10, double 0x3FB99999A0000000)
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %92
90: ; preds = %86
%91 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0))
store i32 -1, i32* %1
br label %93
92: ; preds = %86
store i32 0, i32* %1
br label %93
93: ; preds = %92, %90, %83, %78, %71, %64, %57, %51, %43, %32, %27, %20, %14
%94 = load i32, i32* %1
ret i32 %94
}

LLVM IR (-O2):
@__const.test_sprintf.str = [5 x i8] c"abcd\00"
@__const.test_sprintf.good_msg = [11 x i8] c"this fits!\00"
@__const.test_sprintf.bad_msg = [44 x i8] c"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@.str = [3 x i8] c"%s\00"
@errno = global i64 0
@EOVERFLOW = global i64 0
@.str.3 = [1 x i8] zeroinitializer
@ECANCELED = global i64 0
@INT_MAX = global i32 0
@EINVAL = global i64 0
@.str.10 = [8 x i8] c"%s5%d%c\00"
@.str.12 = [24 x i8] c"expected {%s} len == 9\0A\00"
@.str.13 = [10 x i8] c"%d %5.3f\0A\00"
@str = [21 x i8] c"good sprintf3 failed\00"
@str.15 = [22 x i8] c"good sprintf 2 failed\00"
@str.16 = [15 x i8] c"unexpected len\00"
@str.17 = [22 x i8] c"good sprintf 1 failed\00"
@str.18 = [40 x i8] c"didn't detect massive string size input\00"
@str.19 = [27 x i8] c"bad sprintf 3 did not fail\00"
@str.20 = [26 x i8] c"didn't detect 0 len write\00"
@str.21 = [26 x i8] c"bad sprintf 2 didn't fail\00"
@str.22 = [34 x i8] c"didn't detect massive string size\00"
@str.23 = [27 x i8] c"bad sprintf 1 did not fail\00"
define i32 @test_sprintf() {
%1 = alloca [16 x i8]
%2 = alloca [5 x i8]
%3 = alloca [11 x i8]
%4 = alloca [44 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [44 x i8], [44 x i8]* %4, i64 0, i64 0
%10 = bitcast i32* %5 to i8*
%11 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %6, i32 16, i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %9)
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %13
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.23, i64 0, i64 0))
br label %76
15: ; preds = %0
%16 = load i64, i64* @errno
%17 = load i64, i64* @EOVERFLOW
%18 = icmp eq i64 %16, %17
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.22, i64 0, i64 0))
br label %76
21: ; preds = %15
%22 = load i8, i8* %6
%23 = icmp eq i8 %22, 65
br i1 %23, label %24, label %76
24: ; preds = %21
%25 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %6, i32 16, i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32 %25, -1
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.21, i64 0, i64 0))
br label %76
29: ; preds = %24
%30 = load i64, i64* @errno
%31 = load i64, i64* @ECANCELED
%32 = icmp ne i64 %30, %31
%33 = load i8, i8* %6
%34 = icmp ne i8 %33, 0
%35 = select i1 %32, i1 true, i1 %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.20, i64 0, i64 0))
br label %76
38: ; preds = %29
%39 = load i32, i32* @INT_MAX
%40 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %6, i32 %39, i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%41 = icmp eq i32 %40, -1
br i1 %41, label %44, label %42
42: ; preds = %38
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.19, i64 0, i64 0))
br label %76
44: ; preds = %38
%45 = load i64, i64* @errno
%46 = load i64, i64* @EINVAL
%47 = icmp eq i64 %45, %46
br i1 %47, label %50, label %48
48: ; preds = %44
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.18, i64 0, i64 0))
br label %76
50: ; preds = %44
%51 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %6, i32 16, i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %8)
%52 = icmp eq i32 %51, 0
br i1 %52, label %55, label %53
53: ; preds = %50
%54 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.17, i64 0, i64 0))
br label %76
55: ; preds = %50
%56 = load i32, i32* %5
%57 = call i32 @strlen(i8* %8)
%58 = icmp eq i32 %56, %57
br i1 %58, label %61, label %59
59: ; preds = %55
%60 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.16, i64 0, i64 0))
br label %76
61: ; preds = %55
%62 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %6, i32 16, i32* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* %7, i32 678, i32 57)
%63 = icmp eq i32 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %61
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
br label %76
66: ; preds = %61
%67 = load i32, i32* %5
%68 = icmp eq i32 %67, 9
br i1 %68, label %71, label %69
69: ; preds = %66
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.12, i64 0, i64 0), i8* %6)
br label %76
71: ; preds = %66
%72 = call i32 (i8*, i32, i32*, i8*, ...) @eslib_string_sprintf(i8* %6, i32 16, i32* %5, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.13, i64 0, i64 0), i32 10, double 0x3FB99999A0000000)
%73 = icmp eq i32 %72, 0
br i1 %73, label %76, label %74
74: ; preds = %71
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %76
76: ; preds = %71, %21, %74, %69, %64, %59, %53, %48, %42, %36, %27, %19, %13
%77 = phi i32 [ -1, %13 ], [ -1, %19 ], [ -1, %27 ], [ -1, %36 ], [ -1, %42 ], [ -1, %48 ], [ -1, %53 ], [ -1, %59 ], [ -1, %64 ], [ -1, %69 ], [ -1, %74 ], [ -1, %21 ], [ 0, %71 ]
ret i32 %77
}