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

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
unsigned int write(int /*<<< orphan*/, char *, unsigned int);
void write_to_stdout(char *buf, unsigned int nr) {
  ssize_t ret;
  ret = write(STDOUT_FILENO, buf, nr);
  if (ret != nr) {
    fprintf(stderr,
            "Failed to write out the dmesg log buffer!:"
            " %s\n",
            strerror(errno));
    exit(54);
  }
}


x86 assembly (clang, -O0):
<write_to_stdout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1030 <write@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
je     11a9 <write_to_stdout+0x69>
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe66(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x36,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_stdout>:
push   %rbx
mov    %esi,%ebx
mov    %rdi,%rsi
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%edx
call   1030 <write@plt>
cmp    %ebx,%eax
jne    115c <write_to_stdout+0x1c>
pop    %rbx
ret
mov    0x2e75(%rip),%rax
mov    (%rax),%ebx
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe86(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0x36,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"Failed to write out the dmesg log buffer!: %s\0A\00"
@errno = global i32 0
define void @write_to_stdout(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* @STDOUT_FILENO
%7 = load i8*, i8** %3
%8 = load i32, i32* %4
%9 = call i32 @write(i32 %6, i8* %7, i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 54)
unreachable
19: ; preds = %2
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"Failed to write out the dmesg log buffer!: %s\0A\00"
@errno = global i32 0
define void @write_to_stdout(i8* nocapture %0, i32 %1) {
%3 = load i32, i32* @STDOUT_FILENO
%4 = tail call i32 @write(i32 %3, i8* %0, i32 %1)
%5 = icmp eq i32 %4, %1
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = tail call i32 @exit(i32 54)
unreachable
12: ; preds = %2
ret void
}