#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*/ dump_buffer(char *, int, char *);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ netfree(char *);
char *netmalloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, int, char *);
void *thread2_main(void *param) {
  (void)param;
  printf("Thread2\n");
  char *buffer = netmalloc(5000);
  memset(buffer, 'B', 1000);
  memset(buffer + 1000, 'b', 4000);
  sprintf(buffer + 4500, "foo %d %s", 18, "thread 2 string");
  dump_buffer(buffer, 5000, "t2");
  netfree(buffer);
  return NULL;
}


x86 assembly (clang, -O0):
<thread2_main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1388,%edi
call   1080 <netmalloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x42,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
add    $0x3e8,%rdi
mov    $0x62,%esi
mov    $0xfa0,%edx
call   1050 <memset@plt>
mov    -0x10(%rbp),%rdi
add    $0x1194,%rdi
lea    0xe44(%rip),%rsi
mov    $0x12,%edx
lea    0xe42(%rip),%rcx
call   1070 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1388,%esi
lea    0xe3d(%rip),%rdx
call   1060 <dump_buffer@plt>
mov    -0x10(%rbp),%rdi
call   1030 <netfree@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread2_main>:
push   %rbx
lea    0xeb5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1388,%edi
call   1080 <netmalloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x42,%esi
mov    $0x3e8,%edx
call   1050 <memset@plt>
lea    0x3e8(%rbx),%rdi
mov    $0x62,%esi
mov    $0xfa0,%edx
call   1050 <memset@plt>
lea    0x1194(%rbx),%rdi
lea    0xe50(%rip),%rsi
lea    0xe53(%rip),%rcx
mov    $0x12,%edx
call   1070 <sprintf@plt>
lea    0xe52(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1388,%esi
call   1060 <dump_buffer@plt>
mov    %rbx,%rdi
call   1030 <netfree@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Thread2\0A\00"
@.str.1 = [10 x i8] c"foo %d %s\00"
@.str.2 = [16 x i8] c"thread 2 string\00"
@.str.3 = [3 x i8] c"t2\00"
define i8* @thread2_main(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%6 = call i8* @netmalloc(i32 5000)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @memset(i8* %7, i8 signext 66, i32 1000)
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 1000
%11 = call i32 @memset(i8* %10, i8 signext 98, i32 4000)
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 4500
%14 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%15 = load i8*, i8** %3
%16 = call i32 @dump_buffer(i8* %15, i32 5000, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = load i8*, i8** %3
%18 = call i32 @netfree(i8* %17)
ret i8* null
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"foo %d %s\00"
@.str.2 = [16 x i8] c"thread 2 string\00"
@.str.3 = [3 x i8] c"t2\00"
@str = [8 x i8] c"Thread2\00"
define noalias i8* @thread2_main(i8* nocapture readnone %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%3 = tail call i8* @netmalloc(i32 5000)
%4 = tail call i32 @memset(i8* %3, i8 signext 66, i32 1000)
%5 = getelementptr inbounds i8, i8* %3, i64 1000
%6 = tail call i32 @memset(i8* %5, i8 signext 98, i32 4000)
%7 = getelementptr inbounds i8, i8* %3, i64 4500
%8 = tail call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 18, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @dump_buffer(i8* %3, i32 5000, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%10 = tail call i32 @netfree(i8* %3)
ret i8* null
}