#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);
char *parse_mime_type(char *data, int *i) {
  char *mime_type = (char *)malloc(30 * sizeof(char));
  while (data[*i] != '\0') {
    mime_type[*i - 1] = data[*i];
    (*i)++;
  }
  return mime_type;
}


x86 assembly (clang, -O0):
<parse_mime_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1e,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1177 <parse_mime_type+0x67>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    112e <parse_mime_type+0x1e>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_mime_type>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    $0x1e,%edi
call   1030 <malloc@plt>
movslq (%rbx),%rcx
mov    (%r14,%rcx,1),%dl
test   %dl,%dl
je     114a <parse_mime_type+0x3a>
nop
movslq %ecx,%rcx
mov    %dl,-0x1(%rcx,%rax,1)
movslq (%rbx),%rdx
lea    0x1(%rdx),%rcx
mov    %ecx,(%rbx)
movzbl 0x1(%r14,%rdx,1),%edx
test   %dl,%dl
jne    1130 <parse_mime_type+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i8* @parse_mime_type(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 i64 @malloc(i32 30)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %5
br label %8
8: ; preds = %17, %2
%9 = load i8*, i8** %3
%10 = load i32*, i32** %4
%11 = load i32, i32* %10
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %8
%18 = load i8*, i8** %3
%19 = load i32*, i32** %4
%20 = load i32, i32* %19
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i8, i8* %22
%24 = load i8*, i8** %5
%25 = load i32*, i32** %4
%26 = load i32, i32* %25
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %24, i64 %28
store i8 %23, i8* %29
%30 = load i32*, i32** %4
%31 = load i32, i32* %30
%32 = add nsw i32 %31, 1
store i32 %32, i32* %30
br label %8
33: ; preds = %8
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
define i8* @parse_mime_type(i8* nocapture %0, i32* nocapture %1) {
%3 = tail call i64 @malloc(i32 30)
%4 = inttoptr i64 %3 to i8*
%5 = load i32, i32* %1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %2, %10
%11 = phi i8 [ %20, %10 ], [ %8, %2 ]
%12 = phi i32 [ %17, %10 ], [ %5, %2 ]
%13 = add nsw i32 %12, -1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %4, i64 %14
store i8 %11, i8* %15
%16 = load i32, i32* %1
%17 = add nsw i32 %16, 1
store i32 %17, i32* %1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %10
22: ; preds = %10, %2
ret i8* %4
}