#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 *bmp_js_i(char *content, int csize, char *image, int isize) {
  const char _bmp_header[7] = {0x42, 0x4d, 0x3d, 0x30, 0x3b, 0x2f, 0x2a};
  const char _bmp_header_end[3] = {0x2a, 0x2f, 0x3b};
  char *buffer = (char *)malloc(csize + isize + 3);
  memcpy(buffer, _bmp_header, 7);
  memcpy(&buffer[7], &image[7], isize - 7);
  memcpy(&buffer[isize], _bmp_header_end, 3);
  memcpy(&buffer[isize + 3], content, csize);
  for (int i = 7; i < isize - 7; i++) {
    if (buffer[i] == '*' && buffer[i + 1] == '/') {
      buffer[i + 2] = '/';
      buffer[i + 3] = '*';
    }
  }
  return buffer;
}


x86 assembly (clang, -O0):
<bmp_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    0xec4(%rip),%eax
mov    %eax,-0x23(%rbp)
mov    0xebe(%rip),%ax
mov    %ax,-0x1f(%rbp)
mov    0xeb6(%rip),%al
mov    %al,-0x1d(%rbp)
mov    0xead(%rip),%ax
mov    %ax,-0x26(%rbp)
mov    0xea5(%rip),%al
mov    %al,-0x24(%rbp)
mov    -0xc(%rbp),%edi
add    -0x1c(%rbp),%edi
add    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
lea    -0x23(%rbp),%rsi
mov    $0x7,%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rdi
add    $0x7,%rdi
mov    -0x18(%rbp),%rsi
add    $0x7,%rsi
mov    -0x1c(%rbp),%edx
sub    $0x7,%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
lea    -0x26(%rbp),%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
cltq
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <memcpy@plt>
movl   $0x7,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x7,%ecx
cmp    %ecx,%eax
jge    1256 <bmp_js_i+0x136>
mov    -0x30(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2a,%eax
jne    1243 <bmp_js_i+0x123>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1243 <bmp_js_i+0x123>
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
mov    -0x34(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x2a,(%rax,%rcx,1)
jmp    1248 <bmp_js_i+0x128>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e1 <bmp_js_i+0xc1>
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bmp_js_i>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%r12d
mov    %rdx,%r13
mov    %esi,%r14d
mov    %rdi,0x10(%rsp)
movl   $0x2a2f3b30,0xb(%rsp)
2a
movl   $0x303d4d42,0x8(%rsp)
30
movb   $0x3b,0x2(%rsp)
movw   $0x2f2a,(%rsp)
lea    0x3(%r12),%eax
mov    %eax,0x4(%rsp)
lea    (%r12,%r14,1),%edi
add    $0x3,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0x7,%edx
call   1030 <memcpy@plt>
lea    0x7(%rbx),%rdi
add    $0x7,%r13
lea    -0x7(%r12),%r15d
mov    %r13,%rsi
mov    %r15d,%edx
call   1030 <memcpy@plt>
movslq %r12d,%rbp
lea    (%rbx,%rbp,1),%rdi
mov    %rsp,%rsi
mov    $0x3,%edx
call   1030 <memcpy@plt>
movslq 0x4(%rsp),%rdi
add    %rbx,%rdi
mov    0x10(%rsp),%rsi
mov    %r14d,%edx
call   1030 <memcpy@plt>
cmp    $0xf,%ebp
jl     1200 <bmp_js_i+0xe0>
mov    %r15d,%eax
add    $0xfffffffffffffff9,%rax
xor    %ecx,%ecx
jmp    11e9 <bmp_js_i+0xc9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rcx
cmp    %rcx,%rax
je     1200 <bmp_js_i+0xe0>
cmpb   $0x2a,0x7(%rbx,%rcx,1)
jne    11e0 <bmp_js_i+0xc0>
cmpb   $0x2f,0x8(%rbx,%rcx,1)
jne    11e0 <bmp_js_i+0xc0>
movw   $0x2a2f,0x9(%rbx,%rcx,1)
jmp    11e0 <bmp_js_i+0xc0>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.bmp_js_i._bmp_header = [7 x i8] c"BM=0;/*"
@__const.bmp_js_i._bmp_header_end = [3 x i8] c"*/;"
define i8* @bmp_js_i(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [7 x i8]
%10 = alloca [3 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 [7 x i8]* %9 to i8*
%14 = bitcast [3 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, 3
%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 [7 x i8], [7 x i8]* %9, i64 0, i64 0
%23 = call i32 @memcpy(i8* %21, i8* %22, i32 7)
%24 = load i8*, i8** %11
%25 = getelementptr inbounds i8, i8* %24, i64 7
%26 = load i8*, i8** %7
%27 = getelementptr inbounds i8, i8* %26, i64 7
%28 = load i32, i32* %8
%29 = sub nsw i32 %28, 7
%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 [3 x i8], [3 x i8]* %10, i64 0, i64 0
%36 = call i32 @memcpy(i8* %34, i8* %35, i32 3)
%37 = load i8*, i8** %11
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 3
%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 7, i32* %12
br label %45
45: ; preds = %79, %4
%46 = load i32, i32* %12
%47 = load i32, i32* %8
%48 = sub nsw i32 %47, 7
%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.bmp_js_i._bmp_header = [7 x i8] c"BM=0;/*"
@__const.bmp_js_i._bmp_header_end = [3 x i8] c"*/;"
define i8* @bmp_js_i(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [7 x i8]
%6 = alloca [3 x i8]
%7 = getelementptr inbounds [7 x i8], [7 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [3 x i8], [3 x i8]* %6, i64 0, i64 0
%9 = add i32 %3, 3
%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 7)
%14 = getelementptr inbounds i8, i8* %12, i64 7
%15 = getelementptr inbounds i8, i8* %2, i64 7
%16 = add nsw i32 %3, -7
%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 3)
%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, 14
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 [ 7, %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
}