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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ is_register(char *);
scalar_t__ isdigit(char);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
char *strtok(char *, char *);
void check_registers(FILE *input) {
  char buffer[(1024)];
  char *token;
  char delimiters[] = "\t\n ,";
  uint16_t line = 0;
  while (fgets(buffer, sizeof buffer, input)) {
    line += 1;
    token = strtok(buffer, delimiters);
    while (token != NULL) {
      if (token[0] == 'r' && isdigit(token[1])) {
        if (!is_register(token)) {
          printf("[!] Compile error (line %u): "
                 "Invalid register \"%s\".\n",
                 line, token);
          exit(EXIT_FAILURE);
        }
      }
      token = strtok(NULL, delimiters);
    }
  }
  rewind(input);
}


x86 assembly (clang, -O0):
<check_registers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xe7b(%rip),%eax
mov    %eax,-0x41d(%rbp)
mov    0xe73(%rip),%al
mov    %al,-0x419(%rbp)
movl   $0x0,-0x424(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     1286 <check_registers+0x116>
mov    -0x424(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x424(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0x41d(%rbp),%rsi
call   1080 <strtok@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
je     1281 <check_registers+0x111>
mov    -0x418(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x72,%eax
jne    1265 <check_registers+0xf5>
mov    -0x418(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1030 <isdigit@plt>
cmp    $0x0,%rax
je     1265 <check_registers+0xf5>
mov    -0x418(%rbp),%rdi
call   1040 <is_register@plt>
cmp    $0x0,%eax
jne    1260 <check_registers+0xf0>
mov    -0x424(%rbp),%esi
mov    -0x418(%rbp),%rdx
lea    0xdb8(%rip),%rdi
call   1050 <printf@plt>
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1265 <check_registers+0xf5>
lea    -0x41d(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1080 <strtok@plt>
mov    %rax,-0x418(%rbp)
jmp    11e9 <check_registers+0x79>
jmp    11a1 <check_registers+0x31>
mov    -0x8(%rbp),%rdi
call   1060 <rewind@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_registers>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x410,%rsp
mov    %rdi,%r14
movb   $0x0,0xc(%rsp)
movl   $0x2c200a09,0x8(%rsp)
2c
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1241 <check_registers+0xd1>
xor    %r12d,%r12d
lea    0x10(%rsp),%r15
lea    0x8(%rsp),%r13
jmp    11d5 <check_registers+0x65>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     1241 <check_registers+0xd1>
add    $0x1,%r12d
mov    %r15,%rdi
mov    %r13,%rsi
call   1080 <strtok@plt>
test   %rax,%rax
je     11c0 <check_registers+0x50>
mov    %rax,%rbx
jmp    1202 <check_registers+0x92>
xchg   %ax,%ax
xor    %edi,%edi
mov    %r13,%rsi
call   1080 <strtok@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c0 <check_registers+0x50>
cmpb   $0x72,(%rbx)
jne    11f0 <check_registers+0x80>
movsbl 0x1(%rbx),%edi
call   1030 <isdigit@plt>
test   %rax,%rax
je     11f0 <check_registers+0x80>
mov    %rbx,%rdi
call   1040 <is_register@plt>
test   %eax,%eax
jne    11f0 <check_registers+0x80>
lea    0xddd(%rip),%rdi
mov    %r12d,%esi
mov    %rbx,%rdx
call   1050 <printf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %r14,%rdi
call   1060 <rewind@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.check_registers.delimiters = [5 x i8] c"\09\0A ,\00"
@.str = [53 x i8] c"[!] Compile error (line %u): Invalid register \22%s\22.\0A\00"
@EXIT_FAILURE = global i32 0
define void @check_registers(i32* %0) {
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca i8*
%5 = alloca [5 x i8]
%6 = alloca i32
store i32* %0, i32** %2
%7 = bitcast [5 x i8]* %5 to i8*
store i32 0, i32* %6
br label %8
8: ; preds = %48, %1
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%10 = load i32*, i32** %2
%11 = call i64 @fgets(i8* %9, i32 1024, i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %49
13: ; preds = %8
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 1
store i32 %15, i32* %6
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%18 = call i8* @strtok(i8* %16, i8* %17)
store i8* %18, i8** %4
br label %19
19: ; preds = %45, %13
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %48
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 114
br i1 %27, label %28, label %45
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = getelementptr inbounds i8, i8* %29, i64 1
%31 = load i8, i8* %30
%32 = call i64 @isdigit(i8 signext %31)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %45
34: ; preds = %28
%35 = load i8*, i8** %4
%36 = call i32 @is_register(i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %44, label %38
38: ; preds = %34
%39 = load i32, i32* %6
%40 = load i8*, i8** %4
%41 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %39, i8* %40)
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %34
br label %45
45: ; preds = %44, %28, %22
%46 = getelementptr inbounds [5 x i8], [5 x i8]* %5, i64 0, i64 0
%47 = call i8* @strtok(i8* null, i8* %46)
store i8* %47, i8** %4
br label %19
48: ; preds = %19
br label %8
49: ; preds = %8
%50 = load i32*, i32** %2
%51 = call i32 @rewind(i32* %50)
ret void
}

LLVM IR (-O2):
@__const.check_registers.delimiters = [5 x i8] c"\09\0A ,\00"
@.str = [53 x i8] c"[!] Compile error (line %u): Invalid register \22%s\22.\0A\00"
@EXIT_FAILURE = global i32 0
define void @check_registers(i32* nocapture %0) {
%2 = alloca [1024 x i8]
%3 = alloca [5 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%6 = call i64 @fgets(i8* %4, i32 1024, i32* %0)
%7 = icmp eq i64 %6, 0
br i1 %7, label %35, label %11
8: ; preds = %32, %11
%9 = call i64 @fgets(i8* %4, i32 1024, i32* %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %35, label %11
11: ; preds = %1, %8
%12 = phi i32 [ %13, %8 ], [ 0, %1 ]
%13 = add nuw nsw i32 %12, 1
%14 = call i8* @strtok(i8* %4, i8* %5)
%15 = icmp eq i8* %14, null
br i1 %15, label %8, label %16
16: ; preds = %11, %32
%17 = phi i8* [ %33, %32 ], [ %14, %11 ]
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 114
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = load i8, i8* %21
%23 = call i64 @isdigit(i8 signext %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %20
%26 = call i32 @is_register(i8* %17)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %25
%29 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %13, i8* %17)
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %25, %20, %16
%33 = call i8* @strtok(i8* null, i8* %5)
%34 = icmp eq i8* %33, null
br i1 %34, label %8, label %16
35: ; preds = %8, %1
%36 = call i32 @rewind(i32* %0)
ret void
}