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

/* Variables and functions */
int /*<<< orphan*/ Panic(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strlen(char *);
void Check_snprintf(void) {
  char str[5];
  snprintf(str, sizeof(str), "%s", "1234567890");
  if (str[4] != '\0')
    Panic("snprintf NULL byte");
  if (strlen(str) != 4)
    Panic("snprintf string length");
}


x86 assembly (clang, -O0):
<Check_snprintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x5(%rbp),%rdi
mov    $0x5,%esi
lea    0xeb8(%rip),%rdx
lea    0xeb4(%rip),%rcx
call   1040 <snprintf@plt>
movsbl -0x1(%rbp),%eax
cmp    $0x0,%eax
je     116d <Check_snprintf+0x3d>
lea    0xea6(%rip),%rdi
call   1050 <Panic@plt>
lea    -0x5(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
je     118b <Check_snprintf+0x5b>
lea    0xe9b(%rip),%rdi
call   1050 <Panic@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Check_snprintf>:
push   %rax
lea    0xec8(%rip),%rdx
lea    0xec4(%rip),%rcx
lea    0x3(%rsp),%rdi
mov    $0x5,%esi
call   1040 <snprintf@plt>
cmpb   $0x0,0x7(%rsp)
je     1161 <Check_snprintf+0x31>
lea    0xeb2(%rip),%rdi
call   1050 <Panic@plt>
lea    0x3(%rsp),%rdi
call   1030 <strlen@plt>
cmp    $0x4,%eax
je     117c <Check_snprintf+0x4c>
lea    0xeaa(%rip),%rdi
call   1050 <Panic@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c"1234567890\00"
@.str.2 = [19 x i8] c"snprintf NULL byte\00"
@.str.3 = [23 x i8] c"snprintf string length\00"
define void @Check_snprintf() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
%5 = load i8, i8* %4
%6 = sext i8 %5 to i32
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @Panic(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%12 = call i32 @strlen(i8* %11)
%13 = icmp ne i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 @Panic(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [11 x i8] c"1234567890\00"
@.str.2 = [19 x i8] c"snprintf NULL byte\00"
@.str.3 = [23 x i8] c"snprintf string length\00"
define void @Check_snprintf() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 4
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = call i32 @Panic(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = call i32 @strlen(i8* %2)
%11 = icmp eq i32 %10, 4
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = call i32 @Panic(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
ret void
}