#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*/ printf(char *, int, char *);
int /*<<< orphan*/ pthread_self();
void my_free(void *arg) {
  int i;
  printf("[%lu] freeing 0x%x\n", pthread_self(), arg);
  char **envbuf = (char **)arg;
  for (i = 0; envbuf[i] != NULL; ++i) {
    printf("free %d: %s\n", i, envbuf[i]);
    free(envbuf[i]);
  }
  free((char *)envbuf);
}


x86 assembly (clang, -O0):
<my_free>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%esi
mov    -0x8(%rbp),%rdx
lea    0xeb0(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11b1 <my_free+0x81>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1164 <my_free+0x34>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_free>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <pthread_self@plt>
lea    0xeba(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
call   1040 <printf@plt>
mov    (%r14),%rdx
test   %rdx,%rdx
je     1191 <my_free+0x61>
xor    %ebx,%ebx
lea    0xeb3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    (%r14,%rbx,8),%rdi
call   1030 <free@plt>
mov    0x8(%r14,%rbx,8),%rdx
add    $0x1,%rbx
test   %rdx,%rdx
jne    1170 <my_free+0x40>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"[%lu] freeing 0x%x\0A\00"
@.str.1 = [13 x i8] c"free %d: %s\0A\00"
define void @my_free(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8**
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
%6 = load i8*, i8** %2
%7 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %6)
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to i8**
store i8** %9, i8*** %4
store i32 0, i32* %3
br label %10
10: ; preds = %31, %1
%11 = load i8**, i8*** %4
%12 = load i32, i32* %3
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8*, i8** %11, i64 %13
%15 = load i8*, i8** %14
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %34
17: ; preds = %10
%18 = load i32, i32* %3
%19 = load i8**, i8*** %4
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %18, i8* %23)
%25 = load i8**, i8*** %4
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
%30 = call i32 @free(i8* %29)
br label %31
31: ; preds = %17
%32 = load i32, i32* %3
%33 = add nsw i32 %32, 1
store i32 %33, i32* %3
br label %10
34: ; preds = %10
%35 = load i8**, i8*** %4
%36 = bitcast i8** %35 to i8*
%37 = call i32 @free(i8* %36)
ret void
}

LLVM IR (-O2):
@.str = [20 x i8] c"[%lu] freeing 0x%x\0A\00"
@.str.1 = [13 x i8] c"free %d: %s\0A\00"
define void @my_free(i8* %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2, i8* %0)
%4 = bitcast i8* %0 to i8**
%5 = load i8*, i8** %4
%6 = icmp eq i8* %5, null
br i1 %6, label %19, label %7
7: ; preds = %1, %7
%8 = phi i64 [ %15, %7 ], [ 0, %1 ]
%9 = phi i8* [ %17, %7 ], [ %5, %1 ]
%10 = phi i8** [ %16, %7 ], [ %4, %1 ]
%11 = trunc i64 %8 to i32
%12 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %11, i8* %9)
%13 = load i8*, i8** %10
%14 = tail call i32 @free(i8* %13)
%15 = add nuw i64 %8, 1
%16 = getelementptr inbounds i8*, i8** %4, i64 %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %7
19: ; preds = %7, %1
%20 = tail call i32 @free(i8* %0)
ret void
}