#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__ isdigit(char const);
int valid_identifier(const char *str) {
  if (isdigit(str[0]))
    return 0;
  int i = 0;
  while (str[i]) {
    if (!(str[i] == '_' || isalnum(str[i])))
      return 0;
    ++i;
  }
  return 1;
}


x86 assembly (clang, -O0):
<valid_identifier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     114e <valid_identifier+0x2e>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <valid_identifier+0x98>
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     11b1 <valid_identifier+0x91>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
je     11a3 <valid_identifier+0x83>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isalnum@plt>
cmp    $0x0,%rax
jne    11a3 <valid_identifier+0x83>
movl   $0x0,-0x4(%rbp)
jmp    11b8 <valid_identifier+0x98>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1155 <valid_identifier+0x35>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<valid_identifier>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movsbl (%rdi),%edi
call   1030 <isdigit@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    1163 <valid_identifier+0x43>
jmp    1144 <valid_identifier+0x24>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5f,%al
je     1140 <valid_identifier+0x20>
test   %al,%al
je     115e <valid_identifier+0x3e>
movsbl %al,%edi
call   1040 <isalnum@plt>
test   %rax,%rax
jne    1140 <valid_identifier+0x20>
jmp    1163 <valid_identifier+0x43>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @valid_identifier(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = getelementptr inbounds i8, i8* %5, i64 0
%7 = load i8, i8* %6
%8 = call i64 @isdigit(i8 signext %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %40
11: ; preds = %1
store i32 0, i32* %4
br label %12
12: ; preds = %36, %11
%13 = load i8*, i8** %3
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %39
19: ; preds = %12
%20 = load i8*, i8** %3
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 95
br i1 %26, label %36, label %27
27: ; preds = %19
%28 = load i8*, i8** %3
%29 = load i32, i32* %4
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = call i64 @isalnum(i8 signext %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %27
store i32 0, i32* %2
br label %40
36: ; preds = %27, %19
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %12
39: ; preds = %12
store i32 1, i32* %2
br label %40
40: ; preds = %39, %35, %10
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @valid_identifier(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = tail call i64 @isdigit(i8 signext %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %1, %12
%6 = phi i64 [ %13, %12 ], [ 0, %1 ]
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
switch i8 %8, label %9 [
i8 0, label %14
i8 95, label %12
]
9: ; preds = %5
%10 = tail call i64 @isalnum(i8 signext %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %5, %9
%13 = add nuw i64 %6, 1
br label %5
14: ; preds = %9, %5, %1
%15 = phi i32 [ 0, %1 ], [ 1, %5 ], [ 0, %9 ]
ret i32 %15
}