#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 */
typedef int uint8_t;
typedef int /*<<< orphan*/ replace_insn;
typedef int /*<<< orphan*/ match_insn;

/* Variables and functions */
int /*<<< orphan*/ memcmp(int *, int const **, int);
int /*<<< orphan*/ memcpy(int *, int const **, int);
int patch_radarfreq(uint8_t *insn) {
  const uint8_t match_insn[] = {0x2c, 0xa5, 0x01, 0xb9};
  const uint8_t replace_insn[] = {0x3c, 0x05, 0x00, 0x00};
  if (!memcmp(insn, &match_insn, sizeof(match_insn))) {
    memcpy(insn, &replace_insn, sizeof(replace_insn));
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<patch_radarfreq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xec7(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xec4(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    1191 <patch_radarfreq+0x71>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    1198 <patch_radarfreq+0x78>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<patch_radarfreq>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movaps 0xed1(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xed5(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%rsi
mov    $0x10,%edx
call   1030 <memcmp@plt>
mov    %eax,%ecx
mov    $0x1,%eax
test   %ecx,%ecx
jne    116b <patch_radarfreq+0x4b>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x10,%edx
call   1040 <memcpy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.patch_radarfreq.match_insn = [4 x i32] [i32 44, i32 165, i32 1, i32 185]
@__const.patch_radarfreq.replace_insn = [4 x i32] [i32 60, i32 5, i32 0, i32 0]
define i32 @patch_radarfreq(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [4 x i32]
%5 = alloca [4 x i32]
store i32* %0, i32** %3
%6 = bitcast [4 x i32]* %4 to i8*
%7 = bitcast [4 x i32]* %5 to i8*
%8 = load i32*, i32** %3
%9 = bitcast [4 x i32]* %4 to i32**
%10 = call i32 @memcmp(i32* %8, i32** %9, i32 16)
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = bitcast [4 x i32]* %5 to i32**
%15 = call i32 @memcpy(i32* %13, i32** %14, i32 16)
store i32 0, i32* %2
br label %17
16: ; preds = %1
store i32 1, i32* %2
br label %17
17: ; preds = %16, %12
%18 = load i32, i32* %2
ret i32 %18
}

LLVM IR (-O2):
@__const.patch_radarfreq.match_insn = [4 x i32] [i32 44, i32 165, i32 1, i32 185]
@__const.patch_radarfreq.replace_insn = [4 x i32] [i32 60, i32 5, i32 0, i32 0]
define i32 @patch_radarfreq(i32* %0) {
%2 = alloca [4 x i32]
%3 = alloca [4 x i32]
%4 = bitcast [4 x i32]* %2 to i8*
%5 = bitcast [4 x i32]* %3 to i8*
%6 = bitcast [4 x i32]* %2 to i32**
%7 = call i32 @memcmp(i32* %0, i32** %6, i32 16)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = bitcast [4 x i32]* %3 to i32**
%11 = call i32 @memcpy(i32* %0, i32** %10, i32 16)
br label %12
12: ; preds = %1, %9
%13 = phi i32 [ 0, %9 ], [ 1, %1 ]
ret i32 %13
}