#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 */
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
int GenerateImageHeader(char *mem, char *data, char *type, int len) {
  char ln[1000];
  int hlen;
  sprintf(mem, "HTTP/1.1 200 OK\r\n");
  strcat(mem, "Date: Sun, 21 Dec 2003 23:10:01 GMT\r\n");
  strcat(mem, "Server: IRTrans 2.0\r\n");
  strcat(mem, "Mime-Version: 1.0\r\n");
  sprintf(ln, "Content-Type: image/%s\r\nContent-Length: %6d\r\n", type, len);
  strcat(mem, ln);
  strcat(mem, "\r\n");
  hlen = (int)strlen(mem);
  memcpy(mem + hlen, data, len);
  return (hlen + len);
}


x86 assembly (clang, -O0):
<GenerateImageHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb1(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xeb7(%rip),%rsi
call   1050 <strcat@plt>
lea    -0x410(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xeb1(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x414(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x414(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x414(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GenerateImageHeader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %ecx,%r13d
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
movups 0xe9c(%rip),%xmm0
movups %xmm0,(%rdi)
movw   $0xa,0x10(%rdi)
lea    0xe9e(%rip),%rsi
call   1050 <strcat@plt>
lea    0xeb8(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
lea    0xebf(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
lea    0xec4(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %r15,%rdx
mov    %r13d,%ecx
xor    %eax,%eax
call   1060 <sprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <strcat@plt>
lea    0xe9c(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
add    %rbp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <memcpy@plt>
add    %r13d,%ebp
mov    %ebp,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.1 = [38 x i8] c"Date: Sun, 21 Dec 2003 23:10:01 GMT\0D\0A\00"
@.str.2 = [22 x i8] c"Server: IRTrans 2.0\0D\0A\00"
@.str.3 = [20 x i8] c"Mime-Version: 1.0\0D\0A\00"
@.str.4 = [46 x i8] c"Content-Type: image/%s\0D\0AContent-Length: %6d\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define i32 @GenerateImageHeader(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [1000 x i8]
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i8*, i8** %5
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** %5
%14 = call i32 @strcat(i8* %13, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%15 = load i8*, i8** %5
%16 = call i32 @strcat(i8* %15, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%17 = load i8*, i8** %5
%18 = call i32 @strcat(i8* %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%20 = load i8*, i8** %7
%21 = load i32, i32* %8
%22 = call i32 (i8*, i8*, ...) @sprintf(i8* %19, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %20, i32 %21)
%23 = load i8*, i8** %5
%24 = getelementptr inbounds [1000 x i8], [1000 x i8]* %9, i64 0, i64 0
%25 = call i32 @strcat(i8* %23, i8* %24)
%26 = load i8*, i8** %5
%27 = call i32 @strcat(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%28 = load i8*, i8** %5
%29 = call i64 @strlen(i8* %28)
%30 = trunc i64 %29 to i32
store i32 %30, i32* %10
%31 = load i8*, i8** %5
%32 = load i32, i32* %10
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8*, i8** %6
%36 = load i32, i32* %8
%37 = call i32 @memcpy(i8* %34, i8* %35, i32 %36)
%38 = load i32, i32* %10
%39 = load i32, i32* %8
%40 = add nsw i32 %38, %39
ret i32 %40
}

LLVM IR (-O2):
@.str = [18 x i8] c"HTTP/1.1 200 OK\0D\0A\00"
@.str.1 = [38 x i8] c"Date: Sun, 21 Dec 2003 23:10:01 GMT\0D\0A\00"
@.str.2 = [22 x i8] c"Server: IRTrans 2.0\0D\0A\00"
@.str.3 = [20 x i8] c"Mime-Version: 1.0\0D\0A\00"
@.str.4 = [46 x i8] c"Content-Type: image/%s\0D\0AContent-Length: %6d\0D\0A\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define i32 @GenerateImageHeader(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca [1000 x i8]
%6 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(18) %0, i8* align 1 dereferenceable(18) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i64 18, i1 false)
%7 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.4, i64 0, i64 0), i8* %2, i32 %3)
%11 = call i32 @strcat(i8* %0, i8* %6)
%12 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%13 = call i64 @strlen(i8* dereferenceable(1) %0)
%14 = trunc i64 %13 to i32
%15 = shl i64 %13, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = call i32 @memcpy(i8* %17, i8* %1, i32 %3)
%19 = add nsw i32 %14, %3
ret i32 %19
}