#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 fgetc(int /*<<< orphan*/ *);
char is_md_token(char);
int /*<<< orphan*/ ungetc(int, int /*<<< orphan*/ *);
char *peek_chars(FILE *fp, char base_char, char *token_accumilator) {
  int i = 1, IS_CHAR = 1;
  token_accumilator[0] = base_char;
  while (IS_CHAR == 1) {
    int c = fgetc(fp);
    if (c == EOF) {
      break;
    }
    if (is_md_token((char)c) != '\0') {
      IS_CHAR = 0;
      ungetc(c, fp);
    } else {
      token_accumilator[i] = c;
      ++i;
    }
  }
  token_accumilator[i] = '\0';
  return token_accumilator;
}


x86 assembly (clang, -O0):
<peek_chars>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x1,-0x20(%rbp)
jne    11d7 <peek_chars+0xa7>
mov    -0x8(%rbp),%rdi
call   1030 <fgetc@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
jne    118a <peek_chars+0x5a>
jmp    11d7 <peek_chars+0xa7>
mov    -0x24(%rbp),%eax
movsbl %al,%edi
call   1050 <is_md_token@plt>
movsbl %al,%eax
cmp    $0x0,%eax
je     11b9 <peek_chars+0x89>
movl   $0x0,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x8(%rbp),%rsi
call   1040 <ungetc@plt>
jmp    11d2 <peek_chars+0xa2>
mov    -0x24(%rbp),%eax
mov    %al,%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    115d <peek_chars+0x2d>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peek_chars>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %rdi,%r15
mov    %sil,(%rdx)
call   1030 <fgetc@plt>
mov    0x2e9b(%rip),%r12
mov    $0x1,%ebx
cmp    (%r12),%eax
je     1191 <peek_chars+0x61>
mov    %eax,%ebp
mov    $0x1,%ebx
nop
movsbl %bpl,%edi
call   1050 <is_md_token@plt>
test   %al,%al
jne    1187 <peek_chars+0x57>
mov    %bpl,(%r14,%rbx,1)
mov    %r15,%rdi
call   1030 <fgetc@plt>
mov    %eax,%ebp
add    $0x1,%rbx
cmp    (%r12),%eax
jne    1160 <peek_chars+0x30>
jmp    1191 <peek_chars+0x61>
mov    %ebp,%edi
mov    %r15,%rsi
call   1040 <ungetc@plt>
mov    %ebx,%eax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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