#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 */
scalar_t__ PHYSFS_addToSearchPath(char *, int);
char *PHYSFS_getLastError();
int atoi(char *);
int /*<<< orphan*/ printf(char *, ...);
char *strrchr(char *, char);
int cmd_addarchive(char *args) {
  char *ptr = strrchr(args, ' ');
  int appending = atoi(ptr + 1);
  *ptr = '\0';
  if (*args == '\"') {
    args++;
    *(ptr - 1) = '\0';
  }
  if (PHYSFS_addToSearchPath(args, appending))
    printf("Successful.\n");
  else
    printf("Failure. reason: %s.\n", PHYSFS_getLastError());
  return (1);
}


x86 assembly (clang, -O0):
<cmd_addarchive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11a9 <cmd_addarchive+0x59>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,-0x1(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <PHYSFS_addToSearchPath@plt>
cmp    $0x0,%rax
je     11d2 <cmd_addarchive+0x82>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ea <cmd_addarchive+0x9a>
mov    $0x0,%al
call   1050 <PHYSFS_getLastError@plt>
mov    %rax,%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_addarchive>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x20,%esi
call   1050 <strrchr@plt>
mov    %rax,%r14
lea    0x1(%rax),%rdi
call   1070 <atoi@plt>
movb   $0x0,(%r14)
cmpb   $0x22,(%rbx)
jne    118f <cmd_addarchive+0x2f>
add    $0x1,%rbx
movb   $0x0,-0x1(%r14)
mov    %rbx,%rdi
mov    %eax,%esi
call   1080 <PHYSFS_addToSearchPath@plt>
test   %rax,%rax
je     11ac <cmd_addarchive+0x4c>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
jmp    11c4 <cmd_addarchive+0x64>
xor    %eax,%eax
call   1060 <PHYSFS_getLastError@plt>
lea    0xe46(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Successful.\0A\00"
@.str.1 = [22 x i8] c"Failure. reason: %s.\0A\00"
define i32 @cmd_addarchive(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i8* @strrchr(i8* %5, i8 signext 32)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 1
%9 = call i32 @atoi(i8* %8)
store i32 %9, i32* %4
%10 = load i8*, i8** %3
store i8 0, i8* %10
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 34
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = getelementptr inbounds i8, i8* %16, i32 1
store i8* %17, i8** %2
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 -1
store i8 0, i8* %19
br label %20
20: ; preds = %15, %1
%21 = load i8*, i8** %2
%22 = load i32, i32* %4
%23 = call i64 @PHYSFS_addToSearchPath(i8* %21, i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %30
27: ; preds = %20
%28 = call i8* (...) @PHYSFS_getLastError()
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %30
30: ; preds = %27, %25
ret i32 1
}

LLVM IR (-O2):
@.str.1 = [22 x i8] c"Failure. reason: %s.\0A\00"
@str = [12 x i8] c"Successful.\00"
define i32 @cmd_addarchive(i8* %0) {
%2 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 32)
%3 = getelementptr inbounds i8, i8* %2, i64 1
%4 = tail call i32 @atoi(i8* %3)
store i8 0, i8* %2
%5 = load i8, i8* %0
%6 = icmp eq i8 %5, 34
br i1 %6, label %7, label %10
7: ; preds = %1
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = getelementptr inbounds i8, i8* %2, i64 -1
store i8 0, i8* %9
br label %10
10: ; preds = %7, %1
%11 = phi i8* [ %8, %7 ], [ %0, %1 ]
%12 = tail call i64 @PHYSFS_addToSearchPath(i8* %11, i32 %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %19
16: ; preds = %10
%17 = tail call i8* (...) @PHYSFS_getLastError()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %16, %14
ret i32 1
}