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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, int);
scalar_t__ strcmp(char *, char *);
int main(void) {
  {
    int in = 1234;
    char out[1024];
    int snprintf_return;
    snprintf_return = snprintf(out, sizeof(out), "ab%dcd", in);
    if (snprintf_return < 0) {
      perror("snprintf");
      exit(EXIT_FAILURE);
    }
    assert((size_t)snprintf_return < sizeof(out));
    assert(snprintf_return == 8);
    assert(strcmp(out, "ab1234cd") == 0);
  }
  {}
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x4d2,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x400,%esi
lea    0xe81(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jge    11b1 <main+0x61>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movslq -0x414(%rbp),%rax
cmp    $0x400,%rax
setb   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpl   $0x8,-0x414(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
lea    -0x410(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
lea    0xea1(%rip),%rdx
mov    %rsp,%rdi
mov    $0x400,%esi
mov    $0x4d2,%ecx
call   1030 <snprintf@plt>
test   %eax,%eax
js     11c4 <main+0x74>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0x400,%eax
setb   %dil
call   1050 <assert@plt>
xor    %edi,%edi
cmp    $0x8,%ebx
sete   %dil
call   1050 <assert@plt>
lea    0xe74(%rip),%rsi
mov    %rsp,%rdi
call   1040 <strcmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1050 <assert@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%eax
add    $0x400,%rsp
pop    %rbx
ret
lea    0xe3c(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"ab%dcd\00"
@.str.1 = [9 x i8] c"snprintf\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [9 x i8] c"ab1234cd\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 0, i32* %1
store i32 1234, i32* %2
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* %2
%7 = call i32 @snprintf(i8* %5, i32 1024, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = icmp ult i64 %16, 1024
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 8
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i32, i32* @EXIT_SUCCESS
ret i32 %29
}

LLVM IR (-O2):
@.str = [7 x i8] c"ab%dcd\00"
@.str.1 = [9 x i8] c"snprintf\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [9 x i8] c"ab1234cd\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @snprintf(i8* %2, i32 1024, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 1234)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %9
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = call i32 @exit(i32 %7)
unreachable
9: ; preds = %0
%10 = icmp ult i32 %3, 1024
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = icmp eq i32 %3, 8
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @EXIT_SUCCESS
ret i32 %20
}