#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 */
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ ungetc(char, int /*<<< orphan*/ *);
char *peek_type(FILE *fp, char type, char *token_accumilator) {
  int i = 1;
  char c;
  token_accumilator[0] = type;
  while ((c = (char)fgetc(fp)) == type) {
    token_accumilator[i] = type;
    ++i;
  }
  ungetc(c, fp);
  token_accumilator[i] = '\0';
  return token_accumilator;
}


x86 assembly (clang, -O0):
<peek_type>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %al,-0x1d(%rbp)
movsbl %al,%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    117d <peek_type+0x5d>
mov    -0x9(%rbp),%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1146 <peek_type+0x26>
mov    -0x1d(%rbp),%al
mov    -0x8(%rbp),%rsi
movsbl %al,%edi
call   1040 <ungetc@plt>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek_type>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
mov    %bpl,(%rdx)
call   1030 <fgetc@plt>
mov    $0x1,%ebx
cmp    %bpl,%al
jne    1167 <peek_type+0x47>
mov    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %bpl,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1030 <fgetc@plt>
cmp    %bpl,%al
je     1150 <peek_type+0x30>
mov    %ebx,%ebx
movsbl %al,%edi
mov    %r15,%rsi
call   1040 <ungetc@plt>
movb   $0x0,(%r14,%rbx,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i8* @peek_type(i32* nocapture %0, i8 signext %1, i8* returned writeonly %2) {
store i8 %1, i8* %2
%4 = tail call i64 @fgetc(i32* %0)
%5 = trunc i64 %4 to i8
%6 = icmp eq i8 %5, %1
br i1 %6, label %7, label %17
7: ; preds = %3, %7
%8 = phi i64 [ %10, %7 ], [ 1, %3 ]
%9 = getelementptr inbounds i8, i8* %2, i64 %8
store i8 %1, i8* %9
%10 = add nuw i64 %8, 1
%11 = tail call i64 @fgetc(i32* %0)
%12 = trunc i64 %11 to i8
%13 = icmp eq i8 %12, %1
br i1 %13, label %7, label %14
14: ; preds = %7
%15 = trunc i64 %11 to i8
%16 = and i64 %10, 4294967295
br label %17
17: ; preds = %14, %3
%18 = phi i8 [ %15, %14 ], [ %5, %3 ]
%19 = phi i64 [ %16, %14 ], [ 1, %3 ]
%20 = tail call i32 @ungetc(i8 signext %18, i32* %0)
%21 = getelementptr inbounds i8, i8* %2, i64 %19
store i8 0, i8* %21
ret i8* %2
}