#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 */
struct t_hashtable {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ hashtable_set(struct t_hashtable *, char *, char const *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strlen(char const *);
void hook_focus_hashtable_map2_cb(void *data, struct t_hashtable *hashtable,
                                  const void *key, const void *value) {
  struct t_hashtable *hashtable1;
  int length;
  char *key2;
  (void)hashtable;
  hashtable1 = (struct t_hashtable *)data;
  length = strlen((const char *)key) + 1 + 1;
  key2 = malloc(length);
  if (key2) {
    snprintf(key2, length, "%s2", (const char *)key);
    if (hashtable1 && key && value)
      hashtable_set(hashtable1, key2, (const char *)value);
    free(key2);
  }
}


x86 assembly (clang, -O0):
<hook_focus_hashtable_map2_cb>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11eb <hook_focus_hashtable_map2_cb+0x9b>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xe55(%rip),%rdx
call   1060 <snprintf@plt>
cmpq   $0x0,-0x28(%rbp)
je     11e2 <hook_focus_hashtable_map2_cb+0x92>
cmpq   $0x0,-0x18(%rbp)
je     11e2 <hook_focus_hashtable_map2_cb+0x92>
cmpq   $0x0,-0x20(%rbp)
je     11e2 <hook_focus_hashtable_map2_cb+0x92>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1040 <hashtable_set@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hook_focus_hashtable_map2_cb>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rdi,%r15
mov    %rdx,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
add    $0x2,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11be <hook_focus_hashtable_map2_cb+0x6e>
mov    %rax,%rbx
lea    0xe7c(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r12,%rcx
call   1060 <snprintf@plt>
test   %r15,%r15
je     11ae <hook_focus_hashtable_map2_cb+0x5e>
test   %r12,%r12
je     11ae <hook_focus_hashtable_map2_cb+0x5e>
test   %r14,%r14
je     11ae <hook_focus_hashtable_map2_cb+0x5e>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1040 <hashtable_set@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.t_hashtable = type { i32 }
@.str = [4 x i8] c"%s2\00"
define void @hook_focus_hashtable_map2_cb(i8* %0, %struct.t_hashtable* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca %struct.t_hashtable*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca %struct.t_hashtable*
%10 = alloca i32
%11 = alloca i8*
store i8* %0, i8** %5
store %struct.t_hashtable* %1, %struct.t_hashtable** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%12 = load %struct.t_hashtable*, %struct.t_hashtable** %6
%13 = load i8*, i8** %5
%14 = bitcast i8* %13 to %struct.t_hashtable*
store %struct.t_hashtable* %14, %struct.t_hashtable** %9
%15 = load i8*, i8** %7
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %10
%19 = load i32, i32* %10
%20 = call i8* @malloc(i32 %19)
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %44
23: ; preds = %4
%24 = load i8*, i8** %11
%25 = load i32, i32* %10
%26 = load i8*, i8** %7
%27 = call i32 @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = load %struct.t_hashtable*, %struct.t_hashtable** %9
%29 = icmp ne %struct.t_hashtable* %28, null
br i1 %29, label %30, label %41
30: ; preds = %23
%31 = load i8*, i8** %7
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %41
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %41
36: ; preds = %33
%37 = load %struct.t_hashtable*, %struct.t_hashtable** %9
%38 = load i8*, i8** %11
%39 = load i8*, i8** %8
%40 = call i32 @hashtable_set(%struct.t_hashtable* %37, i8* %38, i8* %39)
br label %41
41: ; preds = %36, %33, %30, %23
%42 = load i8*, i8** %11
%43 = call i32 @free(i8* %42)
br label %44
44: ; preds = %41, %4
ret void
}

LLVM IR (-O2):
%struct.t_hashtable = type { i32 }
@.str = [4 x i8] c"%s2\00"
define void @hook_focus_hashtable_map2_cb(i8* %0, %struct.t_hashtable* nocapture readnone %1, i8* %2, i8* %3) {
%5 = bitcast i8* %0 to %struct.t_hashtable*
%6 = tail call i32 @strlen(i8* %2)
%7 = add nsw i32 %6, 2
%8 = tail call i8* @malloc(i32 %7)
%9 = icmp eq i8* %8, null
br i1 %9, label %21, label %10
10: ; preds = %4
%11 = tail call i32 @snprintf(i8* %8, i32 %7, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
%12 = icmp ne i8* %0, null
%13 = icmp ne i8* %2, null
%14 = and i1 %12, %13
%15 = icmp ne i8* %3, null
%16 = and i1 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = tail call i32 @hashtable_set(%struct.t_hashtable* %5, i8* %8, i8* %3)
br label %19
19: ; preds = %17, %10
%20 = tail call i32 @free(i8* %8)
br label %21
21: ; preds = %19, %4
ret void
}