#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*/ freeAppList(char **);
char **readAppList();
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int /*<<< orphan*/ writeAppList(char **);
int appList_add(char *name) {
  char **appList = readAppList();
  int i = 0;
  while (appList[i])
    if (strcmp(appList[i++], name) == 0) {
      freeAppList(appList);
      return 0;
    }
  appList[i] = strdup(name);
  int result = 0;
  if (!writeAppList(appList))
    result = 2;
  freeAppList(appList);
  return result;
}


x86 assembly (clang, -O0):
<appList_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <readAppList@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11c4 <appList_add+0x74>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11bf <appList_add+0x6f>
mov    -0x18(%rbp),%rdi
call   1050 <freeAppList@plt>
movl   $0x0,-0x4(%rbp)
jmp    120b <appList_add+0xbb>
jmp    116e <appList_add+0x1e>
mov    -0x10(%rbp),%rdi
call   1060 <strdup@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
movl   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <writeAppList@plt>
cmp    $0x0,%eax
jne    11fc <appList_add+0xac>
movl   $0x2,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <freeAppList@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appList_add>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <readAppList@plt>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     118e <appList_add+0x3e>
add    $0x1,%rbx
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
jne    1170 <appList_add+0x20>
xor    %ebx,%ebx
jmp    11ad <appList_add+0x5d>
mov    %ebx,%ebx
mov    %r15,%rdi
call   1060 <strdup@plt>
mov    %rax,(%r14,%rbx,8)
mov    %r14,%rdi
call   1070 <writeAppList@plt>
xor    %ebx,%ebx
test   %eax,%eax
sete   %bl
add    %ebx,%ebx
mov    %r14,%rdi
call   1050 <freeAppList@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @appList_add(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
%7 = call i8** (...) @readAppList()
store i8** %7, i8*** %4
store i32 0, i32* %5
br label %8
8: ; preds = %28, %1
%9 = load i8**, i8*** %4
%10 = load i32, i32* %5
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8*, i8** %9, i64 %11
%13 = load i8*, i8** %12
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %29
15: ; preds = %8
%16 = load i8**, i8*** %4
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
%19 = sext i32 %17 to i64
%20 = getelementptr inbounds i8*, i8** %16, i64 %19
%21 = load i8*, i8** %20
%22 = load i8*, i8** %3
%23 = call i64 @strcmp(i8* %21, i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %15
%26 = load i8**, i8*** %4
%27 = call i32 @freeAppList(i8** %26)
store i32 0, i32* %2
br label %44
28: ; preds = %15
br label %8
29: ; preds = %8
%30 = load i8*, i8** %3
%31 = call i8* @strdup(i8* %30)
%32 = load i8**, i8*** %4
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8*, i8** %32, i64 %34
store i8* %31, i8** %35
store i32 0, i32* %6
%36 = load i8**, i8*** %4
%37 = call i32 @writeAppList(i8** %36)
%38 = icmp ne i32 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %29
store i32 2, i32* %6
br label %40
40: ; preds = %39, %29
%41 = load i8**, i8*** %4
%42 = call i32 @freeAppList(i8** %41)
%43 = load i32, i32* %6
store i32 %43, i32* %2
br label %44
44: ; preds = %40, %25
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
define i32 @appList_add(i8* %0) {
%2 = tail call i8** (...) @readAppList()
br label %3
3: ; preds = %8, %1
%4 = phi i64 [ %9, %8 ], [ 0, %1 ]
%5 = getelementptr inbounds i8*, i8** %2, i64 %4
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %12, label %8
8: ; preds = %3
%9 = add nuw i64 %4, 1
%10 = tail call i64 @strcmp(i8* %6, i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %19, label %3
12: ; preds = %3
%13 = and i64 %4, 4294967295
%14 = getelementptr inbounds i8*, i8** %2, i64 %13
%15 = tail call i8* @strdup(i8* %0)
store i8* %15, i8** %14
%16 = tail call i32 @writeAppList(i8** %2)
%17 = icmp eq i32 %16, 0
%18 = select i1 %17, i32 2, i32 0
br label %19
19: ; preds = %8, %12
%20 = phi i32 [ %18, %12 ], [ 0, %8 ]
%21 = tail call i32 @freeAppList(i8** %2)
ret i32 %20
}