#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*/ free(char *);
int /*<<< orphan*/ getchar();
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
void *threadFunc(void *arg) {
  printf("Before malloc in thread 1\n");
  getchar();
  char *addr = (char *)malloc(1000);
  printf("After malloc and before free in thread 1\n");
  getchar();
  free(addr);
  printf("After free in thread 1\n");
  getchar();
}


x86 assembly (clang, -O0):
<threadFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xead(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<threadFunc>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    $0x3e8,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xec0(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
jmp    1050 <getchar@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Before malloc in thread 1\0A\00"
@.str.1 = [42 x i8] c"After malloc and before free in thread 1\0A\00"
@.str.2 = [24 x i8] c"After free in thread 1\0A\00"
define i8* @threadFunc(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (...) @getchar()
%7 = call i64 @malloc(i32 1000)
%8 = inttoptr i64 %7 to i8*
store i8* %8, i8** %4
%9 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @getchar()
%11 = load i8*, i8** %4
%12 = call i32 @free(i8* %11)
%13 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 (...) @getchar()
%15 = load i8*, i8** %2
ret i8* %15
}

LLVM IR (-O2):
@str = [26 x i8] c"Before malloc in thread 1\00"
@str.3 = [41 x i8] c"After malloc and before free in thread 1\00"
@str.4 = [23 x i8] c"After free in thread 1\00"
define noalias i8* @threadFunc(i8* nocapture readnone %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @getchar()
%4 = tail call i64 @malloc(i32 1000)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 (...) @getchar()
%8 = tail call i32 @free(i8* %5)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.4, i64 0, i64 0))
%10 = tail call i32 (...) @getchar()
ret i8* undef
}