#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 */
int EOF;
int getchar();
char *malloc(int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/);
char *read_str(char first_character) {
  static char buf[0x100];
  int i = 1;
  buf[0] = first_character;
  int c;
  while ((c = getchar()) != EOF) {
    if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c == '_') ||
        (c >= '0' && c <= '9'))
      buf[i++] = c;
    else
      break;
  }
  buf[i] = 0;
  char *res = malloc(i + 1);
  strcpy(res, buf);
  if (c != EOF)
    ungetc(c, stdin);
  return res;
}


x86 assembly (clang, -O0):
<read_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dil,%al
mov    %al,-0x1(%rbp)
movl   $0x1,-0x8(%rbp)
mov    -0x1(%rbp),%al
mov    %al,0x2ef2(%rip)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0xc(%rbp)
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%eax
je     11e9 <read_str+0xa9>
cmpl   $0x61,-0xc(%rbp)
jl     118b <read_str+0x4b>
cmpl   $0x7a,-0xc(%rbp)
jle    11bd <read_str+0x7d>
cmpl   $0x41,-0xc(%rbp)
jl     119f <read_str+0x5f>
cmpl   $0x5a,-0xc(%rbp)
jle    11bd <read_str+0x7d>
cmpl   $0x5f,-0xc(%rbp)
je     11bd <read_str+0x7d>
cmpl   $0x30,-0xc(%rbp)
jl     11df <read_str+0x9f>
cmpl   $0x39,-0xc(%rbp)
jg     11df <read_str+0x9f>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x8(%rbp)
movslq %eax,%rcx
lea    0x2e79(%rip),%rax
mov    %dl,(%rax,%rcx,1)
jmp    11e4 <read_str+0xa4>
jmp    11e9 <read_str+0xa9>
jmp    115e <read_str+0x1e>
movslq -0x8(%rbp),%rcx
lea    0x2e5c(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0x2e3e(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%eax
mov    0x2dbf(%rip),%rcx
cmp    (%rcx),%eax
je     123a <read_str+0xfa>
mov    -0xc(%rbp),%edi
mov    0x2db5(%rip),%rax
mov    (%rax),%esi
call   1060 <ungetc@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %dil,0x2f01(%rip)
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%r14d
mov    0x2e80(%rip),%r12
mov    $0x1,%ebx
cmp    (%r12),%eax
je     11b9 <read_str+0x79>
mov    $0x1,%ebx
lea    0x2ed9(%rip),%r15
jmp    1198 <read_str+0x58>
nopl   0x0(%rax)
mov    %r14b,(%rbx,%r15,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%r14d
cmp    (%r12),%eax
je     11b9 <read_str+0x79>
lea    -0x61(%r14),%eax
cmp    $0x1a,%eax
jb     1180 <read_str+0x40>
lea    -0x30(%r14),%eax
cmp    $0xa,%eax
jb     1180 <read_str+0x40>
cmp    $0x5f,%r14d
je     1180 <read_str+0x40>
lea    -0x41(%r14),%eax
cmp    $0x19,%eax
jbe    1180 <read_str+0x40>
mov    %ebx,%eax
lea    0x2e8e(%rip),%r15
movb   $0x0,(%rax,%r15,1)
add    $0x1,%ebx
mov    %ebx,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
cmp    (%r12),%r14d
je     11f6 <read_str+0xb6>
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1060 <ungetc@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@read_str.buf = internal global [256 x i8] zeroinitializer
@EOF = global i32 0
@stdin = global i32 0
define i8* @read_str(i8 signext %0) {
%2 = alloca i8
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8 %0, i8* %2
store i32 1, i32* %3
%6 = load i8, i8* %2
store i8 %6, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 0)
br label %7
7: ; preds = %40, %1
%8 = call i32 (...) @getchar()
store i32 %8, i32* %4
%9 = load i32, i32* @EOF
%10 = icmp ne i32 %8, %9
br i1 %10, label %11, label %41
11: ; preds = %7
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 97
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 122
br i1 %16, label %32, label %17
17: ; preds = %14, %11
%18 = load i32, i32* %4
%19 = icmp sge i32 %18, 65
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load i32, i32* %4
%22 = icmp sle i32 %21, 90
br i1 %22, label %32, label %23
23: ; preds = %20, %17
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 95
br i1 %25, label %32, label %26
26: ; preds = %23
%27 = load i32, i32* %4
%28 = icmp sge i32 %27, 48
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32, i32* %4
%31 = icmp sle i32 %30, 57
br i1 %31, label %32, label %39
32: ; preds = %29, %23, %20, %14
%33 = load i32, i32* %4
%34 = trunc i32 %33 to i8
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
%37 = sext i32 %35 to i64
%38 = getelementptr inbounds [256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 %37
store i8 %34, i8* %38
br label %40
39: ; preds = %29, %26
br label %41
40: ; preds = %32
br label %7
41: ; preds = %39, %7
%42 = load i32, i32* %3
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 %43
store i8 0, i8* %44
%45 = load i32, i32* %3
%46 = add nsw i32 %45, 1
%47 = call i8* @malloc(i32 %46)
store i8* %47, i8** %5
%48 = load i8*, i8** %5
%49 = call i32 @strcpy(i8* %48, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 0))
%50 = load i32, i32* %4
%51 = load i32, i32* @EOF
%52 = icmp ne i32 %50, %51
br i1 %52, label %53, label %57
53: ; preds = %41
%54 = load i32, i32* %4
%55 = load i32, i32* @stdin
%56 = call i32 @ungetc(i32 %54, i32 %55)
br label %57
57: ; preds = %53, %41
%58 = load i8*, i8** %5
ret i8* %58
}

LLVM IR (-O2):
@read_str.buf = internal global [256 x i8] zeroinitializer
@EOF = global i32 0
@stdin = global i32 0
define i8* @read_str(i8 signext %0) {
store i8 %0, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 0)
%2 = tail call i32 (...) @getchar()
%3 = load i32, i32* @EOF
%4 = icmp eq i32 %2, %3
br i1 %4, label %29, label %5
5: ; preds = %1, %18
%6 = phi i64 [ %20, %18 ], [ 1, %1 ]
%7 = phi i32 [ %22, %18 ], [ %2, %1 ]
%8 = add i32 %7, -97
%9 = icmp ult i32 %8, 26
br i1 %9, label %18, label %10
10: ; preds = %5
%11 = add i32 %7, -65
%12 = icmp ult i32 %11, 26
%13 = icmp eq i32 %7, 95
%14 = or i1 %13, %12
%15 = add i32 %7, -48
%16 = icmp ult i32 %15, 10
%17 = or i1 %16, %14
br i1 %17, label %18, label %25
18: ; preds = %10, %5
%19 = trunc i32 %7 to i8
%20 = add nuw i64 %6, 1
%21 = getelementptr inbounds [256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 %6
store i8 %19, i8* %21
%22 = tail call i32 (...) @getchar()
%23 = load i32, i32* @EOF
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %5
25: ; preds = %10, %18
%26 = phi i64 [ %20, %18 ], [ %6, %10 ]
%27 = phi i32 [ %22, %18 ], [ %7, %10 ]
%28 = trunc i64 %26 to i32
br label %29
29: ; preds = %25, %1
%30 = phi i32 [ 1, %1 ], [ %28, %25 ]
%31 = phi i32 [ %2, %1 ], [ %27, %25 ]
%32 = zext i32 %30 to i64
%33 = getelementptr inbounds [256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 %32
store i8 0, i8* %33
%34 = add nuw nsw i32 %30, 1
%35 = tail call i8* @malloc(i32 %34)
%36 = tail call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([256 x i8], [256 x i8]* @read_str.buf, i64 0, i64 0))
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %31, %37
br i1 %38, label %42, label %39
39: ; preds = %29
%40 = load i32, i32* @stdin
%41 = tail call i32 @ungetc(i32 %31, i32 %40)
br label %42
42: ; preds = %39, %29
ret i8* %35
}