#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 const *);
int strlen(char const *);
char *http_dup_clean_value(const char *s) {
  char *result;
  int len;
  while (*s == ' ')
    s++;
  len = strlen(s);
  if (len >= 2 && s[0] == '"' && s[len - 1] == '"') {
    result = strdup(s + 1);
    len -= 2;
    result[len] = '\0';
  } else {
    result = strdup(s);
  }
  while (len > 0 && result[len - 1] == ' ') {
    len--;
    result[len] = '\0';
  }
  return result;
}


x86 assembly (clang, -O0):
<http_dup_clean_value>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
jne    114d <http_dup_clean_value+0x2d>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    112c <http_dup_clean_value+0xc>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     11b8 <http_dup_clean_value+0x98>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11b8 <http_dup_clean_value+0x98>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x22,%eax
jne    11b8 <http_dup_clean_value+0x98>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11c5 <http_dup_clean_value+0xa5>
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x10(%rbp)
jmp    11ca <http_dup_clean_value+0xaa>
xor    %eax,%eax
cmpl   $0x0,-0x14(%rbp)
mov    %al,-0x15(%rbp)
jle    11f3 <http_dup_clean_value+0xd3>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1203 <http_dup_clean_value+0xe3>
jmp    121d <http_dup_clean_value+0xfd>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ca <http_dup_clean_value+0xaa>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<http_dup_clean_value>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%rbx)
lea    0x1(%rbx),%rbx
je     1130 <http_dup_clean_value+0x10>
lea    -0x1(%rbx),%r15
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r14d
cmp    $0x2,%eax
jl     1176 <http_dup_clean_value+0x56>
cmpb   $0x22,(%r15)
jne    1176 <http_dup_clean_value+0x56>
lea    -0x1(%r14),%eax
cmpb   $0x22,-0x1(%rbx,%rax,1)
jne    1176 <http_dup_clean_value+0x56>
mov    %rbx,%rdi
call   1040 <strdup@plt>
add    $0xfffffffe,%r14d
movb   $0x0,(%rax,%r14,1)
test   %r14d,%r14d
jg     1183 <http_dup_clean_value+0x63>
jmp    11a7 <http_dup_clean_value+0x87>
mov    %r15,%rdi
call   1040 <strdup@plt>
test   %r14d,%r14d
jle    11a7 <http_dup_clean_value+0x87>
mov    %r14d,%ecx
add    $0x1,%rcx
nopw   0x0(%rax,%rax,1)
lea    -0x2(%rcx),%edx
cmpb   $0x20,(%rax,%rdx,1)
jne    11a7 <http_dup_clean_value+0x87>
movb   $0x0,(%rax,%rdx,1)
add    $0xffffffffffffffff,%rcx
cmp    $0x1,%rcx
ja     1190 <http_dup_clean_value+0x70>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @http_dup_clean_value(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
br label %5
5: ; preds = %10, %1
%6 = load i8*, i8** %2
%7 = load i8, i8* %6
%8 = sext i8 %7 to i32
%9 = icmp eq i32 %8, 32
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i8*, i8** %2
%12 = getelementptr inbounds i8, i8* %11, i32 1
store i8* %12, i8** %2
br label %5
13: ; preds = %5
%14 = load i8*, i8** %2
%15 = call i32 @strlen(i8* %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp sge i32 %16, 2
br i1 %17, label %18, label %43
18: ; preds = %13
%19 = load i8*, i8** %2
%20 = getelementptr inbounds i8, i8* %19, i64 0
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp eq i32 %22, 34
br i1 %23, label %24, label %43
24: ; preds = %18
%25 = load i8*, i8** %2
%26 = load i32, i32* %4
%27 = sub nsw i32 %26, 1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 34
br i1 %32, label %33, label %43
33: ; preds = %24
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %3
%37 = load i32, i32* %4
%38 = sub nsw i32 %37, 2
store i32 %38, i32* %4
%39 = load i8*, i8** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %39, i64 %41
store i8 0, i8* %42
br label %46
43: ; preds = %24, %18, %13
%44 = load i8*, i8** %2
%45 = call i8* @strdup(i8* %44)
store i8* %45, i8** %3
br label %46
46: ; preds = %43, %33
br label %47
47: ; preds = %61, %46
%48 = load i32, i32* %4
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %59
50: ; preds = %47
%51 = load i8*, i8** %3
%52 = load i32, i32* %4
%53 = sub nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %51, i64 %54
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = icmp eq i32 %57, 32
br label %59
59: ; preds = %50, %47
%60 = phi i1 [ false, %47 ], [ %58, %50 ]
br i1 %60, label %61, label %68
61: ; preds = %59
%62 = load i32, i32* %4
%63 = add nsw i32 %62, -1
store i32 %63, i32* %4
%64 = load i8*, i8** %3
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
store i8 0, i8* %67
br label %47
68: ; preds = %59
%69 = load i8*, i8** %3
ret i8* %69
}

LLVM IR (-O2):
define noalias i8* @http_dup_clean_value(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %6, %2 ]
%4 = load i8, i8* %3
%5 = icmp eq i8 %4, 32
%6 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %5, label %2, label %7
7: ; preds = %2
%8 = tail call i32 @strlen(i8* %3)
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %24
10: ; preds = %7
%11 = load i8, i8* %3
%12 = icmp eq i8 %11, 34
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = add nsw i32 %8, -1
%15 = zext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %3, i64 %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 34
br i1 %18, label %19, label %24
19: ; preds = %13
%20 = tail call i8* @strdup(i8* %6)
%21 = add nsw i32 %8, -2
%22 = zext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 0, i8* %23
br label %26
24: ; preds = %13, %10, %7
%25 = tail call i8* @strdup(i8* %3)
br label %26
26: ; preds = %24, %19
%27 = phi i8* [ %20, %19 ], [ %25, %24 ]
%28 = phi i32 [ %21, %19 ], [ %8, %24 ]
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %41
30: ; preds = %26
%31 = zext i32 %28 to i64
br label %32
32: ; preds = %30, %39
%33 = phi i64 [ %31, %30 ], [ %34, %39 ]
%34 = add nsw i64 %33, -1
%35 = and i64 %34, 4294967295
%36 = getelementptr inbounds i8, i8* %27, i64 %35
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 32
br i1 %38, label %39, label %41
39: ; preds = %32
store i8 0, i8* %36
%40 = icmp ugt i64 %33, 1
br i1 %40, label %32, label %41
41: ; preds = %32, %39, %26
ret i8* %27
}