#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 */
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *optima_copy_line(char *, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int optima_add_func(char *dst, char *src, int32_t len, int32_t func_label) {
  char tmp[0x1000];
  sprintf(tmp, "LB(0, %d);\n", func_label);
  strcat(dst, tmp);
  if (optima_copy_line(tmp, src, len) == NULL) {
    printf("optimazer err: optima_add_func()\n");
    exit(EXIT_FAILURE);
  }
  strcat(dst, tmp);
  sprintf(
      tmp,
      "labelstack_head--;\n"
      "PAPLMEM0(labelstack_socket, T_VPTR, labelstack_ptr, labelstack_head);\n"
      "PCP(P3F, %s);\n",
      "P02");
  strcat(dst, tmp);
  return 0;
}


x86 assembly (clang, -O0):
<optima_add_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xe86(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <optima_copy_line@plt>
cmp    $0x0,%rax
jne    11c8 <optima_add_func+0x78>
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e1f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1050 <strcat@plt>
lea    -0x1020(%rbp),%rdi
lea    0xe48(%rip),%rsi
lea    0xea9(%rip),%rdx
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<optima_add_func>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1008,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe93(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %ecx,%edx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1040 <optima_copy_line@plt>
test   %rax,%rax
je     11db <optima_add_func+0x8b>
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
lea    0xe5d(%rip),%rsi
lea    0xebe(%rip),%rdx
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
xor    %eax,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe96(%rip),%rdi
call   1030 <puts@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"LB(0, %d);\0A\00"
@.str.1 = [34 x i8] c"optimazer err: optima_add_func()\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [104 x i8] c"labelstack_head--;\0APAPLMEM0(labelstack_socket, T_VPTR, labelstack_ptr, labelstack_head);\0APCP(P3F, %s);\0A\00"
@.str.3 = [4 x i8] c"P02\00"
define i32 @optima_add_func(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4096 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%11 = load i32, i32* %8
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %5
%14 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%15 = call i32 @strcat(i8* %13, i8* %14)
%16 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%17 = load i8*, i8** %6
%18 = load i32, i32* %7
%19 = call i32* @optima_copy_line(i8* %16, i8* %17, i32 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %4
%22 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %4
%26 = load i8*, i8** %5
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([104 x i8], [104 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%31 = load i8*, i8** %5
%32 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%33 = call i32 @strcat(i8* %31, i8* %32)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"LB(0, %d);\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [104 x i8] c"labelstack_head--;\0APAPLMEM0(labelstack_socket, T_VPTR, labelstack_ptr, labelstack_head);\0APCP(P3F, %s);\0A\00"
@.str.3 = [4 x i8] c"P02\00"
@str = [33 x i8] c"optimazer err: optima_add_func()\00"
define i32 @optima_add_func(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%7 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %3)
%8 = call i32 @strcat(i8* %0, i8* %6)
%9 = call i32* @optima_copy_line(i8* %6, i8* %1, i32 %2)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %4
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %4
%16 = call i32 @strcat(i8* %0, i8* %6)
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([104 x i8], [104 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%18 = call i32 @strcat(i8* %0, i8* %6)
ret i32 0
}