#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*/ assert(int);
char *calloc(int, int);
int /*<<< orphan*/ die(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getpid();
int klogctl(int, char *, int);
int /*<<< orphan*/ printf(char *, int, char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  int bytes_total;
  int bytes_read;
  char *buffer = NULL;
  int skip = 0;
  if (argc > 2) {
    usage();
    return 1;
  } else if (argc == 2) {
    if (!strcmp(argv[1], "--version")) {
      fprintf(stdout, "2010.12.15.1"
                      "\n");
      return 0;
    } else if (!strcmp(argv[1], "--help")) {
      usage();
      return 0;
    } else if (!strcmp(argv[1], "--live")) {
      skip = 1;
    } else {
      usage();
      return 1;
    }
  }
  bytes_total = klogctl(10, NULL, 0);
  if (bytes_total <= 0)
    die("SYSLOG_ACTION_SIZE_BUFFER returned %d\n", errno);
  assert(bytes_total >= 0);
  buffer = calloc(1, bytes_total + 1);
  if (!buffer)
    return 2;
  for (;;) {
    bytes_read = klogctl(2, buffer, bytes_total);
    if (bytes_read < 0)
      die("SYSLOG_ACTION_READ returned %d\n", errno);
    buffer[bytes_read] = '\0';
    printf("PID:%d## %s", getpid(), buffer);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11d2 <main+0x42>
mov    $0x0,%al
call   10a0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    136a <main+0x1da>
cmpl   $0x2,-0x8(%rbp)
jne    1295 <main+0x105>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe15(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    121a <main+0x8a>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdef(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    124a <main+0xba>
mov    $0x0,%al
call   10a0 <usage@plt>
movl   $0x0,-0x4(%rbp)
jmp    136a <main+0x1da>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdc6(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    1273 <main+0xe3>
movl   $0x1,-0x24(%rbp)
jmp    1286 <main+0xf6>
mov    $0x0,%al
call   10a0 <usage@plt>
movl   $0x1,-0x4(%rbp)
jmp    136a <main+0x1da>
jmp    128b <main+0xfb>
jmp    1290 <main+0x100>
jmp    1295 <main+0x105>
jmp    129a <main+0x10a>
mov    $0xa,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1090 <klogctl@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     12cc <main+0x13c>
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
lea    0xd5f(%rip),%rdi
call   10b0 <die@plt>
cmpl   $0x0,-0x14(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x14(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1308 <main+0x178>
movl   $0x2,-0x4(%rbp)
jmp    136a <main+0x1da>
jmp    130d <main+0x17d>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x2,%edi
call   1090 <klogctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1340 <main+0x1b0>
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
lea    0xd12(%rip),%rdi
call   10b0 <die@plt>
mov    -0x20(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
mov    -0x20(%rbp),%rdx
lea    0xd0d(%rip),%rdi
call   1040 <printf@plt>
jmp    130d <main+0x17d>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x3,%edi
jl     11bd <main+0x2d>
xor    %eax,%eax
call   10a0 <usage@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cmp    $0x2,%edi
jne    1207 <main+0x77>
mov    0x8(%rsi),%rbx
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12b9 <main+0x129>
lea    0xe34(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     12d5 <main+0x145>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
jne    11a0 <main+0x10>
mov    $0xa,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1090 <klogctl@plt>
mov    %eax,%r14d
test   %eax,%eax
jg     1231 <main+0xa1>
mov    0x2dbd(%rip),%rax
mov    (%rax),%esi
lea    0xdfa(%rip),%rdi
call   10b0 <die@plt>
mov    %r14d,%edi
not    %edi
shr    $0x1f,%edi
call   1070 <assert@plt>
lea    0x1(%r14),%esi
mov    $0x1,%edi
call   1050 <calloc@plt>
test   %rax,%rax
je     12af <main+0x11f>
mov    %rax,%rbx
mov    0x2d85(%rip),%r13
lea    0xdeb(%rip),%r15
lea    0xe04(%rip),%r12
jmp    128b <main+0xfb>
nopl   0x0(%rax,%rax,1)
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1040 <printf@plt>
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1090 <klogctl@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1270 <main+0xe0>
mov    0x0(%r13),%esi
mov    %r15,%rdi
call   10b0 <die@plt>
jmp    1270 <main+0xe0>
mov    $0x2,%ebx
jmp    11ac <main+0x1c>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd41(%rip),%rsi
call   1080 <fprintf@plt>
xor    %ebx,%ebx
jmp    11ac <main+0x1c>
xor    %ebx,%ebx
xor    %eax,%eax
call   10a0 <usage@plt>
jmp    11ac <main+0x1c>

LLVM IR (-O0):
@.str = [10 x i8] c"--version\00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"2010.12.15.1\0A\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [7 x i8] c"--live\00"
@.str.4 = [39 x i8] c"SYSLOG_ACTION_SIZE_BUFFER returned %d\0A\00"
@errno = global i32 0
@.str.5 = [32 x i8] c"SYSLOG_ACTION_READ returned %d\0A\00"
@.str.6 = [12 x i8] c"PID:%d## %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %8
store i32 0, i32* %9
%10 = load i32, i32* %4
%11 = icmp sgt i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (...) @usage()
store i32 1, i32* %3
br label %83
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %46
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @strcmp(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i32 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %17
%24 = load i32, i32* @stdout
%25 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %83
26: ; preds = %17
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @strcmp(i8* %29, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %26
%33 = call i32 (...) @usage()
store i32 0, i32* %3
br label %83
34: ; preds = %26
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %41, label %40
40: ; preds = %34
store i32 1, i32* %9
br label %43
41: ; preds = %34
%42 = call i32 (...) @usage()
store i32 1, i32* %3
br label %83
43: ; preds = %40
br label %44
44: ; preds = %43
br label %45
45: ; preds = %44
br label %46
46: ; preds = %45, %14
br label %47
47: ; preds = %46
%48 = call i32 @klogctl(i32 10, i8* null, i32 0)
store i32 %48, i32* %6
%49 = load i32, i32* %6
%50 = icmp sle i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %47
%52 = load i32, i32* @errno
%53 = call i32 @die(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %52)
br label %54
54: ; preds = %51, %47
%55 = load i32, i32* %6
%56 = icmp sge i32 %55, 0
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = load i32, i32* %6
%60 = add nsw i32 %59, 1
%61 = call i8* @calloc(i32 1, i32 %60)
store i8* %61, i8** %8
%62 = load i8*, i8** %8
%63 = icmp ne i8* %62, null
br i1 %63, label %65, label %64
64: ; preds = %54
store i32 2, i32* %3
br label %83
65: ; preds = %54
br label %66
66: ; preds = %75, %65
%67 = load i8*, i8** %8
%68 = load i32, i32* %6
%69 = call i32 @klogctl(i32 2, i8* %67, i32 %68)
store i32 %69, i32* %7
%70 = load i32, i32* %7
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %66
%73 = load i32, i32* @errno
%74 = call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %72, %66
%76 = load i8*, i8** %8
%77 = load i32, i32* %7
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
store i8 0, i8* %79
%80 = call i32 (...) @getpid()
%81 = load i8*, i8** %8
%82 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %80, i8* %81)
br label %66
83: ; preds = %64, %41, %32, %23, %12
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
@.str = [10 x i8] c"--version\00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"2010.12.15.1\0A\00"
@.str.2 = [7 x i8] c"--help\00"
@.str.3 = [7 x i8] c"--live\00"
@.str.4 = [39 x i8] c"SYSLOG_ACTION_SIZE_BUFFER returned %d\0A\00"
@errno = global i32 0
@.str.5 = [32 x i8] c"SYSLOG_ACTION_READ returned %d\0A\00"
@.str.6 = [12 x i8] c"PID:%d## %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 (...) @usage()
br label %50
6: ; preds = %2
%7 = icmp eq i32 %0, 2
br i1 %7, label %8, label %26
8: ; preds = %6
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(10) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i32, i32* @stdout
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %50
16: ; preds = %8
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 (...) @usage()
br label %50
21: ; preds = %16
%22 = tail call i32 @strcmp(i8* dereferenceable(1) %10, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %26, label %24
24: ; preds = %21
%25 = tail call i32 (...) @usage()
br label %50
26: ; preds = %21, %6
%27 = tail call i32 @klogctl(i32 10, i8* null, i32 0)
%28 = icmp slt i32 %27, 1
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i32, i32* @errno
%31 = tail call i32 @die(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %29, %26
%33 = xor i32 %27, -1
%34 = lshr i32 %33, 31
%35 = tail call i32 @assert(i32 %34)
%36 = add nsw i32 %27, 1
%37 = tail call i8* @calloc(i32 1, i32 %36)
%38 = icmp eq i8* %37, null
br i1 %38, label %50, label %39
39: ; preds = %32, %45
%40 = tail call i32 @klogctl(i32 2, i8* %37, i32 %27)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* @errno
%44 = tail call i32 @die(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %42, %39
%46 = sext i32 %40 to i64
%47 = getelementptr inbounds i8, i8* %37, i64 %46
store i8 0, i8* %47
%48 = tail call i32 (...) @getpid()
%49 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 %48, i8* %37)
br label %39
50: ; preds = %32, %24, %19, %13, %4
%51 = phi i32 [ 1, %4 ], [ 1, %24 ], [ 0, %19 ], [ 0, %13 ], [ 2, %32 ]
ret i32 %51
}