#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;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ hook_signal_send(char const *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned long, char const *);
int strlen(char const *);
void gui_nicklist_send_signal(const char *signal, struct t_gui_buffer *buffer,
                              const char *arguments) {
  char *str_args;
  int length;
  if (buffer) {
    length = 128 + ((arguments) ? strlen(arguments) : 0) + 1 + 1;
    str_args = malloc(length);
    if (str_args) {
      snprintf(str_args, length, "0x%lx,%s", (long unsigned int)(buffer),
               (arguments) ? arguments : "");
      (void)hook_signal_send(signal, "string", str_args);
      free(str_args);
    }
  } else {
    (void)hook_signal_send(signal, "string", (char *)arguments);
  }
}


x86 assembly (clang, -O0):
<gui_nicklist_send_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1238 <gui_nicklist_send_signal+0xe8>
cmpq   $0x0,-0x18(%rbp)
je     118b <gui_nicklist_send_signal+0x3b>
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
jmp    1195 <gui_nicklist_send_signal+0x45>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    1195 <gui_nicklist_send_signal+0x45>
mov    -0x28(%rbp),%eax
add    $0x80,%eax
add    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1233 <gui_nicklist_send_signal+0xe3>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11eb <gui_nicklist_send_signal+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
jmp    11fb <gui_nicklist_send_signal+0xab>
lea    0xe1d(%rip),%rax
mov    %rax,-0x48(%rbp)
jmp    11fb <gui_nicklist_send_signal+0xab>
mov    -0x30(%rbp),%rcx
mov    -0x34(%rbp),%esi
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%r8
lea    0xdef(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xde4(%rip),%rsi
call   1060 <hook_signal_send@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    124c <gui_nicklist_send_signal+0xfc>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xdc2(%rip),%rsi
call   1060 <hook_signal_send@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_nicklist_send_signal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
je     117d <gui_nicklist_send_signal+0x2d>
mov    %rsi,%r15
test   %rbx,%rbx
je     1197 <gui_nicklist_send_signal+0x47>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0x82,%ebp
jmp    119c <gui_nicklist_send_signal+0x4c>
lea    0xe85(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <hook_signal_send@plt>
mov    $0x82,%ebp
mov    %ebp,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11ef <gui_nicklist_send_signal+0x9f>
mov    %rax,%r12
test   %rbx,%rbx
lea    0xe5a(%rip),%r8
cmovne %rbx,%r8
lea    0xe40(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
call   1050 <snprintf@plt>
lea    0xe35(%rip),%rsi
mov    %r14,%rdi
mov    %r12,%rdx
call   1060 <hook_signal_send@plt>
mov    %r12,%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_gui_buffer = type { i32 }
@.str = [9 x i8] c"0x%lx,%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"string\00"
define void @gui_nicklist_send_signal(i8* %0, %struct.t_gui_buffer* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca %struct.t_gui_buffer*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store %struct.t_gui_buffer* %1, %struct.t_gui_buffer** %5
store i8* %2, i8** %6
%9 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %5
%10 = icmp ne %struct.t_gui_buffer* %9, null
br i1 %10, label %11, label %46
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i8*, i8** %6
%16 = call i32 @strlen(i8* %15)
br label %18
17: ; preds = %11
br label %18
18: ; preds = %17, %14
%19 = phi i32 [ %16, %14 ], [ 0, %17 ]
%20 = add nsw i32 128, %19
%21 = add nsw i32 %20, 1
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = call i8* @malloc(i32 %23)
store i8* %24, i8** %7
%25 = load i8*, i8** %7
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %45
27: ; preds = %18
%28 = load i8*, i8** %7
%29 = load i32, i32* %8
%30 = load %struct.t_gui_buffer*, %struct.t_gui_buffer** %5
%31 = ptrtoint %struct.t_gui_buffer* %30 to i64
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %27
%35 = load i8*, i8** %6
br label %37
36: ; preds = %27
br label %37
37: ; preds = %36, %34
%38 = phi i8* [ %35, %34 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %36 ]
%39 = call i32 @snprintf(i8* %28, i32 %29, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %31, i8* %38)
%40 = load i8*, i8** %4
%41 = load i8*, i8** %7
%42 = call i32 @hook_signal_send(i8* %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
br label %45
45: ; preds = %37, %18
br label %50
46: ; preds = %3
%47 = load i8*, i8** %4
%48 = load i8*, i8** %6
%49 = call i32 @hook_signal_send(i8* %47, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %46, %45
ret void
}

LLVM IR (-O2):
%struct.t_gui_buffer = type { i32 }
@.str = [9 x i8] c"0x%lx,%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [7 x i8] c"string\00"
define void @gui_nicklist_send_signal(i8* %0, %struct.t_gui_buffer* %1, i8* %2) {
%4 = icmp eq %struct.t_gui_buffer* %1, null
br i1 %4, label %20, label %5
5: ; preds = %3
%6 = icmp eq i8* %2, null
br i1 %6, label %10, label %7
7: ; preds = %5
%8 = tail call i32 @strlen(i8* %2)
%9 = add i32 %8, 130
br label %10
10: ; preds = %5, %7
%11 = phi i32 [ %9, %7 ], [ 130, %5 ]
%12 = tail call i8* @malloc(i32 %11)
%13 = icmp eq i8* %12, null
br i1 %13, label %22, label %14
14: ; preds = %10
%15 = ptrtoint %struct.t_gui_buffer* %1 to i64
%16 = select i1 %6, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %2
%17 = tail call i32 @snprintf(i8* %12, i32 %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %15, i8* %16)
%18 = tail call i32 @hook_signal_send(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%19 = tail call i32 @free(i8* %12)
br label %22
20: ; preds = %3
%21 = tail call i32 @hook_signal_send(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %22
22: ; preds = %10, %14, %20
ret void
}