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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ errx(int /*<<< orphan*/, char *, ...);
int snprintf(char *, int, char *);
scalar_t__ strcmp(char *, char *);
void snprintf__overflow(void) {
  char buffer[10];
  if (snprintf(buffer, sizeof(buffer), "0123456789abcdef") != 16)
    errx(EXIT_FAILURE, "snprintf did not return the expected "
                       "number of characters");
  if (strcmp(buffer, "012345678") != 0)
    errx(EXIT_FAILURE, "Bad formatting: got %s", buffer);
}


x86 assembly (clang, -O0):
<snprintf__overflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0xa(%rbp),%rdi
mov    $0xa,%esi
lea    0xeb8(%rip),%rdx
call   1040 <snprintf@plt>
cmp    $0x10,%eax
je     116d <snprintf__overflow+0x3d>
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
lea    -0xa(%rbp),%rdi
lea    0xed3(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11a2 <snprintf__overflow+0x72>
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
lea    -0xa(%rbp),%rdx
lea    0xeba(%rip),%rsi
mov    $0x0,%al
call   1030 <errx@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprintf__overflow>:
sub    $0x18,%rsp
lea    0xec5(%rip),%rdx
lea    0xe(%rsp),%rdi
mov    $0xa,%esi
call   1040 <snprintf@plt>
cmp    $0x10,%eax
je     1166 <snprintf__overflow+0x36>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
xor    %eax,%eax
call   1030 <errx@plt>
lea    0xede(%rip),%rsi
lea    0xe(%rsp),%rdi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1198 <snprintf__overflow+0x68>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xec9(%rip),%rsi
lea    0xe(%rsp),%rdx
xor    %eax,%eax
call   1030 <errx@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [17 x i8] c"0123456789abcdef\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [58 x i8] c"snprintf did not return the expected number of characters\00"
@.str.2 = [10 x i8] c"012345678\00"
@.str.3 = [23 x i8] c"Bad formatting: got %s\00"
define void @snprintf__overflow() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = icmp ne i32 %3, 16
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = load i32, i32* @EXIT_FAILURE
%7 = call i32 (i32, i8*, ...) @errx(i32 %6, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %8
%13 = load i32, i32* @EXIT_FAILURE
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%15 = call i32 (i32, i8*, ...) @errx(i32 %13, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"0123456789abcdef\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [58 x i8] c"snprintf did not return the expected number of characters\00"
@.str.2 = [10 x i8] c"012345678\00"
@.str.3 = [23 x i8] c"Bad formatting: got %s\00"
define void @snprintf__overflow() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %3, 16
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @EXIT_FAILURE
%7 = call i32 (i32, i8*, ...) @errx(i32 %6, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i64 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 (i32, i8*, ...) @errx(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %14
14: ; preds = %11, %8
ret void
}