#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*/ fprintf(int /*<<< orphan*/, char *, char const *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ string_encode_base64(char const *, int, char *);
int strlen(char const *);
void gui_window_send_clipboard(const char *storage_unit, const char *text) {
  char *text_base64;
  int length;
  length = strlen(text);
  text_base64 = malloc((length * 4) + 1);
  if (text_base64) {
    string_encode_base64(text, length, text_base64);
    fprintf(stderr, "\033]52;%s;%s\a", (storage_unit) ? storage_unit : "",
            text_base64);
    free(text_base64);
  }
}


x86 assembly (clang, -O0):
<gui_window_send_clipboard>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
shl    $0x2,%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ed <gui_window_send_clipboard+0x9d>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1060 <string_encode_base64@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11bd <gui_window_send_clipboard+0x6d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    11cd <gui_window_send_clipboard+0x7d>
lea    0xe47(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    11cd <gui_window_send_clipboard+0x7d>
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gui_window_send_clipboard>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0x1(,%r12,4),%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11c5 <gui_window_send_clipboard+0x75>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r12d,%esi
mov    %rax,%rdx
call   1060 <string_encode_base64@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
test   %r14,%r14
lea    0xe6c(%rip),%rdx
cmovne %r14,%rdx
lea    0xe56(%rip),%rsi
mov    %rbx,%rcx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <free@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"\1B]52;%s;%s\07\00"
@.str.1 = [1 x i8] zeroinitializer
define void @gui_window_send_clipboard(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = mul nsw i32 %9, 4
%11 = add nsw i32 %10, 1
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %5
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %32
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = load i32, i32* %6
%18 = load i8*, i8** %5
%19 = call i32 @string_encode_base64(i8* %16, i32 %17, i8* %18)
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %25
23: ; preds = %15
%24 = load i8*, i8** %3
br label %26
25: ; preds = %15
br label %26
26: ; preds = %25, %23
%27 = phi i8* [ %24, %23 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %25 ]
%28 = load i8*, i8** %5
%29 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %28)
%30 = load i8*, i8** %5
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %26, %2
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"\1B]52;%s;%s\07\00"
@.str.1 = [1 x i8] zeroinitializer
define void @gui_window_send_clipboard(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = shl nsw i32 %3, 2
%5 = or i32 %4, 1
%6 = tail call i8* @malloc(i32 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %15, label %8
8: ; preds = %2
%9 = tail call i32 @string_encode_base64(i8* %1, i32 %3, i8* %6)
%10 = load i32, i32* @stderr
%11 = icmp eq i8* %0, null
%12 = select i1 %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* %0
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %6)
%14 = tail call i32 @free(i8* %6)
br label %15
15: ; preds = %8, %2
ret void
}