#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 *cgi_xalloc(int, char *);
int strlen(char *);
char *cgi_parse_boundary(char *content_type_string) {
  char *boundary =
      cgi_xalloc(strlen(content_type_string) - 27, "multipart boundary");
  int i = 0, e = 2;
  boundary[0] = '-';
  boundary[1] = '-';
  for (i = 0; i < strlen(content_type_string); i++) {
    if (i < 30)
      continue;
    boundary[e] = content_type_string[i];
    e++;
  }
  boundary[e] = '\0';
  return (boundary);
}


x86 assembly (clang, -O0):
<cgi_parse_boundary>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%edi
sub    $0x1b,%edi
lea    0xebf(%rip),%rsi
call   1040 <cgi_xalloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x2,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x2d,(%rax)
mov    -0x10(%rbp),%rax
movb   $0x2d,0x1(%rax)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
cmp    %ecx,%eax
jge    11c6 <cgi_parse_boundary+0xa6>
cmpl   $0x1e,-0x14(%rbp)
jge    1199 <cgi_parse_boundary+0x79>
jmp    11b8 <cgi_parse_boundary+0x98>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116e <cgi_parse_boundary+0x4e>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_parse_boundary>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
call   1030 <strlen@plt>
lea    -0x1b(%rax),%edi
lea    0xec6(%rip),%rsi
call   1040 <cgi_xalloc@plt>
mov    %rax,%r14
movw   $0x2d2d,(%rax)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    $0x2,%r12d
test   %eax,%eax
jle    118b <cgi_parse_boundary+0x6b>
xor    %ebx,%ebx
jmp    1173 <cgi_parse_boundary+0x53>
nopl   (%rax)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    118b <cgi_parse_boundary+0x6b>
cmp    $0x1e,%rbx
jb     1160 <cgi_parse_boundary+0x40>
movzbl (%r15,%rbx,1),%eax
movslq %r12d,%r12
mov    %al,(%r14,%r12,1)
add    $0x1,%r12d
jmp    1160 <cgi_parse_boundary+0x40>
movslq %r12d,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"multipart boundary\00"
define i8* @cgi_parse_boundary(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
%8 = sub nsw i32 %7, 27
%9 = call i8* @cgi_xalloc(i32 %8, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %3
store i32 0, i32* %4
store i32 2, i32* %5
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
store i8 45, i8* %11
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 1
store i8 45, i8* %13
store i32 0, i32* %4
br label %14
14: ; preds = %35, %1
%15 = load i32, i32* %4
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
%18 = icmp slt i32 %15, %17
br i1 %18, label %19, label %38
19: ; preds = %14
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 30
br i1 %21, label %22, label %23
22: ; preds = %19
br label %35
23: ; preds = %19
%24 = load i8*, i8** %2
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = load i8*, i8** %3
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 1
store i32 %34, i32* %5
br label %35
35: ; preds = %23, %22
%36 = load i32, i32* %4
%37 = add nsw i32 %36, 1
store i32 %37, i32* %4
br label %14
38: ; preds = %14
%39 = load i8*, i8** %3
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
%43 = load i8*, i8** %3
ret i8* %43
}

LLVM IR (-O2):
@.str = [19 x i8] c"multipart boundary\00"
define i8* @cgi_parse_boundary(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, -27
%4 = tail call i8* @cgi_xalloc(i32 %3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i8 45, i8* %4
%5 = getelementptr inbounds i8, i8* %4, i64 1
store i8 45, i8* %5
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %24
8: ; preds = %1, %18
%9 = phi i64 [ %20, %18 ], [ 0, %1 ]
%10 = phi i32 [ %19, %18 ], [ 2, %1 ]
%11 = icmp ult i64 %9, 30
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = getelementptr inbounds i8, i8* %0, i64 %9
%14 = load i8, i8* %13
%15 = sext i32 %10 to i64
%16 = getelementptr inbounds i8, i8* %4, i64 %15
store i8 %14, i8* %16
%17 = add nsw i32 %10, 1
br label %18
18: ; preds = %8, %12
%19 = phi i32 [ %10, %8 ], [ %17, %12 ]
%20 = add nuw nsw i64 %9, 1
%21 = tail call i32 @strlen(i8* %0)
%22 = sext i32 %21 to i64
%23 = icmp slt i64 %20, %22
br i1 %23, label %8, label %24
24: ; preds = %18, %1
%25 = phi i32 [ 2, %1 ], [ %19, %18 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %4, i64 %26
store i8 0, i8* %27
ret i8* %4
}