#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*/ geo_dl_old;
typedef int /*<<< orphan*/ geo_dl_new;

/* Variables and functions */
int /*<<< orphan*/ memcmp(unsigned char *, unsigned char const *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
void fix_geo(unsigned char *buf, int len) {
  static const unsigned char geo_dl_old[] = {0x15, 0x06, 0x00, 0x00, 0x0E};
  static const unsigned char geo_dl_new[] = {0x15, 0x04, 0x00, 0x00, 0x0E};
  for (int i = 0; i < len; i++) {
    if (!memcmp(&buf[i], geo_dl_old, sizeof(geo_dl_old))) {
      memcpy(&buf[i], geo_dl_new, sizeof(geo_dl_new));
    }
  }
}


x86 assembly (clang, -O0):
<fix_geo>:
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_geo+0x76>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xeac(%rip),%rsi
mov    $0x5,%edx
call   1030 <memcmp@plt>
cmp    $0x0,%eax
jne    1183 <fix_geo+0x63>
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xe8c(%rip),%rsi
mov    $0x5,%edx
call   1040 <memcpy@plt>
jmp    1188 <fix_geo+0x68>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1136 <fix_geo+0x16>
add    $0x10,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
@fix_geo.geo_dl_old = internal constant [5 x i8] c"\15\06\00\00\0E"
@fix_geo.geo_dl_new = internal constant [5 x i8] c"\15\04\00\00\0E"
define void @fix_geo(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 ([5 x i8], [5 x i8]* @fix_geo.geo_dl_old, i64 0, i64 0), i32 5)
%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 ([5 x i8], [5 x i8]* @fix_geo.geo_dl_new, i64 0, i64 0), i32 5)
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_geo.geo_dl_old = internal constant [5 x i8] c"\15\06\00\00\0E"
@fix_geo.geo_dl_new = internal constant [5 x i8] c"\15\04\00\00\0E"
define void @fix_geo(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 ([5 x i8], [5 x i8]* @fix_geo.geo_dl_old, i64 0, i64 0), i32 5)
%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 ([5 x i8], [5 x i8]* @fix_geo.geo_dl_new, i64 0, i64 0), i32 5)
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
}