#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 */
int /*<<< orphan*/ assertStringsEqual(char *, char *);
int /*<<< orphan*/ assertTrue(char *, int);
int snprintf(char *, int, char *, ...);
unsigned int strlen(char *);
void test_ret_value() {
  char buffer[100];
  int ret;
  ret = snprintf(buffer, 6, "0%s", "1234");
  assertStringsEqual(buffer, "01234");
  assertTrue("ret == 5", ret == 5);
  ;
  ret = snprintf(buffer, 6, "0%s", "12345");
  assertStringsEqual(buffer, "01234");
  assertTrue("ret == 6", ret == 6);
  ;
  ret = snprintf(buffer, 6, "0%s", "1234567");
  assertStringsEqual(buffer, "01234");
  assertTrue("ret == 8", ret == 8);
  ;
  ret = snprintf(buffer, 10, "hello, world");
  assertTrue("ret == 12", ret == 12);
  ;
  ret = snprintf(buffer, 3, "%d", 10000);
  assertTrue("ret == 5", ret == 5);
  ;
  assertTrue("strlen(buffer) == 2U", strlen(buffer) == 2U);
  ;
  assertTrue("buffer[0] == '1'", buffer[0] == '1');
  ;
  assertTrue("buffer[1] == '0'", buffer[1] == '0');
  ;
  assertTrue("buffer[2] == '\\0'", buffer[2] == '\0');
  ;
}


x86 assembly (clang, -O0):
<test_ret_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    -0x70(%rbp),%rdi
mov    $0x6,%esi
lea    0xea5(%rip),%rdx
lea    0xea3(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1060 <assertStringsEqual@plt>
cmpl   $0x5,-0x74(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe7b(%rip),%rdi
call   1050 <assertTrue@plt>
lea    -0x70(%rbp),%rdi
mov    $0x6,%esi
lea    0xe5c(%rip),%rdx
lea    0xe68(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xe44(%rip),%rsi
call   1060 <assertStringsEqual@plt>
cmpl   $0x6,-0x74(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe41(%rip),%rdi
call   1050 <assertTrue@plt>
lea    -0x70(%rbp),%rdi
mov    $0x6,%esi
lea    0xe13(%rip),%rdx
lea    0xe2e(%rip),%rcx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
lea    0xdfb(%rip),%rsi
call   1060 <assertStringsEqual@plt>
cmpl   $0x8,-0x74(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xe09(%rip),%rdi
call   1050 <assertTrue@plt>
lea    -0x70(%rbp),%rdi
mov    $0xa,%esi
lea    0xdfd(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xc,-0x74(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xded(%rip),%rdi
call   1050 <assertTrue@plt>
lea    -0x70(%rbp),%rdi
mov    $0x3,%esi
lea    0xde2(%rip),%rdx
mov    $0x2710,%ecx
mov    $0x0,%al
call   1040 <snprintf@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x5,-0x74(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xd80(%rip),%rdi
call   1050 <assertTrue@plt>
lea    -0x70(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xda3(%rip),%rdi
call   1050 <assertTrue@plt>
movsbl -0x70(%rbp),%eax
cmp    $0x31,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xd9d(%rip),%rdi
call   1050 <assertTrue@plt>
movsbl -0x6f(%rbp),%eax
cmp    $0x30,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xd93(%rip),%rdi
call   1050 <assertTrue@plt>
movsbl -0x6e(%rbp),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%esi
lea    0xd89(%rip),%rdi
call   1050 <assertTrue@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ret_value>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
lea    0xead(%rip),%r15
lea    0xeab(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ebp
lea    0xe8c(%rip),%r12
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <assertStringsEqual@plt>
xor    %esi,%esi
cmp    $0x5,%ebp
sete   %sil
lea    0xe77(%rip),%r14
mov    %r14,%rdi
call   1050 <assertTrue@plt>
lea    0xe71(%rip),%rcx
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <assertStringsEqual@plt>
xor    %esi,%esi
cmp    $0x6,%ebp
sete   %sil
lea    0xe48(%rip),%rdi
call   1050 <assertTrue@plt>
lea    0xe45(%rip),%rcx
mov    %rbx,%rdi
mov    $0x6,%esi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1060 <assertStringsEqual@plt>
xor    %esi,%esi
cmp    $0x8,%ebp
sete   %sil
lea    0xe1e(%rip),%rdi
call   1050 <assertTrue@plt>
lea    0xe1b(%rip),%rdx
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
xor    %esi,%esi
cmp    $0xc,%eax
sete   %sil
lea    0xe09(%rip),%rdi
call   1050 <assertTrue@plt>
lea    0xe07(%rip),%rdx
mov    %rbx,%rdi
mov    $0x3,%esi
mov    $0x2710,%ecx
xor    %eax,%eax
call   1040 <snprintf@plt>
xor    %esi,%esi
cmp    $0x5,%eax
sete   %sil
mov    %r14,%rdi
call   1050 <assertTrue@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %esi,%esi
cmp    $0x2,%eax
sete   %sil
lea    0xdcd(%rip),%rdi
call   1050 <assertTrue@plt>
xor    %esi,%esi
cmpb   $0x31,(%rsp)
sete   %sil
lea    0xdcc(%rip),%rdi
call   1050 <assertTrue@plt>
xor    %esi,%esi
cmpb   $0x30,0x1(%rsp)
sete   %sil
lea    0xdc6(%rip),%rdi
call   1050 <assertTrue@plt>
xor    %esi,%esi
cmpb   $0x0,0x2(%rsp)
sete   %sil
lea    0xdc0(%rip),%rdi
call   1050 <assertTrue@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"0%s\00"
@.str.1 = [5 x i8] c"1234\00"
@.str.2 = [6 x i8] c"01234\00"
@.str.3 = [9 x i8] c"ret == 5\00"
@.str.4 = [6 x i8] c"12345\00"
@.str.5 = [9 x i8] c"ret == 6\00"
@.str.6 = [8 x i8] c"1234567\00"
@.str.7 = [9 x i8] c"ret == 8\00"
@.str.8 = [13 x i8] c"hello, world\00"
@.str.9 = [10 x i8] c"ret == 12\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [21 x i8] c"strlen(buffer) == 2U\00"
@.str.12 = [17 x i8] c"buffer[0] == '1'\00"
@.str.13 = [17 x i8] c"buffer[1] == '0'\00"
@.str.14 = [18 x i8] c"buffer[2] == '\\0'\00"
define void @test_ret_value() {
%1 = alloca [100 x i8]
%2 = alloca i32
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %3, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %4, i32* %2
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%6 = call i32 @assertStringsEqual(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, 5
%9 = zext i1 %8 to i32
%10 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%12 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 %12, i32* %2
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%14 = call i32 @assertStringsEqual(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 6
%17 = zext i1 %16 to i32
%18 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %17)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%20 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %19, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
store i32 %20, i32* %2
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%22 = call i32 @assertStringsEqual(i8* %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%23 = load i32, i32* %2
%24 = icmp eq i32 %23, 8
%25 = zext i1 %24 to i32
%26 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %25)
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%28 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %27, i32 10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 12
%31 = zext i1 %30 to i32
%32 = call i32 @assertTrue(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %31)
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%34 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 10000)
store i32 %34, i32* %2
%35 = load i32, i32* %2
%36 = icmp eq i32 %35, 5
%37 = zext i1 %36 to i32
%38 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%40 = call i32 @strlen(i8* %39)
%41 = icmp eq i32 %40, 2
%42 = zext i1 %41 to i32
%43 = call i32 @assertTrue(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 49
%48 = zext i1 %47 to i32
%49 = call i32 @assertTrue(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 %48)
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 48
%54 = zext i1 %53 to i32
%55 = call i32 @assertTrue(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0), i32 %54)
%56 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 0
%60 = zext i1 %59 to i32
%61 = call i32 @assertTrue(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %60)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"0%s\00"
@.str.1 = [5 x i8] c"1234\00"
@.str.2 = [6 x i8] c"01234\00"
@.str.3 = [9 x i8] c"ret == 5\00"
@.str.4 = [6 x i8] c"12345\00"
@.str.5 = [9 x i8] c"ret == 6\00"
@.str.6 = [8 x i8] c"1234567\00"
@.str.7 = [9 x i8] c"ret == 8\00"
@.str.8 = [13 x i8] c"hello, world\00"
@.str.9 = [10 x i8] c"ret == 12\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [21 x i8] c"strlen(buffer) == 2U\00"
@.str.12 = [17 x i8] c"buffer[0] == '1'\00"
@.str.13 = [17 x i8] c"buffer[1] == '0'\00"
@.str.14 = [18 x i8] c"buffer[2] == '\\0'\00"
define void @test_ret_value() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%5 = icmp eq i32 %3, 5
%6 = zext i1 %5 to i32
%7 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %6)
%8 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%9 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32 %8, 6
%11 = zext i1 %10 to i32
%12 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %11)
%13 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%14 = call i32 @assertStringsEqual(i8* %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = icmp eq i32 %13, 8
%16 = zext i1 %15 to i32
%17 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%19 = icmp eq i32 %18, 12
%20 = zext i1 %19 to i32
%21 = call i32 @assertTrue(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i32 %20)
%22 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %2, i32 3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 10000)
%23 = icmp eq i32 %22, 5
%24 = zext i1 %23 to i32
%25 = call i32 @assertTrue(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = call i32 @strlen(i8* %2)
%27 = icmp eq i32 %26, 2
%28 = zext i1 %27 to i32
%29 = call i32 @assertTrue(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0), i32 %28)
%30 = load i8, i8* %2
%31 = icmp eq i8 %30, 49
%32 = zext i1 %31 to i32
%33 = call i32 @assertTrue(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.12, i64 0, i64 0), i32 %32)
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
%35 = load i8, i8* %34
%36 = icmp eq i8 %35, 48
%37 = zext i1 %36 to i32
%38 = call i32 @assertTrue(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0), i32 %37)
%39 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 0
%42 = zext i1 %41 to i32
%43 = call i32 @assertTrue(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %42)
ret void
}