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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
int /*<<< orphan*/ isdigit(char const);
int klogctl(int, char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putchar(char);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  char *buf = NULL;
  const char *p;
  int c;
  int bufsz = 0;
  int cmd = 3;
  int len = 0;
  int opt;
  int newline;
  while ((opt = getopt(argc, argv, "c")) != -1) {
    switch (opt) {
    case 'c':
      cmd = 4;
      break;
    case '?':
    default:
      usage(argv[0]);
      exit(1);
    }
  }
  if (!bufsz) {
    len = klogctl(10, NULL, 0);
    if (len > 0)
      bufsz = len;
  }
  if (bufsz) {
    int sz = bufsz + 8;
    buf = (char *)malloc(sz);
    len = klogctl(cmd, buf, sz);
  }
  if (len < 0) {
    perror("klogctl");
    exit(1);
  }
  newline = 1;
  p = buf;
  while ((c = *p)) {
    switch (c) {
    case '\n':
      newline = 1;
      putchar(c);
      p++;
      break;
    case '<':
      if (newline && isdigit(p[1]) && p[2] == '>') {
        p += 3;
        break;
      }
    default:
      newline = 0;
      putchar(c);
      p++;
    }
  }
  if (!newline)
    putchar('\n');
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x3,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe3f(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x34(%rbp)
cmp    $0xffffffff,%eax
je     1223 <main+0xa3>
mov    -0x34(%rbp),%eax
mov    %eax,-0x40(%rbp)
sub    $0x3f,%eax
je     1203 <main+0x83>
jmp    11e6 <main+0x66>
mov    -0x40(%rbp),%eax
sub    $0x63,%eax
jne    1208 <main+0x88>
jmp    11f7 <main+0x77>
movl   $0x4,-0x2c(%rbp)
jmp    121e <main+0x9e>
jmp    1208 <main+0x88>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    11b3 <main+0x33>
cmpl   $0x0,-0x28(%rbp)
jne    1255 <main+0xd5>
mov    $0xa,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <klogctl@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jle    1250 <main+0xd0>
mov    -0x30(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1255 <main+0xd5>
cmpl   $0x0,-0x28(%rbp)
je     1286 <main+0x106>
mov    -0x28(%rbp),%eax
add    $0x8,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x3c(%rbp),%edx
call   1060 <klogctl@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    12a6 <main+0x126>
lea    0xd6b(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x1,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
je     137a <main+0x1fa>
mov    -0x24(%rbp),%eax
mov    %eax,-0x44(%rbp)
sub    $0xa,%eax
je     12ed <main+0x16d>
jmp    12dc <main+0x15c>
mov    -0x44(%rbp),%eax
sub    $0x3c,%eax
je     1310 <main+0x190>
jmp    1357 <main+0x1d7>
movl   $0x1,-0x38(%rbp)
mov    -0x24(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1375 <main+0x1f5>
cmpl   $0x0,-0x38(%rbp)
je     1352 <main+0x1d2>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%edi
call   1040 <isdigit@plt>
cmp    $0x0,%eax
je     1352 <main+0x1d2>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x3e,%eax
jne    1352 <main+0x1d2>
mov    -0x20(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x20(%rbp)
jmp    1375 <main+0x1f5>
jmp    1357 <main+0x1d7>
movl   $0x0,-0x38(%rbp)
mov    -0x24(%rbp),%eax
movsbl %al,%edi
call   1030 <putchar@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    12b5 <main+0x135>
cmpl   $0x0,-0x38(%rbp)
jne    138e <main+0x20e>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%ebx
mov    $0x3,%ecx
lea    0xe68(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %ecx,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15,%rdx
call   1090 <getopt@plt>
mov    $0x4,%ecx
cmp    $0x63,%eax
je     11a0 <main+0x20>
cmp    $0xffffffff,%eax
jne    1287 <main+0x107>
xor    %r15d,%r15d
mov    $0xa,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <klogctl@plt>
mov    %eax,%r14d
test   %eax,%eax
jle    11f9 <main+0x79>
add    $0x8,%r14d
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %ebp,%edi
mov    %rax,%rsi
mov    %r14d,%edx
call   1060 <klogctl@plt>
mov    %eax,%r14d
test   %r14d,%r14d
js     1299 <main+0x119>
mov    (%r15),%cl
test   %cl,%cl
je     127a <main+0xfa>
mov    $0x1,%eax
xchg   %ax,%ax
movsbl %cl,%ebp
mov    $0x1,%ebx
cmp    $0xa,%ebp
je     1252 <main+0xd2>
cmp    $0x3c,%ebp
jne    1250 <main+0xd0>
test   %eax,%eax
je     1250 <main+0xd0>
movsbl 0x1(%r15),%edi
call   1040 <isdigit@plt>
test   %eax,%eax
je     1250 <main+0xd0>
cmpb   $0x3e,0x2(%r15)
jne    1250 <main+0xd0>
mov    $0x1,%eax
mov    $0x3,%edx
jmp    1260 <main+0xe0>
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
mov    %ebp,%edi
call   1030 <putchar@plt>
mov    $0x1,%edx
mov    %ebx,%eax
movzbl (%r15,%rdx,1),%ecx
add    %rdx,%r15
test   %cl,%cl
jne    1210 <main+0x90>
test   %eax,%eax
jne    127a <main+0xfa>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rdi
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xd62(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"c\00"
@.str.1 = [8 x i8] c"klogctl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %9
store i32 3, i32* %10
store i32 0, i32* %11
br label %15
15: ; preds = %30, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %12
%19 = icmp ne i32 %18, -1
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i32, i32* %12
switch i32 %21, label %24 [
i32 99, label %22
i32 63, label %23
]
22: ; preds = %20
store i32 4, i32* %10
br label %30
23: ; preds = %20
br label %24
24: ; preds = %20, %23
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 @usage(i8* %27)
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %22
br label %15
31: ; preds = %15
%32 = load i32, i32* %9
%33 = icmp ne i32 %32, 0
br i1 %33, label %41, label %34
34: ; preds = %31
%35 = call i32 @klogctl(i32 10, i8* null, i32 0)
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = load i32, i32* %11
store i32 %39, i32* %9
br label %40
40: ; preds = %38, %34
br label %41
41: ; preds = %40, %31
%42 = load i32, i32* %9
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %54
44: ; preds = %41
%45 = load i32, i32* %9
%46 = add nsw i32 %45, 8
store i32 %46, i32* %14
%47 = load i32, i32* %14
%48 = call i64 @malloc(i32 %47)
%49 = inttoptr i64 %48 to i8*
store i8* %49, i8** %6
%50 = load i32, i32* %10
%51 = load i8*, i8** %6
%52 = load i32, i32* %14
%53 = call i32 @klogctl(i32 %50, i8* %51, i32 %52)
store i32 %53, i32* %11
br label %54
54: ; preds = %44, %41
%55 = load i32, i32* %11
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %54
store i32 1, i32* %13
%61 = load i8*, i8** %6
store i8* %61, i8** %7
br label %62
62: ; preds = %100, %60
%63 = load i8*, i8** %7
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
store i32 %65, i32* %8
%66 = icmp ne i32 %65, 0
br i1 %66, label %67, label %101
67: ; preds = %62
%68 = load i32, i32* %8
switch i32 %68, label %94 [
i32 10, label %69
i32 60, label %75
]
69: ; preds = %67
store i32 1, i32* %13
%70 = load i32, i32* %8
%71 = trunc i32 %70 to i8
%72 = call i32 @putchar(i8 signext %71)
%73 = load i8*, i8** %7
%74 = getelementptr inbounds i8, i8* %73, i32 1
store i8* %74, i8** %7
br label %100
75: ; preds = %67
%76 = load i32, i32* %13
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %93
78: ; preds = %75
%79 = load i8*, i8** %7
%80 = getelementptr inbounds i8, i8* %79, i64 1
%81 = load i8, i8* %80
%82 = call i32 @isdigit(i8 signext %81)
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %93
84: ; preds = %78
%85 = load i8*, i8** %7
%86 = getelementptr inbounds i8, i8* %85, i64 2
%87 = load i8, i8* %86
%88 = sext i8 %87 to i32
%89 = icmp eq i32 %88, 62
br i1 %89, label %90, label %93
90: ; preds = %84
%91 = load i8*, i8** %7
%92 = getelementptr inbounds i8, i8* %91, i64 3
store i8* %92, i8** %7
br label %100
93: ; preds = %84, %78, %75
br label %94
94: ; preds = %67, %93
store i32 0, i32* %13
%95 = load i32, i32* %8
%96 = trunc i32 %95 to i8
%97 = call i32 @putchar(i8 signext %96)
%98 = load i8*, i8** %7
%99 = getelementptr inbounds i8, i8* %98, i32 1
store i8* %99, i8** %7
br label %100
100: ; preds = %94, %90, %69
br label %62
101: ; preds = %62
%102 = load i32, i32* %13
%103 = icmp ne i32 %102, 0
br i1 %103, label %106, label %104
104: ; preds = %101
%105 = call i32 @putchar(i8 signext 10)
br label %106
106: ; preds = %104, %101
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"c\00"
@.str.1 = [8 x i8] c"klogctl\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 3, %2 ], [ 4, %3 ]
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
switch i32 %5, label %6 [
i32 -1, label %10
i32 99, label %3
]
6: ; preds = %3
%7 = load i8*, i8** %1
%8 = tail call i32 @usage(i8* %7)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = tail call i32 @klogctl(i32 10, i8* null, i32 0)
%12 = icmp slt i32 %11, 1
br i1 %12, label %18, label %13
13: ; preds = %10
%14 = add nuw nsw i32 %11, 8
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @klogctl(i32 %4, i8* %16, i32 %14)
br label %18
18: ; preds = %13, %10
%19 = phi i32 [ %17, %13 ], [ %11, %10 ]
%20 = phi i8* [ %16, %13 ], [ null, %10 ]
%21 = icmp slt i32 %19, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = load i8, i8* %20
%24 = icmp eq i8 %23, 0
br i1 %24, label %58, label %28
25: ; preds = %18
%26 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %22, %48
%29 = phi i8 [ %52, %48 ], [ %23, %22 ]
%30 = phi i32 [ %50, %48 ], [ 1, %22 ]
%31 = phi i8* [ %51, %48 ], [ %20, %22 ]
%32 = sext i8 %29 to i32
switch i32 %32, label %44 [
i32 10, label %45
i32 60, label %33
]
33: ; preds = %28
%34 = icmp eq i32 %30, 0
br i1 %34, label %44, label %35
35: ; preds = %33
%36 = getelementptr inbounds i8, i8* %31, i64 1
%37 = load i8, i8* %36
%38 = tail call i32 @isdigit(i8 signext %37)
%39 = icmp eq i32 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %35
%41 = getelementptr inbounds i8, i8* %31, i64 2
%42 = load i8, i8* %41
%43 = icmp eq i8 %42, 62
br i1 %43, label %48, label %44
44: ; preds = %33, %35, %40, %28
br label %45
45: ; preds = %28, %44
%46 = phi i32 [ 0, %44 ], [ 1, %28 ]
%47 = tail call i32 @putchar(i8 signext %29)
br label %48
48: ; preds = %45, %40
%49 = phi i64 [ 3, %40 ], [ 1, %45 ]
%50 = phi i32 [ 1, %40 ], [ %46, %45 ]
%51 = getelementptr inbounds i8, i8* %31, i64 %49
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
br i1 %53, label %54, label %28
54: ; preds = %48
%55 = icmp eq i32 %50, 0
br i1 %55, label %56, label %58
56: ; preds = %54
%57 = tail call i32 @putchar(i8 signext 10)
br label %58
58: ; preds = %22, %56, %54
ret i32 0
}