#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 size_t ssize_t;

/* Variables and functions */
char *malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *skip_non_whitespace(char const *);
char *skip_to_end_quote(char const *);
char *skip_whitespace(char const *);
char *get_token(const char *p) {
  const char *p2;
  ssize_t len;
  char *token = NULL;
  if (!p || !*p)
    goto ret;
  p = skip_whitespace(p);
  if (*p == '\"')
    p2 = skip_to_end_quote(p + 1);
  else
    p2 = skip_non_whitespace(p);
  len = p2 - p;
  if (!len)
    goto ret;
  token = malloc((size_t)len + 1);
  if (token) {
    memcpy(token, p, (size_t)len);
    token[len] = '\0';
  }
ret:
  return token;
}


x86 assembly (clang, -O0):
<get_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     117c <get_token+0x2c>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1181 <get_token+0x31>
jmp    121e <get_token+0xce>
mov    -0x8(%rbp),%rdi
call   1030 <skip_whitespace@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x22,%eax
jne    11b4 <get_token+0x64>
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
call   1070 <skip_to_end_quote@plt>
mov    %rax,-0x10(%rbp)
jmp    11c1 <get_token+0x71>
mov    -0x8(%rbp),%rdi
call   1050 <skip_non_whitespace@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e0 <get_token+0x90>
jmp    121e <get_token+0xce>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1219 <get_token+0xc9>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    121e <get_token+0xce>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_token>:
push   %r15
push   %r14
push   %rbx
test   %rdi,%rdi
je     11ad <get_token+0x5d>
cmpb   $0x0,(%rdi)
je     11ad <get_token+0x5d>
call   1030 <skip_whitespace@plt>
mov    %rax,%r14
cmpb   $0x22,(%rax)
jne    1177 <get_token+0x27>
lea    0x1(%r14),%rdi
call   1070 <skip_to_end_quote@plt>
jmp    117f <get_token+0x2f>
mov    %r14,%rdi
call   1050 <skip_non_whitespace@plt>
mov    %rax,%r15
sub    %r14,%r15
je     11ad <get_token+0x5d>
lea    0x1(%r15),%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11ad <get_token+0x5d>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1040 <memcpy@plt>
movb   $0x0,(%rbx,%r15,1)
jmp    11af <get_token+0x5f>
xor    %ebx,%ebx
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @get_token(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %28, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %28, label %6
6: ; preds = %3
%7 = tail call i8* @skip_whitespace(i8* %0)
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 34
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = tail call i8* @skip_to_end_quote(i8* %11)
br label %15
13: ; preds = %6
%14 = tail call i8* @skip_non_whitespace(i8* %7)
br label %15
15: ; preds = %13, %10
%16 = phi i8* [ %12, %10 ], [ %14, %13 ]
%17 = ptrtoint i8* %16 to i64
%18 = ptrtoint i8* %7 to i64
%19 = sub i64 %17, %18
%20 = icmp eq i64 %19, 0
br i1 %20, label %28, label %21
21: ; preds = %15
%22 = add i64 %19, 1
%23 = tail call i8* @malloc(i64 %22)
%24 = icmp eq i8* %23, null
br i1 %24, label %28, label %25
25: ; preds = %21
%26 = tail call i32 @memcpy(i8* %23, i8* %7, i64 %19)
%27 = getelementptr inbounds i8, i8* %23, i64 %19
store i8 0, i8* %27
br label %28
28: ; preds = %21, %25, %15, %1, %3
%29 = phi i8* [ %23, %25 ], [ null, %21 ], [ null, %15 ], [ null, %3 ], [ null, %1 ]
ret i8* %29
}