#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 atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ strspn(char *, char *);
int rle_token(FILE *new_file, char *tag) {
  static FILE *file = NULL;
  static char buff[100];
  static int i;
  if (new_file != NULL) {
    file = new_file;
    buff[0] = '\0';
    i = 0;
  } else if (file == NULL)
    return -1;
  i += strspn(buff + i, " \n\t\r");
  if (buff[i] == '\0') {
    i = 0;
    if (fgets(buff, 100, file) == NULL)
      return -1;
  } else if (buff[i] == '!')
    return 0;
  int len;
  len = atoi(buff + i);
  i += strspn(buff + i, "0123456789");
  *tag = buff[i++];
  return len ? len : 1;
}


x86 assembly (clang, -O0):
<rle_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116c <rle_token+0x3c>
mov    -0x10(%rbp),%rax
mov    %rax,0x2efa(%rip)
movb   $0x0,0x2f03(%rip)
movl   $0x0,0x2f5d(%rip)
jmp    118b <rle_token+0x5b>
cmpq   $0x0,0x2edc(%rip)
jne    1186 <rle_token+0x56>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d4 <rle_token+0x1a4>
jmp    118b <rle_token+0x5b>
movslq 0x2f32(%rip),%rax
lea    0x2ec7(%rip),%rdi
add    %rax,%rdi
lea    0xe5d(%rip),%rsi
call   1030 <strspn@plt>
mov    %rax,%rcx
movslq 0x2f12(%rip),%rax
add    %rcx,%rax
mov    %eax,0x2f09(%rip)
movslq 0x2f02(%rip),%rcx
lea    0x2e97(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    1213 <rle_token+0xe3>
movl   $0x0,0x2ee4(%rip)
mov    0x2e69(%rip),%rdx
lea    0x2e72(%rip),%rdi
mov    $0x64,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
jne    120e <rle_token+0xde>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d4 <rle_token+0x1a4>
jmp    123f <rle_token+0x10f>
movslq 0x2eaa(%rip),%rcx
lea    0x2e3f(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x21,%eax
jne    123a <rle_token+0x10a>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <rle_token+0x1a4>
jmp    123f <rle_token+0x10f>
movslq 0x2e7e(%rip),%rax
lea    0x2e13(%rip),%rdi
add    %rax,%rdi
call   1050 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movslq 0x2e65(%rip),%rax
lea    0x2dfa(%rip),%rdi
add    %rax,%rdi
lea    0xd95(%rip),%rsi
call   1030 <strspn@plt>
mov    %rax,%rcx
movslq 0x2e45(%rip),%rax
add    %rcx,%rax
mov    %eax,0x2e3c(%rip)
mov    0x2e36(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2e2b(%rip)
movslq %eax,%rcx
lea    0x2dbd(%rip),%rax
mov    (%rax,%rcx,1),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
cmpl   $0x0,-0x1c(%rbp)
je     12c1 <rle_token+0x191>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    12ce <rle_token+0x19e>
mov    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12ce <rle_token+0x19e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rle_token>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
test   %rdi,%rdi
je     1155 <rle_token+0x25>
mov    %rdi,%r15
mov    %rdi,0x2f06(%rip)
movb   $0x0,0x2f0f(%rip)
xor    %eax,%eax
jmp    116b <rle_token+0x3b>
mov    0x2ef4(%rip),%r15
test   %r15,%r15
je     1210 <rle_token+0xe0>
mov    0x2f59(%rip),%eax
movslq %eax,%rbp
lea    0x2eeb(%rip),%r12
lea    (%r12,%rbp,1),%rdi
lea    0xe80(%rip),%rsi
call   1030 <strspn@plt>
add    %eax,%ebp
mov    %ebp,0x2f37(%rip)
movslq %ebp,%rbx
mov    (%rbx,%r12,1),%al
cmp    $0x21,%al
je     120c <rle_token+0xdc>
test   %al,%al
jne    11c8 <rle_token+0x98>
movl   $0x0,0x2f1e(%rip)
lea    0x2eb3(%rip),%rdi
mov    $0x64,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1210 <rle_token+0xe0>
mov    0x2eff(%rip),%ebp
movslq %ebp,%rbx
add    %r12,%rbx
mov    %rbx,%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
lea    0xe28(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strspn@plt>
mov    %ebp,%ecx
add    %eax,%ecx
add    %ebp,%eax
add    $0x1,%eax
mov    %eax,0x2ed0(%rip)
movslq %ecx,%rax
mov    (%rax,%r12,1),%al
mov    %al,(%r14)
test   %r15d,%r15d
mov    $0x1,%eax
cmovne %r15d,%eax
jmp    1215 <rle_token+0xe5>
xor    %eax,%eax
jmp    1215 <rle_token+0xe5>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@rle_token.file = internal global i32* null
@rle_token.buff = internal global [100 x i8] zeroinitializer
@rle_token.i = internal global i32 0
@.str = [5 x i8] c" \0A\09\0D\00"
@.str.1 = [11 x i8] c"0123456789\00"
define i32 @rle_token(i32* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
%7 = load i32*, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = load i32*, i32** %4
store i32* %10, i32** @rle_token.file
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0)
store i32 0, i32* @rle_token.i
br label %16
11: ; preds = %2
%12 = load i32*, i32** @rle_token.file
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %11
store i32 -1, i32* %3
br label %72
15: ; preds = %11
br label %16
16: ; preds = %15, %9
%17 = load i32, i32* @rle_token.i
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0), i64 %18
%20 = call i64 @strspn(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* @rle_token.i
%22 = sext i32 %21 to i64
%23 = add nsw i64 %22, %20
%24 = trunc i64 %23 to i32
store i32 %24, i32* @rle_token.i
%25 = load i32, i32* @rle_token.i
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %16
store i32 0, i32* @rle_token.i
%32 = load i32*, i32** @rle_token.file
%33 = call i32* @fgets(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0), i32 100, i32* %32)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 -1, i32* %3
br label %72
36: ; preds = %31
br label %46
37: ; preds = %16
%38 = load i32, i32* @rle_token.i
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 33
br i1 %43, label %44, label %45
44: ; preds = %37
store i32 0, i32* %3
br label %72
45: ; preds = %37
br label %46
46: ; preds = %45, %36
%47 = load i32, i32* @rle_token.i
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0), i64 %48
%50 = call i32 @atoi(i8* %49)
store i32 %50, i32* %6
%51 = load i32, i32* @rle_token.i
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0), i64 %52
%54 = call i64 @strspn(i8* %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%55 = load i32, i32* @rle_token.i
%56 = sext i32 %55 to i64
%57 = add nsw i64 %56, %54
%58 = trunc i64 %57 to i32
store i32 %58, i32* @rle_token.i
%59 = load i32, i32* @rle_token.i
%60 = add nsw i32 %59, 1
store i32 %60, i32* @rle_token.i
%61 = sext i32 %59 to i64
%62 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %61
%63 = load i8, i8* %62
%64 = load i8*, i8** %5
store i8 %63, i8* %64
%65 = load i32, i32* %6
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %46
%68 = load i32, i32* %6
br label %70
69: ; preds = %46
br label %70
70: ; preds = %69, %67
%71 = phi i32 [ %68, %67 ], [ 1, %69 ]
store i32 %71, i32* %3
br label %72
72: ; preds = %70, %44, %35, %14
%73 = load i32, i32* %3
ret i32 %73
}

LLVM IR (-O2):
@rle_token.file = internal unnamed_addr global i32* null
@rle_token.buff = internal global [100 x i8] zeroinitializer
@rle_token.i = internal unnamed_addr global i32 0
@.str = [5 x i8] c" \0A\09\0D\00"
@.str.1 = [11 x i8] c"0123456789\00"
define i32 @rle_token(i32* %0, i8* nocapture writeonly %1) {
%3 = icmp eq i32* %0, null
br i1 %3, label %5, label %4
4: ; preds = %2
store i32* %0, i32** @rle_token.file
store i8 0, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0)
br label %10
5: ; preds = %2
%6 = load i32*, i32** @rle_token.file
%7 = icmp eq i32* %6, null
br i1 %7, label %41, label %8
8: ; preds = %5
%9 = load i32, i32* @rle_token.i
br label %10
10: ; preds = %8, %4
%11 = phi i32* [ %6, %8 ], [ %0, %4 ]
%12 = phi i32 [ %9, %8 ], [ 0, %4 ]
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %13
%15 = tail call i64 @strspn(i8* %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%16 = trunc i64 %15 to i32
%17 = add i32 %12, %16
store i32 %17, i32* @rle_token.i
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %18
%20 = load i8, i8* %19
switch i8 %20, label %27 [
i8 0, label %21
i8 33, label %41
]
21: ; preds = %10
store i32 0, i32* @rle_token.i
%22 = tail call i32* @fgets(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 0), i32 100, i32* %11)
%23 = icmp eq i32* %22, null
br i1 %23, label %41, label %24
24: ; preds = %21
%25 = load i32, i32* @rle_token.i
%26 = sext i32 %25 to i64
br label %27
27: ; preds = %24, %10
%28 = phi i64 [ %26, %24 ], [ %18, %10 ]
%29 = phi i32 [ %25, %24 ], [ %17, %10 ]
%30 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %28
%31 = tail call i32 @atoi(i8* %30)
%32 = tail call i64 @strspn(i8* %30, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%33 = trunc i64 %32 to i32
%34 = add i32 %29, %33
%35 = add nsw i32 %34, 1
store i32 %35, i32* @rle_token.i
%36 = sext i32 %34 to i64
%37 = getelementptr inbounds [100 x i8], [100 x i8]* @rle_token.buff, i64 0, i64 %36
%38 = load i8, i8* %37
store i8 %38, i8* %1
%39 = icmp eq i32 %31, 0
%40 = select i1 %39, i32 1, i32 %31
br label %41
41: ; preds = %10, %21, %5, %27
%42 = phi i32 [ %40, %27 ], [ -1, %5 ], [ -1, %21 ], [ 0, %10 ]
ret i32 %42
}