#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 /*<<< orphan*/ dni_get_mtdoops_info(char *);
int dni_read_mtdoops_data(char *, char *, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char **argv) {
  char buf[64 * 1024];
  FILE *fp;
  int i = 0, count = 0;
  char *oops_mtd;
  if (argc < 2) {
    printf("lack of param, exit..\n");
    return 1;
  }
  oops_mtd = argv[1];
  memset(buf, 0x20, 64 * 1024);
  dni_get_mtdoops_info(oops_mtd);
  count = dni_read_mtdoops_data(oops_mtd, buf, 64 * 1024);
  if (count == 0) {
    strcpy(buf, "Good, No kernel panic found so far...");
    count = strlen("Good, No kernel panic found so far...");
  }
  if ((fp = fopen("/tmp/Panic-log.txt", "w")) == NULL) {
    printf("Open error!\n");
    return -1;
  }
  do {
    if (buf[i + 0] == '<' && buf[i + 1] >= '0' && buf[i + 1] <= '7' &&
        buf[i + 2] == '>') {
      i += 3;
      continue;
    }
    fputc(buf[i++], fp);
  } while (i < count);
  for (i = 0; i < 4096; i++)
    printf("%c", buf[i]);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1001c(%rbp)
movl   $0x0,-0x10020(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11e1 <main+0x51>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13c2 <main+0x232>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x10028(%rbp)
lea    -0x10010(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10000,%edx
call   1080 <memset@plt>
mov    -0x10028(%rbp),%rdi
call   10a0 <dni_get_mtdoops_info@plt>
mov    -0x10028(%rbp),%rdi
lea    -0x10010(%rbp),%rsi
mov    $0x10000,%edx
call   1030 <dni_read_mtdoops_data@plt>
mov    %eax,-0x10020(%rbp)
cmpl   $0x0,-0x10020(%rbp)
jne    1262 <main+0xd2>
lea    -0x10010(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   1040 <strcpy@plt>
lea    0xdc0(%rip),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x10020(%rbp)
lea    0xdd4(%rip),%rdi
lea    0xde0(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x10018(%rbp)
cmp    $0x0,%rax
jne    12a0 <main+0x110>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13c2 <main+0x232>
jmp    12a5 <main+0x115>
mov    -0x1001c(%rbp),%eax
add    $0x0,%eax
cltq
movsbl -0x10010(%rbp,%rax,1),%eax
ff
cmp    $0x3c,%eax
jne    1329 <main+0x199>
mov    -0x1001c(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x10010(%rbp,%rax,1),%eax
ff
cmp    $0x30,%eax
jl     1329 <main+0x199>
mov    -0x1001c(%rbp),%eax
add    $0x1,%eax
cltq
movsbl -0x10010(%rbp,%rax,1),%eax
ff
cmp    $0x37,%eax
jg     1329 <main+0x199>
mov    -0x1001c(%rbp),%eax
add    $0x2,%eax
cltq
movsbl -0x10010(%rbp,%rax,1),%eax
ff
cmp    $0x3e,%eax
jne    1329 <main+0x199>
mov    -0x1001c(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x1001c(%rbp)
jmp    1352 <main+0x1c2>
mov    -0x1001c(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x1001c(%rbp)
cltq
mov    -0x10010(%rbp,%rax,1),%al
mov    -0x10018(%rbp),%rsi
movsbl %al,%edi
call   1090 <fputc@plt>
mov    -0x1001c(%rbp),%eax
cmp    -0x10020(%rbp),%eax
jl     12a5 <main+0x115>
movl   $0x0,-0x1001c(%rbp)
cmpl   $0x1000,-0x1001c(%rbp)
jge    13af <main+0x21f>
movslq -0x1001c(%rbp),%rax
movsbl -0x10010(%rbp,%rax,1),%esi
ff
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x1001c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1001c(%rbp)
jmp    136e <main+0x1de>
mov    -0x10018(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10000,%rsp
cmp    $0x1,%edi
jg     11ca <main+0x2a>
lea    0xe8c(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%eax
jmp    12b3 <main+0x113>
mov    0x8(%rsi),%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x20,%esi
mov    $0x10000,%edx
call   1090 <memset@plt>
mov    %rbx,%rdi
call   10b0 <dni_get_mtdoops_info@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x10000,%edx
call   1030 <dni_read_mtdoops_data@plt>
mov    %eax,%r12d
test   %eax,%eax
jne    121f <main+0x7f>
lea    0xdf7(%rip),%rbx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <strcpy@plt>
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %eax,%r12d
lea    0xe00(%rip),%rdi
lea    0xe0c(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12a2 <main+0x102>
mov    %rax,%r15
xor    %eax,%eax
jmp    1252 <main+0xb2>
xchg   %ax,%ax
movsbl %cl,%edi
mov    %r15,%rsi
call   10a0 <fputc@plt>
mov    %ebp,%eax
cmp    %r12d,%ebp
jge    127d <main+0xdd>
movslq %eax,%rdx
movzbl (%rsp,%rdx,1),%ecx
lea    0x1(%rdx),%rbp
cmp    $0x3c,%cl
jne    1240 <main+0xa0>
movzbl (%rsp,%rbp,1),%ebx
and    $0xf8,%bl
cmp    $0x30,%bl
jne    1240 <main+0xa0>
cmpb   $0x3e,0x2(%rdx,%r14,1)
jne    1240 <main+0xa0>
add    $0x3,%eax
mov    %eax,%ebp
jmp    124b <main+0xab>
xor    %ebx,%ebx
nop
movsbl (%rsp,%rbx,1),%edi
call   1040 <putchar@plt>
add    $0x1,%rbx
cmp    $0x1000,%rbx
jne    1280 <main+0xe0>
mov    %r15,%rdi
call   1070 <fclose@plt>
xor    %eax,%eax
jmp    12b3 <main+0x113>
lea    0xd92(%rip),%rdi
call   1060 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"lack of param, exit..\0A\00"
@.str.1 = [38 x i8] c"Good, No kernel panic found so far...\00"
@.str.2 = [19 x i8] c"/tmp/Panic-log.txt\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [13 x i8] c"Open error!\0A\00"
@.str.5 = [3 x i8] c"%c\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [65536 x i8]
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %102
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
store i8* %18, i8** %10
%19 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%20 = call i32 @memset(i8* %19, i32 32, i32 65536)
%21 = load i8*, i8** %10
%22 = call i32 @dni_get_mtdoops_info(i8* %21)
%23 = load i8*, i8** %10
%24 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%25 = call i32 @dni_read_mtdoops_data(i8* %23, i8* %24, i32 65536)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %15
%29 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @strlen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
store i32 %31, i32* %9
br label %32
32: ; preds = %28, %15
%33 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %33, i32** %7
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %32
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %102
37: ; preds = %32
br label %38
38: ; preds = %81, %37
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 0
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 60
br i1 %45, label %46, label %73
46: ; preds = %38
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp sge i32 %52, 48
br i1 %53, label %54, label %73
54: ; preds = %46
%55 = load i32, i32* %8
%56 = add nsw i32 %55, 1
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %57
%59 = load i8, i8* %58
%60 = sext i8 %59 to i32
%61 = icmp sle i32 %60, 55
br i1 %61, label %62, label %73
62: ; preds = %54
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %65
%67 = load i8, i8* %66
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 62
br i1 %69, label %70, label %73
70: ; preds = %62
%71 = load i32, i32* %8
%72 = add nsw i32 %71, 3
store i32 %72, i32* %8
br label %81
73: ; preds = %62, %54, %46, %38
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
store i32 %75, i32* %8
%76 = sext i32 %74 to i64
%77 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %76
%78 = load i8, i8* %77
%79 = load i32*, i32** %7
%80 = call i32 @fputc(i8 signext %78, i32* %79)
br label %81
81: ; preds = %73, %70
%82 = load i32, i32* %8
%83 = load i32, i32* %9
%84 = icmp slt i32 %82, %83
br i1 %84, label %38, label %85
85: ; preds = %81
store i32 0, i32* %8
br label %86
86: ; preds = %96, %85
%87 = load i32, i32* %8
%88 = icmp slt i32 %87, 4096
br i1 %88, label %89, label %99
89: ; preds = %86
%90 = load i32, i32* %8
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 %91
%93 = load i8, i8* %92
%94 = sext i8 %93 to i32
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %94)
br label %96
96: ; preds = %89
%97 = load i32, i32* %8
%98 = add nsw i32 %97, 1
store i32 %98, i32* %8
br label %86
99: ; preds = %86
%100 = load i32*, i32** %7
%101 = call i32 @fclose(i32* %100)
store i32 0, i32* %3
br label %102
102: ; preds = %99, %35, %13
%103 = load i32, i32* %3
ret i32 %103
}

LLVM IR (-O2):
@.str.1 = [38 x i8] c"Good, No kernel panic found so far...\00"
@.str.2 = [19 x i8] c"/tmp/Panic-log.txt\00"
@.str.3 = [2 x i8] c"w\00"
@str = [12 x i8] c"Open error!\00"
@str.6 = [22 x i8] c"lack of param, exit..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [65536 x i8]
%4 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.6, i64 0, i64 0))
br label %60
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = call i32 @memset(i8* %4, i32 32, i32 65536)
%12 = call i32 @dni_get_mtdoops_info(i8* %10)
%13 = call i32 @dni_read_mtdoops_data(i8* %10, i8* %4, i32 65536)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %8
%16 = call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @strlen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %15, %8
%19 = phi i32 [ %17, %15 ], [ %13, %8 ]
%20 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %60
24: ; preds = %18, %47
%25 = phi i32 [ %48, %47 ], [ 0, %18 ]
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = icmp eq i8 %28, 60
%30 = add nsw i32 %25, 1
br i1 %29, label %31, label %45
31: ; preds = %24
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = and i8 %34, -8
%36 = icmp eq i8 %35, 48
br i1 %36, label %37, label %45
37: ; preds = %31
%38 = add nsw i32 %25, 2
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %39
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 62
br i1 %42, label %43, label %45
43: ; preds = %37
%44 = add nsw i32 %25, 3
br label %47
45: ; preds = %24, %37, %31
%46 = call i32 @fputc(i8 signext %28, i32* %20)
br label %47
47: ; preds = %45, %43
%48 = phi i32 [ %44, %43 ], [ %30, %45 ]
%49 = icmp slt i32 %48, %19
br i1 %49, label %24, label %50
50: ; preds = %47, %50
%51 = phi i64 [ %56, %50 ], [ 0, %47 ]
%52 = getelementptr inbounds [65536 x i8], [65536 x i8]* %3, i64 0, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = call i32 @putchar(i32 %54)
%56 = add nuw nsw i64 %51, 1
%57 = icmp eq i64 %56, 4096
br i1 %57, label %58, label %50
58: ; preds = %50
%59 = call i32 @fclose(i32* %20)
br label %60
60: ; preds = %58, %22, %6
%61 = phi i32 [ 1, %6 ], [ -1, %22 ], [ 0, %58 ]
ret i32 %61
}