#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 uint32_t;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int, int, int);
unsigned int strlen(char *);
void insert_link(unsigned char *buf, uint32_t pointer) {
  char link[] = "<a href=\"AAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAAAAA"
                "AAAAAAAAAAAAA%xx"
                "%xx%xx%xx\"></a>";
  char tmp[32];
  unsigned int i;
  sprintf(tmp, "%%%02x%%%02x%%%02x%%%02x", pointer & 0xff,
          (pointer >> 8) & 0xff, (pointer >> 16) & 0xff,
          (pointer >> 24) & 0xff);
  memcpy(link + 0x11d, tmp, 12);
  buf[0] = 0xff;
  buf[1] = 0xfe;
  for (i = 0; i < strlen(link); i++) {
    buf[i * 2 + 2] = link[i];
    buf[i * 2 + 3] = 0;
  }
}


x86 assembly (clang, -O0):
<insert_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x140(%rbp),%rdi
lea    0xeb0(%rip),%rsi
mov    $0x130,%edx
call   1040 <memcpy@plt>
lea    -0x160(%rbp),%rdi
mov    -0xc(%rbp),%edx
and    $0xff,%edx
mov    -0xc(%rbp),%ecx
sar    $0x8,%ecx
and    $0xff,%ecx
mov    -0xc(%rbp),%r8d
sar    $0x10,%r8d
and    $0xff,%r8d
mov    -0xc(%rbp),%r9d
sar    $0x18,%r9d
and    $0xff,%r9d
lea    0xf95(%rip),%rsi
call   1050 <sprintf@plt>
lea    -0x140(%rbp),%rdi
add    $0x11d,%rdi
lea    -0x160(%rbp),%rsi
mov    $0xc,%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x8(%rbp),%rax
movb   $0xfe,0x1(%rax)
movl   $0x0,-0x164(%rbp)
mov    -0x164(%rbp),%eax
mov    %eax,-0x168(%rbp)
lea    -0x140(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x168(%rbp),%eax
cmp    %ecx,%eax
jae    124c <insert_link+0x11c>
mov    -0x164(%rbp),%eax
mov    -0x140(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x164(%rbp),%ecx
shl    $0x1,%ecx
add    $0x2,%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x164(%rbp),%ecx
shl    $0x1,%ecx
add    $0x3,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x164(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x164(%rbp)
jmp    11d8 <insert_link+0xa8>
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<insert_link>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %esi,%ebx
mov    %rdi,%r12
lea    0xeb6(%rip),%rsi
lea    0x20(%rsp),%r14
mov    $0x130,%edx
mov    %r14,%rdi
call   1040 <memcpy@plt>
movzbl %bl,%edx
movzbl %bh,%ecx
mov    %ebx,%eax
shr    $0x10,%eax
movzbl %al,%r8d
shr    $0x18,%ebx
lea    0xfbb(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebx,%r9d
call   1050 <sprintf@plt>
lea    0x13d(%rsp),%rdi
mov    %r15,%rsi
mov    $0xc,%edx
call   1040 <memcpy@plt>
movw   $0xfeff,(%r12)
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11ec <insert_link+0xbc>
mov    $0x2,%r15d
xor    %ebx,%ebx
lea    0x20(%rsp),%r14
nopl   0x0(%rax,%rax,1)
movzbl 0x20(%rsp,%rbx,1),%eax
mov    %r15d,%ecx
mov    %al,(%r12,%rcx,1)
lea    0x1(%r15),%eax
movb   $0x0,(%r12,%rax,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,%eax
add    $0x2,%r15d
cmp    %rax,%rbx
jb     11c0 <insert_link+0x90>
add    $0x158,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.insert_link.link = [304 x i8] c"<a href=\22AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%xx%xx%xx%xx\22></a>\00"
@.str = [25 x i8] c"%%%02x%%%02x%%%02x%%%02x\00"
define void @insert_link(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [304 x i8]
%6 = alloca [32 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%8 = bitcast [304 x i8]* %5 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%10 = load i32, i32* %4
%11 = and i32 %10, 255
%12 = load i32, i32* %4
%13 = ashr i32 %12, 8
%14 = and i32 %13, 255
%15 = load i32, i32* %4
%16 = ashr i32 %15, 16
%17 = and i32 %16, 255
%18 = load i32, i32* %4
%19 = ashr i32 %18, 24
%20 = and i32 %19, 255
%21 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %14, i32 %17, i32 %20)
%22 = getelementptr inbounds [304 x i8], [304 x i8]* %5, i64 0, i64 0
%23 = getelementptr inbounds i8, i8* %22, i64 285
%24 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%25 = call i32 @memcpy(i8* %23, i8* %24, i32 12)
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 -1, i8* %27
%28 = load i8*, i8** %3
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 -2, i8* %29
store i32 0, i32* %7
br label %30
30: ; preds = %52, %2
%31 = load i32, i32* %7
%32 = getelementptr inbounds [304 x i8], [304 x i8]* %5, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = icmp ult i32 %31, %33
br i1 %34, label %35, label %55
35: ; preds = %30
%36 = load i32, i32* %7
%37 = zext i32 %36 to i64
%38 = getelementptr inbounds [304 x i8], [304 x i8]* %5, i64 0, i64 %37
%39 = load i8, i8* %38
%40 = load i8*, i8** %3
%41 = load i32, i32* %7
%42 = mul i32 %41, 2
%43 = add i32 %42, 2
%44 = zext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %40, i64 %44
store i8 %39, i8* %45
%46 = load i8*, i8** %3
%47 = load i32, i32* %7
%48 = mul i32 %47, 2
%49 = add i32 %48, 3
%50 = zext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %46, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %35
%53 = load i32, i32* %7
%54 = add i32 %53, 1
store i32 %54, i32* %7
br label %30
55: ; preds = %30
ret void
}

LLVM IR (-O2):
@__const.insert_link.link = [304 x i8] c"<a href=\22AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA%xx%xx%xx%xx\22></a>\00"
@.str = [25 x i8] c"%%%02x%%%02x%%%02x%%%02x\00"
define void @insert_link(i8* nocapture writeonly %0, i32 %1) {
%3 = alloca [304 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [304 x i8], [304 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = and i32 %1, 255
%8 = lshr i32 %1, 8
%9 = and i32 %8, 255
%10 = lshr i32 %1, 16
%11 = and i32 %10, 255
%12 = lshr i32 %1, 24
%13 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %9, i32 %11, i32 %12)
%14 = getelementptr inbounds [304 x i8], [304 x i8]* %3, i64 0, i64 285
%15 = call i32 @memcpy(i8* %14, i8* %6, i32 12)
store i8 -1, i8* %0
%16 = getelementptr inbounds i8, i8* %0, i64 1
store i8 -2, i8* %16
%17 = call i32 @strlen(i8* %5)
%18 = icmp eq i32 %17, 0
br i1 %18, label %35, label %19
19: ; preds = %2, %19
%20 = phi i64 [ %31, %19 ], [ 0, %2 ]
%21 = getelementptr inbounds [304 x i8], [304 x i8]* %3, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = trunc i64 %20 to i32
%24 = shl i32 %23, 1
%25 = add i32 %24, 2
%26 = zext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 %22, i8* %27
%28 = add i32 %24, 3
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
%31 = add nuw nsw i64 %20, 1
%32 = call i32 @strlen(i8* %5)
%33 = zext i32 %32 to i64
%34 = icmp ult i64 %31, %33
br i1 %34, label %19, label %35
35: ; preds = %19, %2
ret void
}