#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 */
struct dynamic_buffer {
  int dummy;
};

/* Variables and functions */
char *dynbuffer_data(struct dynamic_buffer *);
int /*<<< orphan*/ dynbuffer_free(struct dynamic_buffer *);
struct dynamic_buffer *dynbuffer_unattached_mode_new();
int /*<<< orphan*/ dynbuffer_write(struct dynamic_buffer *, char const *, int);
char *parse_token_string(const char **pp) {
  const char *p = *pp;
  char c = *p++;
  struct dynamic_buffer *token_buff = dynbuffer_unattached_mode_new();
  while (*p != '\0') {
    if (*p != c) {
      dynbuffer_write(token_buff, p, 1);
      p++;
    } else {
      p++;
      break;
    }
  }
  *pp = p;
  char *data = dynbuffer_data(token_buff);
  dynbuffer_free(token_buff);
  return data;
}


x86 assembly (clang, -O0):
<parse_token_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    $0x0,%al
call   1060 <dynbuffer_unattached_mode_new@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d2 <parse_token_string+0x92>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x11(%rbp),%ecx
cmp    %ecx,%eax
je     11bc <parse_token_string+0x7c>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1040 <dynbuffer_write@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11cd <parse_token_string+0x8d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    11d2 <parse_token_string+0x92>
jmp    1176 <parse_token_string+0x36>
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <dynbuffer_data@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <dynbuffer_free@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_token_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%rbx
mov    (%rbx),%bpl
xor    %eax,%eax
call   1060 <dynbuffer_unattached_mode_new@plt>
mov    %rax,%r15
mov    0x1(%rbx),%al
test   %al,%al
je     119b <parse_token_string+0x5b>
cmp    %bpl,%al
je     1195 <parse_token_string+0x55>
add    $0x2,%rbx
nopw   0x0(%rax,%rax,1)
lea    -0x1(%rbx),%rsi
mov    %r15,%rdi
mov    $0x1,%edx
call   1040 <dynbuffer_write@plt>
movzbl (%rbx),%eax
test   %al,%al
je     119f <parse_token_string+0x5f>
add    $0x1,%rbx
cmp    %bpl,%al
jne    1170 <parse_token_string+0x30>
add    $0xfffffffffffffffe,%rbx
add    $0x2,%rbx
jmp    119f <parse_token_string+0x5f>
add    $0x1,%rbx
mov    %rbx,(%r14)
mov    %r15,%rdi
call   1030 <dynbuffer_data@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1050 <dynbuffer_free@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dynamic_buffer = type { i32 }
define i8* @parse_token_string(i8** %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8
%5 = alloca %struct.dynamic_buffer*
%6 = alloca i8*
store i8** %0, i8*** %2
%7 = load i8**, i8*** %2
%8 = load i8*, i8** %7
store i8* %8, i8** %3
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i32 1
store i8* %10, i8** %3
%11 = load i8, i8* %9
store i8 %11, i8* %4
%12 = call %struct.dynamic_buffer* (...) @dynbuffer_unattached_mode_new()
store %struct.dynamic_buffer* %12, %struct.dynamic_buffer** %5
br label %13
13: ; preds = %34, %1
%14 = load i8*, i8** %3
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %35
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %21, %23
br i1 %24, label %25, label %31
25: ; preds = %18
%26 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %5
%27 = load i8*, i8** %3
%28 = call i32 @dynbuffer_write(%struct.dynamic_buffer* %26, i8* %27, i32 1)
%29 = load i8*, i8** %3
%30 = getelementptr inbounds i8, i8* %29, i32 1
store i8* %30, i8** %3
br label %34
31: ; preds = %18
%32 = load i8*, i8** %3
%33 = getelementptr inbounds i8, i8* %32, i32 1
store i8* %33, i8** %3
br label %35
34: ; preds = %25
br label %13
35: ; preds = %31, %13
%36 = load i8*, i8** %3
%37 = load i8**, i8*** %2
store i8* %36, i8** %37
%38 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %5
%39 = call i8* @dynbuffer_data(%struct.dynamic_buffer* %38)
store i8* %39, i8** %6
%40 = load %struct.dynamic_buffer*, %struct.dynamic_buffer** %5
%41 = call i32 @dynbuffer_free(%struct.dynamic_buffer* %40)
%42 = load i8*, i8** %6
ret i8* %42
}

LLVM IR (-O2):
%struct.dynamic_buffer = type { i32 }
define i8* @parse_token_string(i8** nocapture %0) {
%2 = load i8*, i8** %0
%3 = load i8, i8* %2
%4 = tail call %struct.dynamic_buffer* (...) @dynbuffer_unattached_mode_new()
%5 = getelementptr inbounds i8, i8* %2, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %21, label %8
8: ; preds = %1
%9 = icmp eq i8 %6, %3
br i1 %9, label %18, label %12
10: ; preds = %12
%11 = icmp eq i8 %16, %3
br i1 %11, label %18, label %12
12: ; preds = %8, %10
%13 = phi i8* [ %15, %10 ], [ %5, %8 ]
%14 = tail call i32 @dynbuffer_write(%struct.dynamic_buffer* %4, i8* %13, i32 1)
%15 = getelementptr inbounds i8, i8* %13, i64 1
%16 = load i8, i8* %15
%17 = icmp eq i8 %16, 0
br i1 %17, label %21, label %10
18: ; preds = %10, %8
%19 = phi i8* [ %2, %8 ], [ %13, %10 ]
%20 = getelementptr inbounds i8, i8* %19, i64 2
br label %21
21: ; preds = %12, %1, %18
%22 = phi i8* [ %20, %18 ], [ %5, %1 ], [ %15, %12 ]
store i8* %22, i8** %0
%23 = tail call i8* @dynbuffer_data(%struct.dynamic_buffer* %4)
%24 = tail call i32 @dynbuffer_free(%struct.dynamic_buffer* %4)
ret i8* %23
}