#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*/ buff;

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strstr(char *, char *);
int strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  char buff[1023];
  int len;
  int reg_num;
  int core = 0;
  while (fgets(buff, sizeof(buff), stdin) != NULL) {
    len = strlen(buff);
    if (buff[len - 1] == '\n') {
      len--;
      buff[len] = '\0';
    }
    if ((strncmp(buff, "Reg ", 4) == 0) && (strstr(buff, "<-") == (char *)0)) {
      buff[6] = '\0';
      reg_num = atoi(buff + 4);
      printf("DEBUG MIPS REG %2d 0x%s\n", reg_num, buff + 7);
    } else if ((strncmp(buff, "PC ", 3) == 0) && (core == 0)) {
      printf("DEBUG MIPS PC 0x%s\n", buff + 7);
    } else if (strncmp(buff, "Core = ", 7) == 0) {
      core = strtol(buff + 7, NULL, 0);
      printf("DEBUG MIPS COREID %d\n", core);
    } else if (strncmp(buff, "DEBUG CAP", 9) == 0) {
      printf("%s\n", buff);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x41c(%rbp)
lea    -0x410(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
mov    $0x3ff,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1372 <main+0x202>
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x414(%rbp)
mov    -0x414(%rbp),%eax
sub    $0x1,%eax
cltq
movsbl -0x410(%rbp,%rax,1),%eax
ff
cmp    $0xa,%eax
jne    1203 <main+0x93>
mov    -0x414(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x414(%rbp)
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rdi
lea    0xdef(%rip),%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1283 <main+0x113>
lea    -0x410(%rbp),%rdi
lea    0xdd2(%rip),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%rax
jne    1283 <main+0x113>
movb   $0x0,-0x40a(%rbp)
lea    -0x410(%rbp),%rdi
add    $0x4,%rdi
call   1080 <atoi@plt>
mov    %eax,-0x418(%rbp)
mov    -0x418(%rbp),%esi
lea    -0x410(%rbp),%rdx
add    $0x7,%rdx
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    136d <main+0x1fd>
lea    -0x410(%rbp),%rdi
lea    0xd90(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12d0 <main+0x160>
cmpl   $0x0,-0x41c(%rbp)
jne    12d0 <main+0x160>
lea    -0x410(%rbp),%rsi
add    $0x7,%rsi
lea    0xd61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1368 <main+0x1f8>
lea    -0x410(%rbp),%rdi
lea    0xd5b(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1327 <main+0x1b7>
lea    -0x410(%rbp),%rdi
add    $0x7,%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %eax,-0x41c(%rbp)
mov    -0x41c(%rbp),%esi
lea    0xd26(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1363 <main+0x1f3>
lea    -0x410(%rbp),%rdi
lea    0xd22(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    135e <main+0x1ee>
lea    -0x410(%rbp),%rsi
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1363 <main+0x1f3>
jmp    1368 <main+0x1f8>
jmp    136d <main+0x1fd>
jmp    1193 <main+0x23>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    0x2e50(%rip),%r13
mov    0x0(%r13),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     12ea <main+0x16a>
lea    0x7(%rsp),%r14
lea    0xe3f(%rip),%r12
lea    0xe59(%rip),%r15
xor    %ebp,%ebp
jmp    11fd <main+0x7d>
nopl   0x0(%rax)
xor    %ebp,%ebp
lea    0xe4c(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x3ff,%esi
call   1070 <fgets@plt>
test   %rax,%rax
je     12ea <main+0x16a>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0xa,-0x1(%rax,%rbx,1)
jne    1213 <main+0x93>
movb   $0x0,-0x1(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1240 <main+0xc0>
mov    %rbx,%rdi
lea    0xdd3(%rip),%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     12c3 <main+0x143>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    125d <main+0xdd>
test   %ebp,%ebp
je     11d0 <main+0x50>
mov    %rbx,%rdi
lea    0xdd2(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     12a0 <main+0x120>
mov    %rbx,%rdi
lea    0xdd7(%rip),%rsi
mov    $0x9,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11e3 <main+0x63>
mov    %rbx,%rdi
call   1040 <puts@plt>
jmp    11e3 <main+0x63>
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <strtol@plt>
mov    %eax,%ebp
lea    0xd8c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11e3 <main+0x63>
movb   $0x0,0x6(%rsp)
lea    0x4(%rsp),%rdi
call   1090 <atoi@plt>
lea    0xd2f(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
jmp    11e3 <main+0x63>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [5 x i8] c"Reg \00"
@.str.1 = [3 x i8] c"<-\00"
@.str.2 = [25 x i8] c"DEBUG MIPS REG %2d 0x%s\0A\00"
@.str.3 = [4 x i8] c"PC \00"
@.str.4 = [20 x i8] c"DEBUG MIPS PC 0x%s\0A\00"
@.str.5 = [8 x i8] c"Core = \00"
@.str.6 = [22 x i8] c"DEBUG MIPS COREID %d\0A\00"
@.str.7 = [10 x i8] c"DEBUG CAP\00"
@.str.8 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1023 x i8]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
br label %10
10: ; preds = %79, %2
%11 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i32* @fgets(i8* %11, i32 1023, i32 %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %80
15: ; preds = %10
%16 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 %20
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 10
br i1 %24, label %25, label %31
25: ; preds = %15
%26 = load i32, i32* %7
%27 = add nsw i32 %26, -1
store i32 %27, i32* %7
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %25, %15
%32 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%33 = call i64 @strncmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %31
%36 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%37 = call i8* @strstr(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%38 = icmp eq i8* %37, null
br i1 %38, label %39, label %48
39: ; preds = %35
%40 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 6
store i8 0, i8* %40
%41 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%42 = getelementptr inbounds i8, i8* %41, i64 4
%43 = call i32 @atoi(i8* %42)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%46 = getelementptr inbounds i8, i8* %45, i64 7
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %44, i8* %46)
br label %79
48: ; preds = %35, %31
%49 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%50 = call i64 @strncmp(i8* %49, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %59
52: ; preds = %48
%53 = load i32, i32* %9
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%57 = getelementptr inbounds i8, i8* %56, i64 7
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %78
59: ; preds = %52, %48
%60 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%61 = call i64 @strncmp(i8* %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %69
63: ; preds = %59
%64 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%65 = getelementptr inbounds i8, i8* %64, i64 7
%66 = call i32 @strtol(i8* %65, i32* null, i32 0)
store i32 %66, i32* %9
%67 = load i32, i32* %9
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %67)
br label %77
69: ; preds = %59
%70 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%71 = call i64 @strncmp(i8* %70, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 9)
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %69
%74 = getelementptr inbounds [1023 x i8], [1023 x i8]* %6, i64 0, i64 0
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %73, %69
br label %77
77: ; preds = %76, %63
br label %78
78: ; preds = %77, %55
br label %79
79: ; preds = %78, %39
br label %10
80: ; preds = %10
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [5 x i8] c"Reg \00"
@.str.1 = [3 x i8] c"<-\00"
@.str.2 = [25 x i8] c"DEBUG MIPS REG %2d 0x%s\0A\00"
@.str.3 = [4 x i8] c"PC \00"
@.str.4 = [20 x i8] c"DEBUG MIPS PC 0x%s\0A\00"
@.str.5 = [8 x i8] c"Core = \00"
@.str.6 = [22 x i8] c"DEBUG MIPS COREID %d\0A\00"
@.str.7 = [10 x i8] c"DEBUG CAP\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1023 x i8]
%4 = getelementptr inbounds [1023 x i8], [1023 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @stdin
%6 = call i32* @fgets(i8* %4, i32 1023, i32 %5)
%7 = icmp eq i32* %6, null
br i1 %7, label %53, label %8
8: ; preds = %2
%9 = getelementptr inbounds [1023 x i8], [1023 x i8]* %3, i64 0, i64 7
%10 = getelementptr inbounds [1023 x i8], [1023 x i8]* %3, i64 0, i64 6
%11 = getelementptr inbounds [1023 x i8], [1023 x i8]* %3, i64 0, i64 4
br label %12
12: ; preds = %8, %48
%13 = phi i32 [ 0, %8 ], [ %49, %48 ]
%14 = call i32 @strlen(i8* %4)
%15 = add nsw i32 %14, -1
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [1023 x i8], [1023 x i8]* %3, i64 0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 10
br i1 %19, label %20, label %21
20: ; preds = %12
store i8 0, i8* %17
br label %21
21: ; preds = %20, %12
%22 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %30
27: ; preds = %24
store i8 0, i8* %10
%28 = call i32 @atoi(i8* %11)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %28, i8* %9)
br label %48
30: ; preds = %24, %21
%31 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 3)
%32 = icmp eq i64 %31, 0
%33 = icmp eq i32 %13, 0
%34 = select i1 %32, i1 %33, i1 false
br i1 %34, label %35, label %37
35: ; preds = %30
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %48
37: ; preds = %30
%38 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 7)
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %37
%41 = call i32 @strtol(i8* nocapture %9, i32* null, i32 0)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %41)
br label %48
43: ; preds = %37
%44 = call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i32 9)
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @puts(i8* %4)
br label %48
48: ; preds = %35, %43, %46, %40, %27
%49 = phi i32 [ %13, %27 ], [ 0, %35 ], [ %41, %40 ], [ %13, %46 ], [ %13, %43 ]
%50 = load i32, i32* @stdin
%51 = call i32* @fgets(i8* %4, i32 1023, i32 %50)
%52 = icmp eq i32* %51, null
br i1 %52, label %53, label %12
53: ; preds = %48, %2
ret i32 0
}