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


x86 assembly (clang, -O0):
<script_action_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11b2 <script_action_add+0x62>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     11ad <script_action_add+0x5d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    121d <script_action_add+0xcd>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
add    -0x14(%rbp),%esi
add    $0x1,%esi
call   1060 <realloc@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
je     1218 <script_action_add+0xc8>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
lea    0xdfd(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <strcat@plt>
jmp    121d <script_action_add+0xcd>
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define void @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 %22, label %10
10: ; preds = %6
%11 = tail call i32 @strcpy(i8* %8, i8* %1)
br label %22
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)
store i8* %16, i8** %0
%17 = icmp eq i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %12
%19 = tail call i32 @strcat(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = load i8*, i8** %0
%21 = tail call i32 @strcat(i8* %20, i8* %1)
br label %22
22: ; preds = %12, %18, %6, %10
ret void
}