#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 */
char *strdup(char *);
char tolower(char);
char *parse_image_format(char *data, int *len) {
  char *mime_type = strdup("image/xxx");
  mime_type[6] = tolower(data[0]);
  mime_type[7] = tolower(data[1]);
  mime_type[8] = tolower(data[2]);
  *len = 3;
  return mime_type;
}


x86 assembly (clang, -O0):
<parse_image_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xec9(%rip),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x8(%rbp),%rax
movsbl 0x2(%rax),%edi
call   1030 <tolower@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x10(%rbp),%rax
movl   $0x3,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_image_format>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xece(%rip),%rdi
call   1040 <strdup@plt>
mov    %rax,%rbx
movsbl (%r15),%edi
call   1030 <tolower@plt>
mov    %al,0x6(%rbx)
movsbl 0x1(%r15),%edi
call   1030 <tolower@plt>
mov    %al,0x7(%rbx)
movsbl 0x2(%r15),%edi
call   1030 <tolower@plt>
mov    %al,0x8(%rbx)
movl   $0x3,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [10 x i8] c"image/xxx\00"
define i8* @parse_image_format(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = call i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store i8* %6, i8** %5
%7 = load i8*, i8** %3
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = call signext i8 @tolower(i8 signext %9)
%11 = load i8*, i8** %5
%12 = getelementptr inbounds i8, i8* %11, i64 6
store i8 %10, i8* %12
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = call signext i8 @tolower(i8 signext %15)
%17 = load i8*, i8** %5
%18 = getelementptr inbounds i8, i8* %17, i64 7
store i8 %16, i8* %18
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 2
%21 = load i8, i8* %20
%22 = call signext i8 @tolower(i8 signext %21)
%23 = load i8*, i8** %5
%24 = getelementptr inbounds i8, i8* %23, i64 8
store i8 %22, i8* %24
%25 = load i32*, i32** %4
store i32 3, i32* %25
%26 = load i8*, i8** %5
ret i8* %26
}

LLVM IR (-O2):
@.str = [10 x i8] c"image/xxx\00"
define noalias i8* @parse_image_format(i8* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call dereferenceable_or_null(10) i8* @strdup(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%4 = load i8, i8* %0
%5 = tail call signext i8 @tolower(i8 signext %4)
%6 = getelementptr inbounds i8, i8* %3, i64 6
store i8 %5, i8* %6
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = tail call signext i8 @tolower(i8 signext %8)
%10 = getelementptr inbounds i8, i8* %3, i64 7
store i8 %9, i8* %10
%11 = getelementptr inbounds i8, i8* %0, i64 2
%12 = load i8, i8* %11
%13 = tail call signext i8 @tolower(i8 signext %12)
%14 = getelementptr inbounds i8, i8* %3, i64 8
store i8 %13, i8* %14
store i32 3, i32* %1
ret i8* %3
}