#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 *DEH_String(char const *);
int /*<<< orphan*/ ValidFormatReplacement(char const *, char const *);
int /*<<< orphan*/ printf(char *, char const *);
const char *FormatStringReplacement(const char *s) {
  const char *repl;
  repl = DEH_String(s);
  if (!ValidFormatReplacement(s, repl)) {
    printf("WARNING: Unsafe dehacked replacement provided for "
           "printf format string: %s\n",
           s);
    return s;
  }
  return repl;
}


x86 assembly (clang, -O0):
<FormatStringReplacement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <DEH_String@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <ValidFormatReplacement@plt>
cmp    $0x0,%eax
jne    117c <FormatStringReplacement+0x4c>
mov    -0x10(%rbp),%rsi
lea    0xe96(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1184 <FormatStringReplacement+0x54>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FormatStringReplacement>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <DEH_String@plt>
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1040 <ValidFormatReplacement@plt>
test   %eax,%eax
jne    1160 <FormatStringReplacement+0x30>
lea    0xeab(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    %r14,%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [76 x i8] c"WARNING: Unsafe dehacked replacement provided for printf format string: %s\0A\00"
define i8* @FormatStringReplacement(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i8* @DEH_String(i8* %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %4
%9 = call i32 @ValidFormatReplacement(i8* %7, i8* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %3
store i8* %14, i8** %2
br label %17
15: ; preds = %1
%16 = load i8*, i8** %4
store i8* %16, i8** %2
br label %17
17: ; preds = %15, %11
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [76 x i8] c"WARNING: Unsafe dehacked replacement provided for printf format string: %s\0A\00"
define i8* @FormatStringReplacement(i8* %0) {
%2 = tail call i8* @DEH_String(i8* %0)
%3 = tail call i32 @ValidFormatReplacement(i8* %0, i8* %2)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %1, %5
%8 = phi i8* [ %0, %5 ], [ %2, %1 ]
ret i8* %8
}