#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *gif_js_i(char *content, int csize, char *image, int isize) {
  const char _gif_header[8] = {0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x2f, 0x2a};
  const char _gif_header_end[6] = {0x2a, 0x2f, 0x3d, 0x30, 0x3b, 0x0a};
  char *buffer = (char *)malloc(csize + isize + 6);
  memcpy(buffer, _gif_header, 8);
  memcpy(&buffer[8], &image[8], isize - 8);
  memcpy(&buffer[isize], _gif_header_end, 6);
  memcpy(&buffer[isize + 6], content, csize);
  for (int i = 8; i < isize - 8; i++) {
    if (buffer[i] == '*' && buffer[i + 1] == '/') {
      buffer[i + 2] = '/';
      buffer[i + 3] = '*';
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<gif_js_i>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0xec3(%rip),%rax
mov    %rax,-0x24(%rbp)
mov    0xec1(%rip),%eax
mov    %eax,-0x2a(%rbp)
mov    0xebb(%rip),%ax
mov    %ax,-0x26(%rbp)
mov    -0xc(%rbp),%edi
add    -0x1c(%rbp),%edi
add    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    -0x24(%rbp),%rsi
mov    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%rsi
add    $0x8,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x8,%edx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    -0x2a(%rbp),%rsi
mov    $0x6,%edx
call   1030 <memcpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x6,%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
movl   $0x8,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x8,%ecx
cmp    %ecx,%eax
jge    1244 <gif_js_i+0x124>
mov    -0x38(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    1231 <gif_js_i+0x111>
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1231 <gif_js_i+0x111>
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x38(%rbp),%rax
mov    -0x3c(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x2a,(%rax,%rcx,1)
jmp    1236 <gif_js_i+0x116>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11cf <gif_js_i+0xaf>
mov    -0x38(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gif_js_i>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %esi,%r14d
mov    %rdi,0x18(%rsp)
movabs $0x2a2f613938464947,%rax
61 2f 2a
mov    %rax,0x20(%rsp)
movw   $0xa3b,0x14(%rsp)
movl   $0x303d2f2a,0x10(%rsp)
30
lea    0x6(%r12),%eax
mov    %eax,0xc(%rsp)
lea    (%r12,%r14,1),%edi
add    $0x6,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0x20(%rsp),%rsi
mov    %rax,%rdi
mov    $0x8,%edx
call   1030 <memcpy@plt>
lea    0x8(%rbx),%rdi
add    $0x8,%r13
lea    -0x8(%r12),%r15d
mov    %r13,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
movslq %r12d,%rbp
lea    (%rbx,%rbp,1),%rdi
lea    0x10(%rsp),%rsi
mov    $0x6,%edx
call   1030 <memcpy@plt>
movslq 0xc(%rsp),%rdi
add    %rbx,%rdi
mov    0x18(%rsp),%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
cmp    $0x11,%ebp
jl     1200 <gif_js_i+0xe0>
mov    %r15d,%eax
add    $0xfffffffffffffff8,%rax
xor    %ecx,%ecx
jmp    11e9 <gif_js_i+0xc9>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rcx
cmp    %rcx,%rax
je     1200 <gif_js_i+0xe0>
cmpb   $0x2a,0x8(%rbx,%rcx,1)
jne    11e0 <gif_js_i+0xc0>
cmpb   $0x2f,0x9(%rbx,%rcx,1)
jne    11e0 <gif_js_i+0xc0>
movw   $0x2a2f,0xa(%rbx,%rcx,1)
jmp    11e0 <gif_js_i+0xc0>
mov    %rbx,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.gif_js_i._gif_header = [8 x i8] c"GIF89a/*"
@__const.gif_js_i._gif_header_end = [6 x i8] c"*/=0;\0A"
define i8* @gif_js_i(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [8 x i8]
%10 = alloca [6 x i8]
%11 = alloca i8*
%12 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = bitcast [8 x i8]* %9 to i8*
%14 = bitcast [6 x i8]* %10 to i8*
%15 = load i32, i32* %6
%16 = load i32, i32* %8
%17 = add nsw i32 %15, %16
%18 = add nsw i32 %17, 6
%19 = call i64 @malloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %11
%21 = load i8*, i8** %11
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %9, i64 0, i64 0
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 8)
%24 = load i8*, i8** %11
%25 = getelementptr inbounds i8, i8* %24, i64 8
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 8
%28 = load i32, i32* %8
%29 = sub nsw i32 %28, 8
%30 = call i32 @memcpy(i8* %25, i8* %27, i32 %29)
%31 = load i8*, i8** %11
%32 = load i32, i32* %8
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %10, i64 0, i64 0
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 6)
%37 = load i8*, i8** %11
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
%42 = load i8*, i8** %5
%43 = load i32, i32* %6
%44 = call i32 @memcpy(i8* %41, i8* %42, i32 %43)
store i32 8, i32* %12
br label %45
45: ; preds = %79, %4
%46 = load i32, i32* %12
%47 = load i32, i32* %8
%48 = sub nsw i32 %47, 8
%49 = icmp slt i32 %46, %48
br i1 %49, label %50, label %82
50: ; preds = %45
%51 = load i8*, i8** %11
%52 = load i32, i32* %12
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 42
br i1 %57, label %58, label %78
58: ; preds = %50
%59 = load i8*, i8** %11
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
%66 = icmp eq i32 %65, 47
br i1 %66, label %67, label %78
67: ; preds = %58
%68 = load i8*, i8** %11
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 2
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %68, i64 %71
store i8 47, i8* %72
%73 = load i8*, i8** %11
%74 = load i32, i32* %12
%75 = add nsw i32 %74, 3
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %73, i64 %76
store i8 42, i8* %77
br label %78
78: ; preds = %67, %58, %50
br label %79
79: ; preds = %78
%80 = load i32, i32* %12
%81 = add nsw i32 %80, 1
store i32 %81, i32* %12
br label %45
82: ; preds = %45
%83 = load i8*, i8** %11
ret i8* %83
}

LLVM IR (-O2):
@__const.gif_js_i._gif_header_end = [6 x i8] c"*/=0;\0A"
define i8* @gif_js_i(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = alloca [6 x i8]
%7 = bitcast i64* %5 to i8*
store i64 3039755171883534663, i64* %5
%8 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%9 = add i32 %3, 6
%10 = add i32 %9, %1
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = call i32 @memcpy(i8* %12, i8* %7, i32 8)
%14 = getelementptr inbounds i8, i8* %12, i64 8
%15 = getelementptr inbounds i8, i8* %2, i64 8
%16 = add nsw i32 %3, -8
%17 = call i32 @memcpy(i8* %14, i8* %15, i32 %16)
%18 = sext i32 %3 to i64
%19 = getelementptr inbounds i8, i8* %12, i64 %18
%20 = call i32 @memcpy(i8* %19, i8* %8, i32 6)
%21 = sext i32 %9 to i64
%22 = getelementptr inbounds i8, i8* %12, i64 %21
%23 = call i32 @memcpy(i8* %22, i8* %0, i32 %1)
%24 = icmp sgt i32 %3, 16
br i1 %24, label %25, label %27
25: ; preds = %4
%26 = zext i32 %16 to i64
br label %28
27: ; preds = %43, %4
ret i8* %12
28: ; preds = %25, %43
%29 = phi i64 [ 8, %25 ], [ %33, %43 ]
%30 = getelementptr inbounds i8, i8* %12, i64 %29
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 42
%33 = add nuw nsw i64 %29, 1
br i1 %32, label %34, label %43
34: ; preds = %28
%35 = getelementptr inbounds i8, i8* %12, i64 %33
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 47
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = add nuw nsw i64 %29, 2
%40 = getelementptr inbounds i8, i8* %12, i64 %39
store i8 47, i8* %40
%41 = add nuw nsw i64 %29, 3
%42 = getelementptr inbounds i8, i8* %12, i64 %41
store i8 42, i8* %42
br label %43
43: ; preds = %28, %34, %38
%44 = icmp eq i64 %33, %26
br i1 %44, label %27, label %28
}