#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*/ BufferDiff(char *, int, int, int);
int FindPostString(char *, char *, char *, int);
int strlen(char *);
int PurgePostString(char *sPost, char *sArg, int dMaxSize) {
  char sAccum[1024];
  int dPointer;
  dPointer = FindPostString(sPost, sArg, sAccum, 1024);
  if (dPointer < 0) {
    return -1;
  }
  dPointer -= (strlen(sArg) + 1);
  BufferDiff(sPost, dPointer, -(strlen(sArg) + strlen(sAccum) + 2), dMaxSize);
  return strlen(sPost);
}


x86 assembly (clang, -O0):
<PurgePostString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x420(%rbp),%rdx
mov    $0x400,%ecx
call   1050 <FindPostString@plt>
mov    %eax,-0x424(%rbp)
cmpl   $0x0,-0x424(%rbp)
jge    117e <PurgePostString+0x4e>
movl   $0xffffffff,-0x4(%rbp)
jmp    11fe <PurgePostString+0xce>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x424(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x438(%rbp)
mov    -0x424(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x438(%rbp),%rdi
mov    -0x42c(%rbp),%esi
mov    %eax,%ecx
mov    -0x428(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
xor    %edx,%edx
sub    %eax,%edx
mov    -0x1c(%rbp),%ecx
call   1040 <BufferDiff@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PurgePostString>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsp,%rdx
mov    $0x400,%ecx
call   1050 <FindPostString@plt>
test   %eax,%eax
js     1197 <PurgePostString+0x67>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
not    %eax
add    %eax,%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebx
mov    %rsp,%rdi
call   1030 <strlen@plt>
add    %ebx,%eax
mov    $0xfffffffe,%edx
sub    %eax,%edx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%ecx
call   1040 <BufferDiff@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
jmp    119c <PurgePostString+0x6c>
mov    $0xffffffff,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @PurgePostString(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%13 = call i32 @FindPostString(i8* %10, i8* %11, i8* %12, i32 1024)
store i32 %13, i32* %9
%14 = load i32, i32* %9
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 -1, i32* %4
br label %36
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = call i32 @strlen(i8* %18)
%20 = add nsw i32 %19, 1
%21 = load i32, i32* %9
%22 = sub nsw i32 %21, %20
store i32 %22, i32* %9
%23 = load i8*, i8** %5
%24 = load i32, i32* %9
%25 = load i8*, i8** %6
%26 = call i32 @strlen(i8* %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = add nsw i32 %26, %28
%30 = add nsw i32 %29, 2
%31 = sub nsw i32 0, %30
%32 = load i32, i32* %7
%33 = call i32 @BufferDiff(i8* %23, i32 %24, i32 %31, i32 %32)
%34 = load i8*, i8** %5
%35 = call i32 @strlen(i8* %34)
store i32 %35, i32* %4
br label %36
36: ; preds = %17, %16
%37 = load i32, i32* %4
ret i32 %37
}

LLVM IR (-O2):
define i32 @PurgePostString(i8* %0, i8* %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @FindPostString(i8* %0, i8* %1, i8* %5, i32 1024)
%7 = icmp slt i32 %6, 0
br i1 %7, label %18, label %8
8: ; preds = %3
%9 = call i32 @strlen(i8* %1)
%10 = xor i32 %9, -1
%11 = add i32 %6, %10
%12 = call i32 @strlen(i8* %1)
%13 = call i32 @strlen(i8* %5)
%14 = add i32 %12, %13
%15 = sub i32 -2, %14
%16 = call i32 @BufferDiff(i8* %0, i32 %11, i32 %15, i32 %2)
%17 = call i32 @strlen(i8* %0)
br label %18
18: ; preds = %3, %8
%19 = phi i32 [ %17, %8 ], [ -1, %3 ]
ret i32 %19
}