#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_gui_buffer {
  int dummy;
};
typedef int /*<<< orphan*/ str_buffer;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ gui_history_buffer_add(struct t_gui_buffer *, char *);
int /*<<< orphan*/ gui_history_global_add(char *);
char *hook_modifier_exec(int /*<<< orphan*/ *, char *, char *, char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long);
void gui_history_add(struct t_gui_buffer *buffer, const char *string) {
  char *string2, str_buffer[128];
  snprintf(str_buffer, sizeof(str_buffer), "0x%lx",
           (long unsigned int)(buffer));
  string2 = hook_modifier_exec(NULL, "history_add", str_buffer, string);
  if (!string2 || string2[0]) {
    gui_history_buffer_add(buffer, (string2) ? string2 : string);
    gui_history_global_add((string2) ? string2 : string);
  }
  if (string2)
    free(string2);
}


x86 assembly (clang, -O0):
<gui_history_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x80,%esi
lea    0xe86(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xa0(%rbp),%rdx
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe71(%rip),%rsi
call   1060 <hook_modifier_exec@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b9 <gui_history_add+0x69>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122f <gui_history_add+0xdf>
mov    -0x8(%rbp),%rax
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11df <gui_history_add+0x8f>
mov    -0x18(%rbp),%rax
mov    %rax,-0xb0(%rbp)
jmp    11ea <gui_history_add+0x9a>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0xa8(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
call   1050 <gui_history_buffer_add@plt>
cmpq   $0x0,-0x18(%rbp)
je     1218 <gui_history_add+0xc8>
mov    -0x18(%rbp),%rax
mov    %rax,-0xb8(%rbp)
jmp    1223 <gui_history_add+0xd3>
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0xb8(%rbp),%rdi
call   1070 <gui_history_global_add@plt>
cmpq   $0x0,-0x18(%rbp)
je     1243 <gui_history_add+0xf3>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_history_add>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe97(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xe83(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %r15,%rcx
call   1060 <hook_modifier_exec@plt>
test   %rax,%rax
je     11ba <gui_history_add+0x6a>
mov    %rax,%rbx
cmpb   $0x0,(%rax)
je     11b0 <gui_history_add+0x60>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <gui_history_buffer_add@plt>
mov    %rbx,%rdi
call   1070 <gui_history_global_add@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11cd <gui_history_add+0x7d>
mov    %r14,%rdi
mov    %r15,%rsi
call   1050 <gui_history_buffer_add@plt>
mov    %r15,%rdi
call   1070 <gui_history_global_add@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.t_gui_buffer = type { i32 }
@.str = [6 x i8] c"0x%lx\00"
@.str.1 = [12 x i8] c"history_add\00"
define void @gui_history_add(%struct.t_gui_buffer* %0, i8* %1) {
%3 = alloca %struct.t_gui_buffer*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [128 x i8]
store %struct.t_gui_buffer* %0, %struct.t_gui_buffer** %3
store i8* %1, i8** %4
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%8 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%9 = ptrtoint %struct.t_gui_buffer* %8 to i64
%10 = call i32 @snprintf(i8* %7, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%12 = load i8*, i8** %4
%13 = call i8* @hook_modifier_exec(i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %12)
store i8* %13, i8** %5
%14 = load i8*, i8** %5
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %22
16: ; preds = %2
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %42
22: ; preds = %16, %2
%23 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %3
%24 = load i8*, i8** %5
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = load i8*, i8** %5
br label %30
28: ; preds = %22
%29 = load i8*, i8** %4
br label %30
30: ; preds = %28, %26
%31 = phi i8* [ %27, %26 ], [ %29, %28 ]
%32 = call i32 @gui_history_buffer_add(%struct.t_gui_buffer* %23, i8* %31)
%33 = load i8*, i8** %5
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = load i8*, i8** %5
br label %39
37: ; preds = %30
%38 = load i8*, i8** %4
br label %39
39: ; preds = %37, %35
%40 = phi i8* [ %36, %35 ], [ %38, %37 ]
%41 = call i32 @gui_history_global_add(i8* %40)
br label %42
42: ; preds = %39, %16
%43 = load i8*, i8** %5
%44 = icmp ne i8* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = load i8*, i8** %5
%47 = call i32 @free(i8* %46)
br label %48
48: ; preds = %45, %42
ret void
}

LLVM IR (-O2):
%struct.t_gui_buffer = type { i32 }
@.str = [6 x i8] c"0x%lx\00"
@.str.1 = [12 x i8] c"history_add\00"
define void @gui_history_add(%struct.t_gui_buffer* %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = ptrtoint %struct.t_gui_buffer* %0 to i64
%6 = call i32 @snprintf(i8* %4, i32 128, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %5)
%7 = call i8* @hook_modifier_exec(i32* null, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %17, label %9
9: ; preds = %2
%10 = load i8, i8* %7
%11 = icmp eq i8 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = call i32 @gui_history_buffer_add(%struct.t_gui_buffer* %0, i8* %7)
%14 = call i32 @gui_history_global_add(i8* %7)
br label %15
15: ; preds = %12, %9
%16 = call i32 @free(i8* %7)
br label %20
17: ; preds = %2
%18 = call i32 @gui_history_buffer_add(%struct.t_gui_buffer* %0, i8* %1)
%19 = call i32 @gui_history_global_add(i8* %1)
br label %20
20: ; preds = %17, %15
ret void
}