#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
char *rfc2047_search_quote(const char **ptr) {
  const char *p = *ptr;
  char *s;
  while (**ptr && **ptr != '?')
    ++*ptr;
  if ((s = malloc(*ptr - p + 1)) == 0)
    return (0);
  memcpy(s, p, *ptr - p);
  s[*ptr - p] = 0;
  return (s);
}


x86 assembly (clang, -O0):
<rfc2047_search_quote>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x21(%rbp)
je     1162 <rfc2047_search_quote+0x42>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x3f,%eax
setne  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1172 <rfc2047_search_quote+0x52>
jmp    1185 <rfc2047_search_quote+0x65>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    1137 <rfc2047_search_quote+0x17>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11b9 <rfc2047_search_quote+0x99>
movq   $0x0,-0x8(%rbp)
jmp    11f4 <rfc2047_search_quote+0xd4>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rfc2047_search_quote>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
mov    (%rdi),%r14
lea    0x1(%r14),%rax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl -0x1(%rax),%ecx
test   %cl,%cl
je     1159 <rfc2047_search_quote+0x39>
cmp    $0x3f,%cl
je     1159 <rfc2047_search_quote+0x39>
mov    %rax,(%r15)
add    $0x1,%ebx
add    $0x1,%rax
jmp    1140 <rfc2047_search_quote+0x20>
lea    0x1(%rbx),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %rax,%rax
je     1181 <rfc2047_search_quote+0x61>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <memcpy@plt>
mov    (%r15),%rax
sub    %r14,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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