#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__ strchr(char *, char);
char *gather_word(char *ptr, char *word) {
  for (; strchr(
           "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$",
           *ptr);
       ptr++, word++)
    *word = *ptr;
  *word = 0;
  return ptr;
}


x86 assembly (clang, -O0):
<gather_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
lea    0xed5(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
je     1166 <gather_word+0x56>
mov    -0x8(%rbp),%rax
mov    (%rax),%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1120 <gather_word+0x10>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gather_word>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
movsbl (%rdi),%esi
lea    0xedb(%rip),%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     115f <gather_word+0x4f>
lea    0xeca(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
movzbl (%rbx),%eax
mov    %al,(%r14)
add    $0x1,%r14
movsbl 0x1(%rbx),%esi
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <strchr@plt>
test   %rax,%rax
jne    1140 <gather_word+0x30>
movb   $0x0,(%r14)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [65 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$\00"
define i8* @gather_word(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
br label %5
5: ; preds = %14, %2
%6 = load i8*, i8** %3
%7 = load i8, i8* %6
%8 = call i64 @strchr(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8 signext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %5
%11 = load i8*, i8** %3
%12 = load i8, i8* %11
%13 = load i8*, i8** %4
store i8 %12, i8* %13
br label %14
14: ; preds = %10
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %3
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %4
br label %5
19: ; preds = %5
%20 = load i8*, i8** %4
store i8 0, i8* %20
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [65 x i8] c"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$\00"
define i8* @gather_word(i8* %0, i8* nocapture writeonly %1) {
%3 = load i8, i8* %0
%4 = tail call i64 @strchr(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %2, %6
%7 = phi i8* [ %11, %6 ], [ %1, %2 ]
%8 = phi i8* [ %10, %6 ], [ %0, %2 ]
%9 = load i8, i8* %8
store i8 %9, i8* %7
%10 = getelementptr inbounds i8, i8* %8, i64 1
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %10
%13 = tail call i64 @strchr(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %6
15: ; preds = %6, %2
%16 = phi i8* [ %0, %2 ], [ %10, %6 ]
%17 = phi i8* [ %1, %2 ], [ %11, %6 ]
store i8 0, i8* %17
ret i8* %16
}