#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*/ printf(char *, ...);
void log_func(const void *mp_p, const int func_id,
              const unsigned long byte_size, const unsigned long ele_n,
              const void *new_addr, const void *old_addr,
              const unsigned long old_byte_size) {
  (void)printf("mp %#lx ", (long)mp_p);
  switch (func_id) {
  case 1:
    (void)printf("close\n");
    break;
  case 2:
    (void)printf("clear\n");
    break;
  case 3:
    (void)printf("alloc %lu bytes got %#lx\n", byte_size, (long)new_addr);
    break;
  case 4:
    (void)printf("calloc %lu ele size, %lu ele number, got %#lx\n", byte_size,
                 ele_n, (long)new_addr);
    break;
  case 5:
    (void)printf("free %#lx of %lu bytes\n", (long)old_addr, byte_size);
    break;
  case 6:
    (void)printf("resize %#lx of %lu bytes to %lu bytes, got %#lx\n",
                 (long)old_addr, old_byte_size, byte_size, (long)new_addr);
    break;
  default:
    (void)printf("unknown function %d, %lu bytes\n", func_id, byte_size);
    break;
  }
}


x86 assembly (clang, -O0):
<log_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x5,%eax
ja     120c <log_func+0xfc>
mov    -0x38(%rbp),%rax
lea    0xe9b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <log_func+0x111>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <log_func+0x111>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <log_func+0x111>
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <log_func+0x111>
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xe9b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <log_func+0x111>
mov    -0x30(%rbp),%rsi
mov    0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1221 <log_func+0x111>
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_func>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r15
mov    %r8,%r14
mov    %rcx,%r12
mov    %rdx,%r13
mov    %esi,%ebp
mov    %rdi,%rsi
mov    0x40(%rsp),%rbx
lea    0xed0(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    -0x1(%rbp),%eax
cmp    $0x5,%eax
ja     1170 <log_func+0x50>
lea    0xea2(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf6b(%rip),%rdi
jmp    1198 <log_func+0x78>
lea    0xf3c(%rip),%rdi
mov    %ebp,%esi
mov    %r13,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xf3b(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>
lea    0xe6f(%rip),%rdi
mov    %r13,%rsi
mov    %r14,%rdx
jmp    11ec <log_func+0xcc>
lea    0xe7a(%rip),%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %r14,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe84(%rip),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe7a(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %r13,%rcx
mov    %r14,%r8
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"mp %#lx \00"
@.str.1 = [7 x i8] c"close\0A\00"
@.str.2 = [7 x i8] c"clear\0A\00"
@.str.3 = [26 x i8] c"alloc %lu bytes got %#lx\0A\00"
@.str.4 = [47 x i8] c"calloc %lu ele size, %lu ele number, got %#lx\0A\00"
@.str.5 = [24 x i8] c"free %#lx of %lu bytes\0A\00"
@.str.6 = [49 x i8] c"resize %#lx of %lu bytes to %lu bytes, got %#lx\0A\00"
@.str.7 = [32 x i8] c"unknown function %d, %lu bytes\0A\00"
define void @log_func(i8* %0, i32 %1, i64 %2, i64 %3, i8* %4, i8* %5, i64 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
store i8* %0, i8** %8
store i32 %1, i32* %9
store i64 %2, i64* %10
store i64 %3, i64* %11
store i8* %4, i8** %12
store i8* %5, i8** %13
store i64 %6, i64* %14
%15 = load i8*, i8** %8
%16 = ptrtoint i8* %15 to i64
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = load i32, i32* %9
switch i32 %18, label %47 [
i32 1, label %19
i32 2, label %21
i32 3, label %23
i32 4, label %28
i32 5, label %34
i32 6, label %39
]
19: ; preds = %7
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %51
21: ; preds = %7
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
br label %51
23: ; preds = %7
%24 = load i64, i64* %10
%25 = load i8*, i8** %12
%26 = ptrtoint i8* %25 to i64
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %24, i64 %26)
br label %51
28: ; preds = %7
%29 = load i64, i64* %10
%30 = load i64, i64* %11
%31 = load i8*, i8** %12
%32 = ptrtoint i8* %31 to i64
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i64 %29, i64 %30, i64 %32)
br label %51
34: ; preds = %7
%35 = load i8*, i8** %13
%36 = ptrtoint i8* %35 to i64
%37 = load i64, i64* %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 %36, i64 %37)
br label %51
39: ; preds = %7
%40 = load i8*, i8** %13
%41 = ptrtoint i8* %40 to i64
%42 = load i64, i64* %14
%43 = load i64, i64* %10
%44 = load i8*, i8** %12
%45 = ptrtoint i8* %44 to i64
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i64 %41, i64 %42, i64 %43, i64 %45)
br label %51
47: ; preds = %7
%48 = load i32, i32* %9
%49 = load i64, i64* %10
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %48, i64 %49)
br label %51
51: ; preds = %47, %39, %34, %28, %23, %21, %19
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"mp %#lx \00"
@.str.3 = [26 x i8] c"alloc %lu bytes got %#lx\0A\00"
@.str.4 = [47 x i8] c"calloc %lu ele size, %lu ele number, got %#lx\0A\00"
@.str.5 = [24 x i8] c"free %#lx of %lu bytes\0A\00"
@.str.6 = [49 x i8] c"resize %#lx of %lu bytes to %lu bytes, got %#lx\0A\00"
@.str.7 = [32 x i8] c"unknown function %d, %lu bytes\0A\00"
@str = [6 x i8] c"clear\00"
@str.8 = [6 x i8] c"close\00"
define void @log_func(i8* %0, i32 %1, i64 %2, i64 %3, i8* %4, i8* %5, i64 %6) {
%8 = ptrtoint i8* %0 to i64
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %8)
switch i32 %1, label %27 [
i32 1, label %10
i32 2, label %12
i32 3, label %14
i32 4, label %17
i32 5, label %20
i32 6, label %23
]
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.8, i64 0, i64 0))
br label %29
12: ; preds = %7
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0))
br label %29
14: ; preds = %7
%15 = ptrtoint i8* %4 to i64
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i64 %2, i64 %15)
br label %29
17: ; preds = %7
%18 = ptrtoint i8* %4 to i64
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0), i64 %2, i64 %3, i64 %18)
br label %29
20: ; preds = %7
%21 = ptrtoint i8* %5 to i64
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i64 %21, i64 %2)
br label %29
23: ; preds = %7
%24 = ptrtoint i8* %5 to i64
%25 = ptrtoint i8* %4 to i64
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0), i64 %24, i64 %6, i64 %2, i64 %25)
br label %29
27: ; preds = %7
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0), i32 %1, i64 %2)
br label %29
29: ; preds = %27, %23, %20, %17, %14, %12, %10
ret void
}