#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*/ free(char *);
char *malloc(int);
char *realloc(char *, int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
void plugin_script_action_add(char **action_list, const char *name) {
  int length;
  char *action_list2;
  length = strlen(name);
  if (!(*action_list)) {
    *action_list = malloc(length + 1);
    if (*action_list)
      strcpy(*action_list, name);
  } else {
    action_list2 = realloc(*action_list, strlen(*action_list) + 1 + length + 1);
    if (!action_list2) {
      free(*action_list);
      *action_list = NULL;
      return;
    }
    *action_list = action_list2;
    strcat(*action_list, ",");
    strcat(*action_list, name);
  }
}


x86 assembly (clang, -O0):
<plugin_script_action_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11c2 <plugin_script_action_add+0x62>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11bd <plugin_script_action_add+0x5d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1246 <plugin_script_action_add+0xe6>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
add    -0x14(%rbp),%esi
add    $0x1,%esi
call   1070 <realloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1218 <plugin_script_action_add+0xb8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%rax
movq   $0x0,(%rax)
jmp    1246 <plugin_script_action_add+0xe6>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xdcf(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plugin_script_action_add>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <strlen@plt>
mov    %eax,%r12d
mov    (%r15),%rbx
test   %rbx,%rbx
je     11c5 <plugin_script_action_add+0x65>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    (%r12,%rax,1),%esi
add    $0x2,%esi
mov    %rbx,%rdi
call   1070 <realloc@plt>
test   %rax,%rax
je     11ef <plugin_script_action_add+0x8f>
mov    %rax,(%r15)
lea    0xe59(%rip),%rsi
mov    %rax,%rdi
call   1080 <strcat@plt>
mov    (%r15),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1080 <strcat@plt>
add    $0x1,%r12d
mov    %r12d,%edi
call   1060 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     11fe <plugin_script_action_add+0x9e>
mov    %rax,%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <strcpy@plt>
mov    (%r15),%rdi
call   1030 <free@plt>
movq   $0x0,(%r15)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define void @plugin_script_action_add(i8** %0, i8* %1) {
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
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* %5
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %26, label %12
12: ; preds = %2
%13 = load i32, i32* %5
%14 = add nsw i32 %13, 1
%15 = call i8* @malloc(i32 %14)
%16 = load i8**, i8*** %3
store i8* %15, i8** %16
%17 = load i8**, i8*** %3
%18 = load i8*, i8** %17
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %25
20: ; preds = %12
%21 = load i8**, i8*** %3
%22 = load i8*, i8** %21
%23 = load i8*, i8** %4
%24 = call i32 @strcpy(i8* %22, i8* %23)
br label %25
25: ; preds = %20, %12
br label %54
26: ; preds = %2
%27 = load i8**, i8*** %3
%28 = load i8*, i8** %27
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 1
%33 = load i32, i32* %5
%34 = add nsw i32 %32, %33
%35 = add nsw i32 %34, 1
%36 = call i8* @realloc(i8* %28, i32 %35)
store i8* %36, i8** %6
%37 = load i8*, i8** %6
%38 = icmp ne i8* %37, null
br i1 %38, label %44, label %39
39: ; preds = %26
%40 = load i8**, i8*** %3
%41 = load i8*, i8** %40
%42 = call i32 @free(i8* %41)
%43 = load i8**, i8*** %3
store i8* null, i8** %43
br label %54
44: ; preds = %26
%45 = load i8*, i8** %6
%46 = load i8**, i8*** %3
store i8* %45, i8** %46
%47 = load i8**, i8*** %3
%48 = load i8*, i8** %47
%49 = call i32 @strcat(i8* %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%50 = load i8**, i8*** %3
%51 = load i8*, i8** %50
%52 = load i8*, i8** %4
%53 = call i32 @strcat(i8* %51, i8* %52)
br label %54
54: ; preds = %39, %44, %25
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define void @plugin_script_action_add(i8** nocapture %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = add nsw i32 %3, 1
%8 = tail call i8* @malloc(i32 %7)
store i8* %8, i8** %0
%9 = icmp eq i8* %8, null
br i1 %9, label %25, label %10
10: ; preds = %6
%11 = tail call i32 @strcpy(i8* %8, i8* %1)
br label %25
12: ; preds = %2
%13 = tail call i32 @strlen(i8* %4)
%14 = add i32 %3, 2
%15 = add i32 %14, %13
%16 = tail call i8* @realloc(i8* %4, i32 %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i8*, i8** %0
%20 = tail call i32 @free(i8* %19)
store i8* null, i8** %0
br label %25
21: ; preds = %12
store i8* %16, i8** %0
%22 = tail call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %0
%24 = tail call i32 @strcat(i8* %23, i8* %1)
br label %25
25: ; preds = %21, %10, %6, %18
ret void
}