#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 /*<<< orphan*/ f3d_combine_old;
typedef int /*<<< orphan*/ f3d_combine_new;

/* Variables and functions */
int /*<<< orphan*/ memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void fix_f3d(unsigned char *buf, int len) {
  static const unsigned char f3d_combine_old[] = {0xFC, 0x12, 0x7F, 0xFF,
                                                  0xFF, 0xFF, 0xF8, 0x38};
  static const unsigned char f3d_combine_new[] = {0xFC, 0x12, 0x18, 0x24,
                                                  0xFF, 0x33, 0xFF, 0xFF};
  for (int i = 0; i < len; i++) {
    if (!memcmp(&buf[i], f3d_combine_old, sizeof(f3d_combine_old))) {
      memcpy(&buf[i], f3d_combine_new, sizeof(f3d_combine_new));
    }
  }
}


x86 assembly (clang, -O0):
<fix_f3d>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <fix_f3d+0x76>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xeac(%rip),%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    1183 <fix_f3d+0x63>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xe8f(%rip),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
jmp    1188 <fix_f3d+0x68>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <fix_f3d+0x16>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fix_f3d>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1180 <fix_f3d+0x60>
mov    %rdi,%rbx
mov    %esi,%r12d
lea    0xec7(%rip),%r14
lea    0xec8(%rip),%r15
jmp    115a <fix_f3d+0x3a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r12
je     1180 <fix_f3d+0x60>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
test   %eax,%eax
jne    1150 <fix_f3d+0x30>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
jmp    1150 <fix_f3d+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@fix_f3d.f3d_combine_old = internal constant [8 x i8] c"\FC\12\7F\FF\FF\FF\F88"
@fix_f3d.f3d_combine_new = internal constant [8 x i8] c"\FC\12\18$\FF3\FF\FF"
define void @fix_f3d(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %24, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %27
10: ; preds = %6
%11 = load i8*, i8** %3
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = call i32 @memcmp(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @fix_f3d.f3d_combine_old, i64 0, i64 0), i32 8)
%16 = icmp ne i32 %15, 0
br i1 %16, label %23, label %17
17: ; preds = %10
%18 = load i8*, i8** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i32 @memcpy(i8* %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @fix_f3d.f3d_combine_new, i64 0, i64 0), i32 8)
br label %23
23: ; preds = %17, %10
br label %24
24: ; preds = %23
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %6
27: ; preds = %6
ret void
}

LLVM IR (-O2):
@fix_f3d.f3d_combine_old = internal constant [8 x i8] c"\FC\12\7F\FF\FF\FF\F88"
@fix_f3d.f3d_combine_new = internal constant [8 x i8] c"\FC\12\18$\FF3\FF\FF"
define void @fix_f3d(i8* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %7
6: ; preds = %14, %2
ret void
7: ; preds = %4, %14
%8 = phi i64 [ 0, %4 ], [ %15, %14 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = tail call i32 @memcmp(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @fix_f3d.f3d_combine_old, i64 0, i64 0), i32 8)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %7
%13 = tail call i32 @memcpy(i8* %9, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @fix_f3d.f3d_combine_new, i64 0, i64 0), i32 8)
br label %14
14: ; preds = %7, %12
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %5
br i1 %16, label %6, label %7
}