#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 */
scalar_t__ isalnum(char);
scalar_t__ strchr(char *, char);
char *tl_read_token(char *token, const char *str) {
  char *c = (char *)str;
  int i = 0;
  do {
    token[i] = *c;
    if (token[i] == '_') {
      token[i] = ' ';
    }
    ++i;
    ++c;
  } while (isalnum(token[i - 1]) || strchr(" _\'\"", token[i - 1]));
  token[i - 1] = '\0';
  --c;
  return c;
}


x86 assembly (clang, -O0):
<tl_read_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%dl
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
jne    1171 <tl_read_token+0x51>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x1d(%rbp)
jne    11d5 <tl_read_token+0xb5>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
lea    0xe3e(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    113f <tl_read_token+0x1f>
mov    -0x8(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tl_read_token>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x20,%ebp
lea    0xec7(%rip),%r15
jmp    1148 <tl_read_token+0x28>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
add    $0x1,%rbx
movzbl (%r14),%eax
cmp    $0x5f,%al
cmove  %ebp,%eax
mov    %al,(%rbx)
movsbl %al,%edi
call   1040 <isalnum@plt>
test   %rax,%rax
jne    1140 <tl_read_token+0x20>
movsbl (%rbx),%esi
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1140 <tl_read_token+0x20>
movb   $0x0,(%rbx)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [5 x i8] c" _'\22\00"
define i8* @tl_read_token(i8* nocapture %0, i8* %1) {
br label %3
3: ; preds = %18, %2
%4 = phi i64 [ 0, %2 ], [ %10, %18 ]
%5 = phi i8* [ %1, %2 ], [ %11, %18 ]
%6 = load i8, i8* %5
%7 = getelementptr inbounds i8, i8* %0, i64 %4
%8 = icmp eq i8 %6, 95
%9 = select i1 %8, i8 32, i8 %6
store i8 %9, i8* %7
%10 = add nuw i64 %4, 1
%11 = getelementptr inbounds i8, i8* %5, i64 1
%12 = tail call i64 @isalnum(i8 signext %9)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8, i8* %7
%16 = tail call i64 @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %19, label %18
18: ; preds = %14, %3
br label %3
19: ; preds = %14
store i8 0, i8* %7
ret i8* %5
}