#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*/ assert(int);
int /*<<< orphan*/ free(char *);
size_t netstring_encode_new(char **, char *, int);
scalar_t__ strncmp(char *, char *, int);
void test_netstring_encode_new(void) {
  char *ns;
  size_t bytes;
  bytes = netstring_encode_new(&ns, "foo", 3);
  assert(ns != NULL);
  assert(strncmp(ns, "3:foo,", 6) == 0);
  assert(bytes == 6);
  free(ns);
  bytes = netstring_encode_new(&ns, NULL, 0);
  assert(ns != NULL);
  assert(strncmp(ns, "0:,", 3) == 0);
  assert(bytes == 3);
  free(ns);
  bytes = netstring_encode_new(&ns, "hello world!", 12);
  assert(bytes == 16);
  assert(ns != NULL);
  assert(strncmp(ns, "12:hello world!,", 16) == 0);
  free(ns);
}


x86 assembly (clang, -O0):
<test_netstring_encode_new>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
lea    0xead(%rip),%rsi
mov    $0x3,%edx
call   1050 <netstring_encode_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe86(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x6,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <netstring_encode_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xe27(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x3,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    -0x8(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0xc,%edx
call   1050 <netstring_encode_new@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x10,-0x10(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
lea    0xdba(%rip),%rsi
mov    $0x10,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_netstring_encode_new>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x3,%edx
call   1050 <netstring_encode_new@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setne  %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
lea    0xe8b(%rip),%rsi
mov    $0x6,%edx
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmp    $0x6,%rbx
sete   %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <netstring_encode_new@plt>
mov    %rax,%rbx
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setne  %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
lea    0xe38(%rip),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmp    $0x3,%rbx
sete   %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
lea    0xe05(%rip),%rsi
mov    %r14,%rdi
mov    $0xc,%edx
call   1050 <netstring_encode_new@plt>
xor    %edi,%edi
cmp    $0x10,%rax
sete   %dil
call   1060 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,(%rsp)
setne  %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
lea    0xddb(%rip),%rsi
mov    $0x10,%edx
call   1040 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1060 <assert@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"foo\00"
@.str.1 = [7 x i8] c"3:foo,\00"
@.str.2 = [4 x i8] c"0:,\00"
@.str.3 = [13 x i8] c"hello world!\00"
@.str.4 = [17 x i8] c"12:hello world!,\00"
define void @test_netstring_encode_new() {
%1 = alloca i8*
%2 = alloca i64
%3 = call i64 @netstring_encode_new(i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
store i64 %3, i64* %2
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %1
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i64, i64* %2
%14 = icmp eq i64 %13, 6
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
%17 = load i8*, i8** %1
%18 = call i32 @free(i8* %17)
%19 = call i64 @netstring_encode_new(i8** %1, i8* null, i32 0)
store i64 %19, i64* %2
%20 = load i8*, i8** %1
%21 = icmp ne i8* %20, null
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i8*, i8** %1
%25 = call i64 @strncmp(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
%28 = call i32 @assert(i32 %27)
%29 = load i64, i64* %2
%30 = icmp eq i64 %29, 3
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load i8*, i8** %1
%34 = call i32 @free(i8* %33)
%35 = call i64 @netstring_encode_new(i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 12)
store i64 %35, i64* %2
%36 = load i64, i64* %2
%37 = icmp eq i64 %36, 16
%38 = zext i1 %37 to i32
%39 = call i32 @assert(i32 %38)
%40 = load i8*, i8** %1
%41 = icmp ne i8* %40, null
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = load i8*, i8** %1
%45 = call i64 @strncmp(i8* %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 16)
%46 = icmp eq i64 %45, 0
%47 = zext i1 %46 to i32
%48 = call i32 @assert(i32 %47)
%49 = load i8*, i8** %1
%50 = call i32 @free(i8* %49)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"foo\00"
@.str.1 = [7 x i8] c"3:foo,\00"
@.str.2 = [4 x i8] c"0:,\00"
@.str.3 = [13 x i8] c"hello world!\00"
@.str.4 = [17 x i8] c"12:hello world!,\00"
define void @test_netstring_encode_new() {
%1 = alloca i8*
%2 = bitcast i8** %1 to i8*
%3 = call i64 @netstring_encode_new(i8** %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 3)
%4 = load i8*, i8** %1
%5 = icmp ne i8* %4, null
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = load i8*, i8** %1
%9 = call i64 @strncmp(i8* %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 6)
%10 = icmp eq i64 %9, 0
%11 = zext i1 %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = icmp eq i64 %3, 6
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %1
%17 = call i32 @free(i8* %16)
%18 = call i64 @netstring_encode_new(i8** %1, i8* null, i32 0)
%19 = load i8*, i8** %1
%20 = icmp ne i8* %19, null
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i8*, i8** %1
%24 = call i64 @strncmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 3)
%25 = icmp eq i64 %24, 0
%26 = zext i1 %25 to i32
%27 = call i32 @assert(i32 %26)
%28 = icmp eq i64 %18, 3
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i8*, i8** %1
%32 = call i32 @free(i8* %31)
%33 = call i64 @netstring_encode_new(i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 12)
%34 = icmp eq i64 %33, 16
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = load i8*, i8** %1
%38 = icmp ne i8* %37, null
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i8*, i8** %1
%42 = call i64 @strncmp(i8* %41, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0), i32 16)
%43 = icmp eq i64 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i8*, i8** %1
%47 = call i32 @free(i8* %46)
ret void
}