#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ eprintf(char *);
int /*<<< orphan*/ putchar(char);
int write(int, char const *, size_t);
void dmesg_show(const void *buf, size_t n) {
  const char *p = buf;
  ssize_t r;
  r = write(1, p, n);
  if (r < 0)
    eprintf("write:");
  if (r > 0 && p[r - 1] != '\n')
    putchar('\n');
}


x86 assembly (clang, -O0):
<dmesg_show>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1173 <dmesg_show+0x43>
lea    0xe92(%rip),%rdi
call   1050 <eprintf@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    11a1 <dmesg_show+0x71>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     11a1 <dmesg_show+0x71>
mov    $0xa,%edi
call   1030 <putchar@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dmesg_show>:
push   %rbx
mov    %rsi,%rdx
mov    %rdi,%rbx
mov    $0x1,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
test   %eax,%eax
js     1155 <dmesg_show+0x25>
je     1153 <dmesg_show+0x23>
add    $0xffffffff,%eax
cmpb   $0xa,(%rbx,%rax,1)
jne    1162 <dmesg_show+0x32>
pop    %rbx
ret
lea    0xea4(%rip),%rdi
pop    %rbx
jmp    1050 <eprintf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"write:\00"
define void @dmesg_show(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i64 %1, i64* %4
%7 = load i8*, i8** %3
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = load i64, i64* %4
%10 = call i32 @write(i32 1, i8* %8, i64 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @eprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 10
br i1 %26, label %27, label %29
27: ; preds = %18
%28 = call i32 @putchar(i8 signext 10)
br label %29
29: ; preds = %27, %18, %15
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"write:\00"
define void @dmesg_show(i8* nocapture %0, i64 %1) {
%3 = tail call i32 @write(i32 1, i8* %0, i64 %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @eprintf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %2
%8 = icmp eq i32 %3, 0
br i1 %8, label %17, label %9
9: ; preds = %7
%10 = add nsw i32 %3, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 10
br i1 %14, label %17, label %15
15: ; preds = %9
%16 = tail call i32 @putchar(i8 signext 10)
br label %17
17: ; preds = %5, %15, %9, %7
ret void
}