#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 */
typedef int /*<<< orphan*/ value;

/* Variables and functions */
char *cloneString(char *);
int /*<<< orphan*/ errAbort(char *, unsigned long, char *);
scalar_t__ strchr(char *, char);
char *getMimeHeaderMainVal(char *header) {
  char value[1024];
  char *h = header;
  int i = 0;
  char *puncChars = ",;: \t\r\n";
  i = 0;
  while (1) {
    char c = *h++;
    if (c == 0 || strchr(puncChars, c))
      break;
    value[i++] = c;
    if (i >= sizeof(value))
      errAbort(
          "error: main value too long (>%lu) in MIME header Content-type:%s",
          (unsigned long)sizeof(value), header);
  }
  value[i] = 0;
  return cloneString(value);
}


x86 assembly (clang, -O0):
<getMimeHeaderMainVal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x418(%rbp)
movl   $0x0,-0x41c(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x428(%rbp)
movl   $0x0,-0x41c(%rbp)
mov    -0x418(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x418(%rbp)
mov    (%rax),%al
mov    %al,-0x429(%rbp)
movsbl -0x429(%rbp),%eax
cmp    $0x0,%eax
je     11b6 <getMimeHeaderMainVal+0x86>
mov    -0x428(%rbp),%rdi
movsbl -0x429(%rbp),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     11bb <getMimeHeaderMainVal+0x8b>
jmp    1208 <getMimeHeaderMainVal+0xd8>
mov    -0x429(%rbp),%cl
mov    -0x41c(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x41c(%rbp)
cltq
mov    %cl,-0x410(%rbp,%rax,1)
movslq -0x41c(%rbp),%rax
cmp    $0x400,%rax
jb     1203 <getMimeHeaderMainVal+0xd3>
mov    -0x8(%rbp),%rdx
lea    0xe0f(%rip),%rdi
mov    $0x400,%esi
call   1040 <errAbort@plt>
jmp    116c <getMimeHeaderMainVal+0x3c>
movslq -0x41c(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
call   1050 <cloneString@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMimeHeaderMainVal>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    (%rdi),%bpl
test   %bpl,%bpl
je     119f <getMimeHeaderMainVal+0x6f>
mov    %rdi,%r12
xor    %ebx,%ebx
lea    0xead(%rip),%r14
lea    0xeae(%rip),%r15
jmp    116f <getMimeHeaderMainVal+0x3f>
nopl   0x0(%rax)
movzbl 0x1(%r12,%rbx,1),%ebp
add    $0x1,%rbx
test   %bpl,%bpl
je     11a1 <getMimeHeaderMainVal+0x71>
movsbl %bpl,%esi
mov    %r14,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    11a1 <getMimeHeaderMainVal+0x71>
mov    %bpl,(%rsp,%rbx,1)
cmp    $0x3ff,%rbx
jb     1160 <getMimeHeaderMainVal+0x30>
mov    $0x400,%esi
mov    %r15,%rdi
mov    %r12,%rdx
call   1040 <errAbort@plt>
jmp    1160 <getMimeHeaderMainVal+0x30>
xor    %ebx,%ebx
mov    %ebx,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
call   1050 <cloneString@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c",;: \09\0D\0A\00"
@.str.1 = [65 x i8] c"error: main value too long (>%lu) in MIME header Content-type:%s\00"
define i8* @getMimeHeaderMainVal(i8* %0) {
%2 = alloca i8*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %2
%8 = load i8*, i8** %2
store i8* %8, i8** %4
store i32 0, i32* %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %5
br label %9
9: ; preds = %1, %34
%10 = load i8*, i8** %4
%11 = getelementptr inbounds i8, i8* %10, i32 1
store i8* %11, i8** %4
%12 = load i8, i8* %10
store i8 %12, i8* %7
%13 = load i8, i8* %7
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %9
%17 = load i8*, i8** %6
%18 = load i8, i8* %7
%19 = call i64 @strchr(i8* %17, i8 signext %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %16, %9
br label %35
22: ; preds = %16
%23 = load i8, i8* %7
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %26
store i8 %23, i8* %27
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = icmp uge i64 %29, 1024
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i8*, i8** %2
%33 = call i32 @errAbort(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i64 1024, i8* %32)
br label %34
34: ; preds = %31, %22
br label %9
35: ; preds = %21
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %37
store i8 0, i8* %38
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%40 = call i8* @cloneString(i8* %39)
ret i8* %40
}

LLVM IR (-O2):
@.str = [8 x i8] c",;: \09\0D\0A\00"
@.str.1 = [65 x i8] c"error: main value too long (>%lu) in MIME header Content-type:%s\00"
define i8* @getMimeHeaderMainVal(i8* %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %26, label %6
6: ; preds = %1, %21
%7 = phi i64 [ %15, %21 ], [ 0, %1 ]
%8 = phi i8 [ %22, %21 ], [ %4, %1 ]
%9 = phi i8* [ %11, %21 ], [ %0, %1 ]
%10 = phi i32 [ %16, %21 ], [ 0, %1 ]
%11 = getelementptr inbounds i8, i8* %9, i64 1
%12 = tail call i64 @strchr(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8 signext %8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %24
14: ; preds = %6
%15 = add nuw i64 %7, 1
%16 = add nuw nsw i32 %10, 1
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %7
store i8 %8, i8* %17
%18 = icmp ugt i64 %7, 1022
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32 @errAbort(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i64 1024, i8* %0)
br label %21
21: ; preds = %14, %19
%22 = load i8, i8* %11
%23 = icmp eq i8 %22, 0
br i1 %23, label %26, label %6
24: ; preds = %6
%25 = trunc i64 %7 to i32
br label %26
26: ; preds = %21, %24, %1
%27 = phi i32 [ 0, %1 ], [ %25, %24 ], [ %16, %21 ]
%28 = zext i32 %27 to i64
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 %28
store i8 0, i8* %29
%30 = call i8* @cloneString(i8* %3)
ret i8* %30
}