#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 const);
scalar_t__ isalpha(char const);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
char *xmalloc(size_t);
char *parse_ident(const char **str) {
  const char *tmp = *str;
  if (!(isalpha((*tmp)) || (*tmp) == '_'))
    return NULL;
  else
    tmp++;
  while ((isalnum((*tmp)) || (*tmp) == '_'))
    tmp++;
  if (tmp == *str) {
    return NULL;
  } else {
    size_t len = tmp - *str;
    char *ret = xmalloc(len + 1);
    memcpy(ret, *str, len);
    ret[len] = '\0';
    *str = tmp;
    return ret;
  }
}


x86 assembly (clang, -O0):
<parse_ident>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1060 <isalpha@plt>
cmp    $0x0,%rax
jne    118a <parse_ident+0x4a>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
je     118a <parse_ident+0x4a>
movq   $0x0,-0x8(%rbp)
jmp    125e <parse_ident+0x11e>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119b <parse_ident+0x5b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
jne    11c9 <parse_ident+0x89>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5f,%eax
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11d9 <parse_ident+0x99>
jmp    11ea <parse_ident+0xaa>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    119b <parse_ident+0x5b>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jne    1208 <parse_ident+0xc8>
movq   $0x0,-0x8(%rbp)
jmp    125e <parse_ident+0x11e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_ident>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    (%rdi),%r12
movsbl (%r12),%edi
call   1060 <isalpha@plt>
test   %rax,%rax
jne    1167 <parse_ident+0x27>
cmpb   $0x5f,(%r12)
jne    11db <parse_ident+0x9b>
mov    $0xfffffffffffffffe,%r13
sub    %r12,%r13
add    $0x1,%r12
mov    %r12,%rbx
jmp    118c <parse_ident+0x4c>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
add    $0xffffffffffffffff,%r13
add    $0x1,%r12
movsbl (%rbx),%edi
call   1030 <isalnum@plt>
test   %rax,%rax
jne    1180 <parse_ident+0x40>
cmpb   $0x5f,(%rbx)
je     1180 <parse_ident+0x40>
mov    (%r14),%rbp
cmp    %rbp,%rbx
je     11db <parse_ident+0x9b>
mov    %r12,%r15
sub    %rbp,%r15
add    %rbp,%r13
neg    %r13
mov    %r13,%rdi
call   1040 <xmalloc@plt>
mov    %rax,%r13
mov    (%r14),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    %r13,%rax
sub    %rbp,%rax
movb   $0x0,(%rax,%r12,1)
mov    %rbx,(%r14)
jmp    11de <parse_ident+0x9e>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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