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


x86 assembly (clang, -O0):
<appList_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <readAppList@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     120c <appList_remove+0xbc>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    1207 <appList_remove+0xb7>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x14(%rbp)
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1202 <appList_remove+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    11c3 <appList_remove+0x73>
jmp    120c <appList_remove+0xbc>
jmp    116e <appList_remove+0x1e>
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1228 <appList_remove+0xd8>
movl   $0x1,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <writeAppList@plt>
cmp    $0x0,%eax
jne    1241 <appList_remove+0xf1>
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <freeAppList@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<appList_remove>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %eax,%eax
call   1050 <readAppList@plt>
mov    %rax,%r14
mov    $0xffffffffffffffff,%rbx
nopl   0x0(%rax,%rax,1)
mov    0x8(%r14,%rbx,8),%rdi
test   %rdi,%rdi
je     11c0 <appList_remove+0x70>
mov    %r15,%rsi
call   1040 <strcmp@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1170 <appList_remove+0x20>
mov    %ebx,%r15d
mov    (%r14,%r15,8),%rdi
call   1030 <free@plt>
cmpq   $0x0,(%r14,%r15,8)
je     11c0 <appList_remove+0x70>
mov    %ebx,%eax
lea    (%r14,%rax,8),%rax
add    $0x8,%rax
nopl   0x0(%rax,%rax,1)
mov    (%rax),%rcx
mov    %rcx,-0x8(%rax)
add    $0x8,%rax
test   %rcx,%rcx
jne    11b0 <appList_remove+0x60>
xor    %ebp,%ebp
cmpq   $0x0,(%r14)
sete   %bpl
mov    %r14,%rdi
call   1070 <writeAppList@plt>
test   %eax,%eax
mov    $0x2,%ebx
cmovne %ebp,%ebx
mov    %r14,%rdi
call   1060 <freeAppList@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @appList_remove(i8* %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = call i8** (...) @readAppList()
store i8** %6, i8*** %3
store i32 0, i32* %4
br label %7
7: ; preds = %52, %1
%8 = load i8**, i8*** %3
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8*, i8** %8, i64 %10
%12 = load i8*, i8** %11
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %53
14: ; preds = %7
%15 = load i8**, i8*** %3
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8*, i8** %15, i64 %18
%20 = load i8*, i8** %19
%21 = load i8*, i8** %2
%22 = call i64 @strcmp(i8* %20, i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %52
24: ; preds = %14
%25 = load i8**, i8*** %3
%26 = load i32, i32* %4
%27 = add nsw i32 %26, -1
store i32 %27, i32* %4
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8*, i8** %25, i64 %28
%30 = load i8*, i8** %29
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %40, %24
%33 = load i8**, i8*** %3
%34 = load i32, i32* %4
%35 = add nsw i32 %34, 1
store i32 %35, i32* %4
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds i8*, i8** %33, i64 %36
%38 = load i8*, i8** %37
%39 = icmp ne i8* %38, null
br i1 %39, label %40, label %51
40: ; preds = %32
%41 = load i8**, i8*** %3
%42 = load i32, i32* %4
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8*, i8** %41, i64 %43
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %3
%47 = load i32, i32* %4
%48 = sub nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %46, i64 %49
store i8* %45, i8** %50
br label %32
51: ; preds = %32
br label %53
52: ; preds = %14
br label %7
53: ; preds = %51, %7
store i32 0, i32* %5
%54 = load i8**, i8*** %3
%55 = getelementptr inbounds i8*, i8** %54, i64 0
%56 = load i8*, i8** %55
%57 = icmp eq i8* %56, null
br i1 %57, label %58, label %59
58: ; preds = %53
store i32 1, i32* %5
br label %59
59: ; preds = %58, %53
%60 = load i8**, i8*** %3
%61 = call i32 @writeAppList(i8** %60)
%62 = icmp ne i32 %61, 0
br i1 %62, label %64, label %63
63: ; preds = %59
store i32 2, i32* %5
br label %64
64: ; preds = %63, %59
%65 = load i8**, i8*** %3
%66 = call i32 @freeAppList(i8** %65)
%67 = load i32, i32* %5
ret i32 %67
}

LLVM IR (-O2):
define i32 @appList_remove(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 %27, 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 %12, label %3
12: ; preds = %8
%13 = and i64 %4, 4294967295
%14 = getelementptr inbounds i8*, i8** %2, i64 %13
%15 = load i8*, i8** %14
%16 = tail call i32 @free(i8* %15)
%17 = load i8*, i8** %14
%18 = icmp eq i8* %17, null
br i1 %18, label %27, label %19
19: ; preds = %12, %19
%20 = phi i64 [ %22, %19 ], [ %13, %12 ]
%21 = phi i8** [ %23, %19 ], [ %14, %12 ]
%22 = add nuw i64 %20, 1
%23 = getelementptr inbounds i8*, i8** %2, i64 %22
%24 = load i8*, i8** %23
store i8* %24, i8** %21
%25 = load i8*, i8** %23
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %19
27: ; preds = %3, %19, %12
%28 = load i8*, i8** %2
%29 = icmp eq i8* %28, null
%30 = zext i1 %29 to i32
%31 = tail call i32 @writeAppList(i8** %2)
%32 = icmp eq i32 %31, 0
%33 = select i1 %32, i32 2, i32 %30
%34 = tail call i32 @freeAppList(i8** %2)
ret i32 %33
}