#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);
int /*<<< orphan*/ sprintf(char *, char *, size_t);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
char *strrchr(char *, char);
char *GetAuxFile(const char *psz_arg, size_t i_payload_size) {
  char *psz_aux = malloc(strlen(psz_arg) + 256);
  char *psz_token;
  strcpy(psz_aux, psz_arg);
  psz_token = strrchr(psz_aux, '/');
  if (psz_token != NULL)
    psz_token++;
  else
    psz_token = psz_aux + 1;
  if (*psz_token)
    psz_token++;
  psz_token = strrchr(psz_token, '.');
  if (psz_token)
    *psz_token = '\0';
  strcat(psz_aux, "."
                  "aux");
  if (i_payload_size != 1316)
    sprintf(psz_aux + strlen(psz_aux), "%zu", i_payload_size);
  return psz_aux;
}


x86 assembly (clang, -O0):
<GetAuxFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
add    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c5 <GetAuxFile+0x65>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    11d1 <GetAuxFile+0x71>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ea <GetAuxFile+0x8a>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     120e <GetAuxFile+0xae>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    0xde7(%rip),%rsi
call   1070 <strcat@plt>
cmpq   $0x524,-0x10(%rbp)
je     1256 <GetAuxFile+0xf6>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x28(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
lea    0xdb4(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetAuxFile>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1040 <strlen@plt>
lea    0x100(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
cmove  %rbx,%rax
lea    0x1(%rax),%rcx
lea    0x2(%rax),%rdi
cmpb   $0x0,0x1(%rax)
cmove  %rcx,%rdi
mov    $0x2e,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11bf <GetAuxFile+0x5f>
movb   $0x0,(%rax)
lea    0xe3a(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
cmp    $0x524,%r14
je     11f6 <GetAuxFile+0x96>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
mov    %rbx,%rdi
add    %rax,%rdi
lea    0xe17(%rip),%rsi
mov    %r14,%rdx
call   1080 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c".aux\00"
@.str.1 = [4 x i8] c"%zu\00"
define i8* @GetAuxFile(i8* %0, i64 %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = add nsw i32 %3, 256
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
%7 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 47)
%8 = icmp eq i8* %7, null
%9 = select i1 %8, i8* %5, i8* %7
%10 = getelementptr inbounds i8, i8* %9, i64 1
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 0
%13 = getelementptr inbounds i8, i8* %9, i64 2
%14 = select i1 %12, i8* %10, i8* %13
%15 = tail call i8* @strrchr(i8* %14, i8 signext 46)
%16 = icmp eq i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %2
store i8 0, i8* %15
br label %18
18: ; preds = %17, %2
%19 = tail call i32 @strcat(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i64 %1, 1316
br i1 %20, label %26, label %21
21: ; preds = %18
%22 = tail call i32 @strlen(i8* %5)
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %5, i64 %23
%25 = tail call i32 @sprintf(i8* dereferenceable(1) %24, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 %1)
br label %26
26: ; preds = %21, %18
ret i8* %5
}