#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int getc(int /*<<< orphan*/ *);
scalar_t__ isalnum(unsigned char);
char *mpc_alloc_str(size_t);
char *mpc_realloc_str(char *, size_t, size_t);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
char *extract_suffix(FILE *stream) {
  int c;
  size_t nread = 0;
  size_t strsize = 100;
  char *str = mpc_alloc_str(strsize);
  c = getc(stream);
  while (isalnum((unsigned char)c) || c == '_') {
    str[nread] = (char)c;
    nread++;
    if (nread == strsize) {
      str = mpc_realloc_str(str, strsize, 2 * strsize);
      strsize *= 2;
    }
    c = getc(stream);
  }
  str = mpc_realloc_str(str, strsize, nread + 1);
  strsize = nread + 1;
  str[nread] = '\0';
  if (c != EOF)
    ungetc(c, stream);
  return str;
}


x86 assembly (clang, -O0):
<extract_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x64,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <mpc_alloc_str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
movzbl %al,%edi
call   1040 <isalnum@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x29(%rbp)
jne    11ac <extract_suffix+0x5c>
cmpl   $0x5f,-0xc(%rbp)
sete   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11bc <extract_suffix+0x6c>
jmp    121c <extract_suffix+0xcc>
mov    -0xc(%rbp),%eax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    120b <extract_suffix+0xbb>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x20(%rbp),%rdx
shl    $0x1,%rdx
call   1060 <mpc_realloc_str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0xc(%rbp)
jmp    1185 <extract_suffix+0x35>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
call   1060 <mpc_realloc_str@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
mov    0x2d91(%rip),%rcx
cmp    (%rcx),%eax
je     126b <extract_suffix+0x11b>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1050 <ungetc@plt>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<extract_suffix>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x64,%r12d
mov    $0x64,%edi
call   1030 <mpc_alloc_str@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
movzbl %bpl,%edi
call   1040 <isalnum@plt>
cmp    $0x5f,%ebp
je     1193 <extract_suffix+0x43>
test   %rax,%rax
jne    1193 <extract_suffix+0x43>
xor    %r13d,%r13d
jmp    11e2 <extract_suffix+0x92>
mov    $0x64,%r12d
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    %bpl,(%r15,%r13,1)
add    $0x1,%r13
cmp    %r12,%r13
jne    11c5 <extract_suffix+0x75>
lea    (%r12,%r12,1),%rbx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1060 <mpc_realloc_str@plt>
mov    %rax,%r15
mov    %rbx,%r12
mov    %r14,%rdi
call   1070 <getc@plt>
mov    %eax,%ebp
movzbl %bpl,%edi
call   1040 <isalnum@plt>
cmp    $0x5f,%ebp
je     11a0 <extract_suffix+0x50>
test   %rax,%rax
jne    11a0 <extract_suffix+0x50>
lea    0x1(%r13),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1060 <mpc_realloc_str@plt>
mov    %rax,%rbx
movb   $0x0,(%rax,%r13,1)
mov    0x2de8(%rip),%rax
cmp    (%rax),%ebp
je     120e <extract_suffix+0xbe>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <ungetc@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @extract_suffix(i32* nocapture %0) {
%2 = tail call i8* @mpc_alloc_str(i64 100)
%3 = tail call i32 @getc(i32* %0)
%4 = trunc i32 %3 to i8
%5 = tail call i64 @isalnum(i8 zeroext %4)
%6 = icmp ne i64 %5, 0
%7 = icmp eq i32 %3, 95
%8 = or i1 %7, %6
br i1 %8, label %9, label %29
9: ; preds = %1, %20
%10 = phi i8 [ %24, %20 ], [ %4, %1 ]
%11 = phi i8* [ %22, %20 ], [ %2, %1 ]
%12 = phi i64 [ %21, %20 ], [ 100, %1 ]
%13 = phi i64 [ %15, %20 ], [ 0, %1 ]
%14 = getelementptr inbounds i8, i8* %11, i64 %13
store i8 %10, i8* %14
%15 = add i64 %13, 1
%16 = icmp eq i64 %15, %12
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = shl i64 %12, 1
%19 = tail call i8* @mpc_realloc_str(i8* %11, i64 %12, i64 %18)
br label %20
20: ; preds = %17, %9
%21 = phi i64 [ %18, %17 ], [ %12, %9 ]
%22 = phi i8* [ %19, %17 ], [ %11, %9 ]
%23 = tail call i32 @getc(i32* %0)
%24 = trunc i32 %23 to i8
%25 = tail call i64 @isalnum(i8 zeroext %24)
%26 = icmp ne i64 %25, 0
%27 = icmp eq i32 %23, 95
%28 = or i1 %27, %26
br i1 %28, label %9, label %29
29: ; preds = %20, %1
%30 = phi i32 [ %3, %1 ], [ %23, %20 ]
%31 = phi i64 [ 0, %1 ], [ %15, %20 ]
%32 = phi i64 [ 100, %1 ], [ %21, %20 ]
%33 = phi i8* [ %2, %1 ], [ %22, %20 ]
%34 = add i64 %31, 1
%35 = tail call i8* @mpc_realloc_str(i8* %33, i64 %32, i64 %34)
%36 = getelementptr inbounds i8, i8* %35, i64 %31
store i8 0, i8* %36
%37 = load i32, i32* @EOF
%38 = icmp eq i32 %30, %37
br i1 %38, label %41, label %39
39: ; preds = %29
%40 = tail call i32 @ungetc(i32 %30, i32* %0)
br label %41
41: ; preds = %39, %29
ret i8* %35
}