#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*/ netfree(char *);
char *netmalloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *);
int main(void) {
  char *buffer = netmalloc(5120);
  sprintf(buffer, "toto");
  sprintf(buffer + 4094, "foobar");
  printf("toto = %s\n", buffer);
  printf("foobar = %s\n", buffer + 4094);
  netfree(buffer);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1400,%edi
call   1060 <netmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
add    $0xffe,%rdi
lea    0xe86(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rsi
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
add    $0xffe,%rsi
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <netfree@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x1400,%edi
call   1050 <netmalloc@plt>
mov    %rax,%rbx
movl   $0x6f746f74,(%rax)
movb   $0x0,0x4(%rax)
lea    0xffe(%rax),%r14
movl   $0x626f6f66,0xffe(%rax)
6f 6f 62
movl   $0x726162,0x1001(%rax)
lea    0xe9f(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xe9b(%rip),%rdi
mov    %r14,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <netfree@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [5 x i8] c"toto\00"
@.str.1 = [7 x i8] c"foobar\00"
@.str.2 = [11 x i8] c"toto = %s\0A\00"
@.str.3 = [13 x i8] c"foobar = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
store i32 0, i32* %1
%3 = call i8* @netmalloc(i32 5120)
store i8* %3, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @sprintf(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i8*, i8** %2
%7 = getelementptr inbounds i8, i8* %6, i64 4094
%8 = call i32 @sprintf(i8* %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = load i8*, i8** %2
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i64 4094
%13 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %2
%15 = call i32 @netfree(i8* %14)
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"toto\00"
@.str.1 = [7 x i8] c"foobar\00"
@.str.2 = [11 x i8] c"toto = %s\0A\00"
@.str.3 = [13 x i8] c"foobar = %s\0A\00"
define i32 @main() {
%1 = tail call i8* @netmalloc(i32 5120)
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(5) %1, i8* align 1 dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 5, i1 false)
%2 = getelementptr inbounds i8, i8* %1, i64 4094
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(7) %2, i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 7, i1 false)
%3 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i8* %2)
%5 = tail call i32 @netfree(i8* %1)
ret i32 0
}