#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*/ time_t;
struct tm {
  int tm_year;
  int tm_mon;
  int tm_mday;
  int tm_hour;
  int tm_min;
  int tm_sec;
};

/* Variables and functions */
int /*<<< orphan*/ LOG_KERN;
int LOG_NOTICE;
int /*<<< orphan*/ gmtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ localtime_r(int /*<<< orphan*/ *, struct tm *);
int /*<<< orphan*/ printf(char *, char *, int, int, int, int, int, int, int,
                          char *);
int /*<<< orphan*/ stub1(int /*<<< orphan*/ *, struct tm *);
char *syslog_facility(int /*<<< orphan*/);
int syslog_priority(char *, char **, int *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int kernel_print(char *line) {
  char *facility;
  int level, start;
  struct tm date;
  time_t now;
  time(&now);
  (1 ? gmtime_r : localtime_r)(&now, &date);
  facility = syslog_facility(LOG_KERN), level = LOG_NOTICE;
  start = syslog_priority(line, &facility, &level);
  if (line[start]) {
    printf("0 0 0 %s %u %04u-%02u-%02u %02u:%02u:%02u %s\n", facility, level,
           date.tm_year + 1900, date.tm_mon + 1, date.tm_mday, date.tm_hour,
           date.tm_min, date.tm_sec, line + start);
  }
  return start;
}


x86 assembly (clang, -O0):
<kernel_print>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x3c(%rbp),%rdi
call   1070 <time@plt>
lea    -0x3c(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <gmtime_r@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1030 <syslog_facility@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1060 <syslog_priority@plt>
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rcx
cmpb   $0x0,(%rax,%rcx,1)
je     1207 <kernel_print+0xb7>
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x38(%rbp),%ecx
add    $0x76c,%ecx
mov    -0x34(%rbp),%r8d
add    $0x1,%r8d
mov    -0x30(%rbp),%r9d
mov    -0x2c(%rbp),%ebx
mov    -0x28(%rbp),%r11d
mov    -0x24(%rbp),%r10d
mov    -0x10(%rbp),%rax
movslq -0x20(%rbp),%rdi
add    %rdi,%rax
lea    0xe10(%rip),%rdi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10d,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <printf@plt>
mov    -0x20(%rbp),%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<kernel_print>:
push   %rbp
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
lea    0x34(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <time@plt>
lea    0x18(%rsp),%rsi
mov    %rbp,%rdi
call   1050 <gmtime_r@plt>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
call   1030 <syslog_facility@plt>
mov    %rax,0x10(%rsp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1060 <syslog_priority@plt>
mov    %eax,%ebp
cltq
cmpb   $0x0,(%rbx,%rax,1)
je     11f6 <kernel_print+0xa6>
add    %rax,%rbx
mov    0x10(%rsp),%rsi
mov    0xc(%rsp),%edx
mov    $0x76c,%ecx
add    0x18(%rsp),%ecx
mov    0x1c(%rsp),%r8d
mov    0x20(%rsp),%r9d
add    $0x1,%r8d
mov    0x24(%rsp),%r10d
mov    0x28(%rsp),%r11d
mov    0x2c(%rsp),%eax
lea    0xe19(%rip),%rdi
push   %rbx
push   %rax
push   %r11
push   %r10
call   1040 <printf@plt>
add    $0x20,%rsp
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@LOG_KERN = global i32 0
@LOG_NOTICE = global i32 0
@.str = [46 x i8] c"0 0 0 %s %u %04u-%02u-%02u %02u:%02u:%02u %s\0A\00"
define i32 @kernel_print(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.tm
%7 = alloca i32
store i8* %0, i8** %2
%8 = call i32 @time(i32* %7)
%9 = call i32 @gmtime_r(i32* %7, %struct.tm* %6)
%10 = load i32, i32* @LOG_KERN
%11 = call i8* @syslog_facility(i32 %10)
store i8* %11, i8** %3
%12 = load i32, i32* @LOG_NOTICE
store i32 %12, i32* %4
%13 = load i8*, i8** %2
%14 = call i32 @syslog_priority(i8* %13, i8** %3, i32* %4)
store i32 %14, i32* %5
%15 = load i8*, i8** %2
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %43
21: ; preds = %1
%22 = load i8*, i8** %3
%23 = load i32, i32* %4
%24 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = add nsw i32 %25, 1900
%27 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 1
%28 = load i32, i32* %27
%29 = add nsw i32 %28, 1
%30 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 2
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 3
%33 = load i32, i32* %32
%34 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 4
%35 = load i32, i32* %34
%36 = getelementptr inbounds %struct.tm, %struct.tm* %6, i32 0, i32 5
%37 = load i32, i32* %36
%38 = load i8*, i8** %2
%39 = load i32, i32* %5
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23, i32 %26, i32 %29, i32 %31, i32 %33, i32 %35, i32 %37, i8* %41)
br label %43
43: ; preds = %21, %1
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
%struct.tm = type { i32, i32, i32, i32, i32, i32 }
@LOG_KERN = global i32 0
@LOG_NOTICE = global i32 0
@.str = [46 x i8] c"0 0 0 %s %u %04u-%02u-%02u %02u:%02u:%02u %s\0A\00"
define i32 @kernel_print(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca %struct.tm
%5 = alloca i32
%6 = bitcast i8** %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast %struct.tm* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = call i32 @time(i32* %5)
%11 = call i32 @gmtime_r(i32* %5, %struct.tm* %4)
%12 = load i32, i32* @LOG_KERN
%13 = call i8* @syslog_facility(i32 %12)
store i8* %13, i8** %2
%14 = load i32, i32* @LOG_NOTICE
store i32 %14, i32* %3
%15 = call i32 @syslog_priority(i8* %0, i8** %2, i32* %3)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %0, i64 %16
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 0
br i1 %19, label %38, label %20
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = load i32, i32* %3
%23 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 0
%24 = load i32, i32* %23
%25 = add nsw i32 %24, 1900
%26 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 1
%27 = load i32, i32* %26
%28 = add nsw i32 %27, 1
%29 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 2
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 3
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 4
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.tm, %struct.tm* %4, i64 0, i32 5
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %21, i32 %22, i32 %25, i32 %28, i32 %30, i32 %32, i32 %34, i32 %36, i8* %17)
br label %38
38: ; preds = %20, %1
ret i32 %15
}