#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();
  return (void *)0;
}


x86 assembly (clang, -O0):
<threadFunc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%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,-0x10(%rbp)
lea    0xea7(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xeb5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getchar@plt>
xor    %eax,%eax
add    $0x10,%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
call   1050 <getchar@plt>
xor    %eax,%eax
pop    %rbx
ret

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*
store i8* %0, i8** %2
%4 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @getchar()
%6 = call i64 @malloc(i32 1000)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %3
%8 = call i32 @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 (...) @getchar()
%10 = load i8*, i8** %3
%11 = call i32 @free(i8* %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (...) @getchar()
ret i8* null
}

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* null
}