#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 */
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int strlen(char const *);
char *plugin_script_build_function_and_data(const char *function,
                                            const char *data) {
  int length_function, length_data, length;
  char *result;
  if (!function || !function[0])
    return NULL;
  length_function = (function) ? strlen(function) : 0;
  length_data = (data) ? strlen(data) : 0;
  length = length_function + 1 + length_data + 1;
  result = malloc(length);
  if (!result)
    return NULL;
  if (function)
    memcpy(result, function, length_function + 1);
  else
    result[0] = '\0';
  if (data)
    memcpy(result + length_function + 1, data, length_data + 1);
  else
    result[length_function + 1] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<plugin_script_build_function_and_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1158 <plugin_script_build_function_and_data+0x28>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1165 <plugin_script_build_function_and_data+0x35>
movq   $0x0,-0x8(%rbp)
jmp    1261 <plugin_script_build_function_and_data+0x131>
cmpq   $0x0,-0x10(%rbp)
je     1181 <plugin_script_build_function_and_data+0x51>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x34(%rbp)
jmp    118b <plugin_script_build_function_and_data+0x5b>
xor    %eax,%eax
mov    %eax,-0x34(%rbp)
jmp    118b <plugin_script_build_function_and_data+0x5b>
mov    -0x34(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ad <plugin_script_build_function_and_data+0x7d>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x38(%rbp)
jmp    11b7 <plugin_script_build_function_and_data+0x87>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
jmp    11b7 <plugin_script_build_function_and_data+0x87>
mov    -0x38(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
add    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f0 <plugin_script_build_function_and_data+0xc0>
movq   $0x0,-0x8(%rbp)
jmp    1261 <plugin_script_build_function_and_data+0x131>
cmpq   $0x0,-0x10(%rbp)
je     1213 <plugin_script_build_function_and_data+0xe3>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
jmp    121a <plugin_script_build_function_and_data+0xea>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     1248 <plugin_script_build_function_and_data+0x118>
mov    -0x30(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
jmp    1259 <plugin_script_build_function_and_data+0x129>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plugin_script_build_function_and_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11b1 <plugin_script_build_function_and_data+0x81>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     11b1 <plugin_script_build_function_and_data+0x81>
mov    %rsi,%r14
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
test   %r14,%r14
je     116b <plugin_script_build_function_and_data+0x3b>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
add    $0x1,%r12d
jmp    1171 <plugin_script_build_function_and_data+0x41>
mov    $0x1,%r12d
movslq %ebp,%rbp
lea    0x1(%rbp),%r13
lea    (%r12,%r13,1),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11b1 <plugin_script_build_function_and_data+0x81>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
test   %r14,%r14
je     11c6 <plugin_script_build_function_and_data+0x96>
lea    (%r15,%rbp,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
mov    %r12d,%edx
call   1040 <memcpy@plt>
jmp    11b4 <plugin_script_build_function_and_data+0x84>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%r15,%r13,1)
jmp    11b4 <plugin_script_build_function_and_data+0x84>

LLVM IR (-O0):
define i8* @plugin_script_build_function_and_data(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = getelementptr inbounds i8, i8* %13, i64 0
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12, %2
store i8* null, i8** %3
br label %78
18: ; preds = %12
%19 = load i8*, i8** %4
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i8*, i8** %4
%23 = call i32 @strlen(i8* %22)
br label %25
24: ; preds = %18
br label %25
25: ; preds = %24, %21
%26 = phi i32 [ %23, %21 ], [ 0, %24 ]
store i32 %26, i32* %6
%27 = load i8*, i8** %5
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i8*, i8** %5
%31 = call i32 @strlen(i8* %30)
br label %33
32: ; preds = %25
br label %33
33: ; preds = %32, %29
%34 = phi i32 [ %31, %29 ], [ 0, %32 ]
store i32 %34, i32* %7
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
%37 = load i32, i32* %7
%38 = add nsw i32 %36, %37
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
%40 = load i32, i32* %8
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %9
%42 = load i8*, i8** %9
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %33
store i8* null, i8** %3
br label %78
45: ; preds = %33
%46 = load i8*, i8** %4
%47 = icmp ne i8* %46, null
br i1 %47, label %48, label %54
48: ; preds = %45
%49 = load i8*, i8** %9
%50 = load i8*, i8** %4
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
%53 = call i32 @memcpy(i8* %49, i8* %50, i32 %52)
br label %57
54: ; preds = %45
%55 = load i8*, i8** %9
%56 = getelementptr inbounds i8, i8* %55, i64 0
store i8 0, i8* %56
br label %57
57: ; preds = %54, %48
%58 = load i8*, i8** %5
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %70
60: ; preds = %57
%61 = load i8*, i8** %9
%62 = load i32, i32* %6
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = getelementptr inbounds i8, i8* %64, i64 1
%66 = load i8*, i8** %5
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
%69 = call i32 @memcpy(i8* %65, i8* %66, i32 %68)
br label %76
70: ; preds = %57
%71 = load i8*, i8** %9
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %71, i64 %74
store i8 0, i8* %75
br label %76
76: ; preds = %70, %60
%77 = load i8*, i8** %9
store i8* %77, i8** %3
br label %78
78: ; preds = %76, %44, %17
%79 = load i8*, i8** %3
ret i8* %79
}

LLVM IR (-O2):
define i8* @plugin_script_build_function_and_data(i8* %0, i8* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %29, label %4
4: ; preds = %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %4
%8 = tail call i32 @strlen(i8* %0)
%9 = icmp eq i8* %1, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %1)
%12 = add i32 %11, 1
br label %13
13: ; preds = %7, %10
%14 = phi i32 [ %12, %10 ], [ 1, %7 ]
%15 = add nsw i32 %8, 1
%16 = add i32 %14, %15
%17 = tail call i8* @malloc(i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %29, label %19
19: ; preds = %13
%20 = tail call i32 @memcpy(i8* %17, i8* %0, i32 %15)
br i1 %9, label %26, label %21
21: ; preds = %19
%22 = sext i32 %8 to i64
%23 = getelementptr inbounds i8, i8* %17, i64 %22
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = tail call i32 @memcpy(i8* %24, i8* %1, i32 %14)
br label %29
26: ; preds = %19
%27 = sext i32 %15 to i64
%28 = getelementptr inbounds i8, i8* %17, i64 %27
store i8 0, i8* %28
br label %29
29: ; preds = %21, %26, %13, %2, %4
%30 = phi i8* [ null, %4 ], [ null, %2 ], [ null, %13 ], [ %17, %26 ], [ %17, %21 ]
ret i8* %30
}