#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 EIO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open_nb(char *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int write_err(int pts, int realfd, char *realcons, int e) {
  int fd;
  if (e != EIO) {
  werr:
    close(pts);
    fprintf(stderr, "bootlogd: writing to console: %s\n", strerror(e));
    return -1;
  }
  close(realfd);
  if ((fd = open_nb(realcons)) < 0)
    goto werr;
  return fd;
}


x86 assembly (clang, -O0):
<write_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
je     11a6 <write_err+0x66>
jmp    116c <write_err+0x2c>
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ce <write_err+0x8e>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
mov    -0x18(%rbp),%rdi
call   1050 <open_nb@plt>
mov    %eax,-0x20(%rbp)
cmp    $0x0,%eax
jge    11c8 <write_err+0x88>
jmp    116c <write_err+0x2c>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_err>:
push   %rbp
push   %r14
push   %rbx
mov    %ecx,%ebx
mov    %edi,%r14d
mov    0x2e90(%rip),%rax
cmp    %ecx,(%rax)
jne    116a <write_err+0x2a>
mov    %rdx,%rbp
mov    %esi,%edi
call   1030 <close@plt>
mov    %rbp,%rdi
call   1050 <open_nb@plt>
test   %eax,%eax
jns    1198 <write_err+0x58>
mov    %r14d,%edi
call   1030 <close@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe77(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@EIO = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"bootlogd: writing to console: %s\0A\00"
define i32 @write_err(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i32, i32* %9
%12 = load i32, i32* @EIO
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %4
br label %15
15: ; preds = %28, %14
%16 = load i32, i32* %6
%17 = call i32 @close(i32 %16)
%18 = load i32, i32* @stderr
%19 = load i32, i32* %9
%20 = call i8* @strerror(i32 %19)
%21 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %20)
store i32 -1, i32* %5
br label %31
22: ; preds = %4
%23 = load i32, i32* %7
%24 = call i32 @close(i32 %23)
%25 = load i8*, i8** %8
%26 = call i32 @open_nb(i8* %25)
store i32 %26, i32* %10
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %22
br label %15
29: ; preds = %22
%30 = load i32, i32* %10
store i32 %30, i32* %5
br label %31
31: ; preds = %29, %15
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@EIO = global i32 0
@stderr = global i32 0
@.str = [34 x i8] c"bootlogd: writing to console: %s\0A\00"
define i32 @write_err(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = load i32, i32* @EIO
%6 = icmp eq i32 %5, %3
br i1 %6, label %12, label %7
7: ; preds = %12, %4
%8 = tail call i32 @close(i32 %0)
%9 = load i32, i32* @stderr
%10 = tail call i8* @strerror(i32 %3)
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %16
12: ; preds = %4
%13 = tail call i32 @close(i32 %1)
%14 = tail call i32 @open_nb(i8* %2)
%15 = icmp slt i32 %14, 0
br i1 %15, label %7, label %16
16: ; preds = %12, %7
%17 = phi i32 [ -1, %7 ], [ %14, %12 ]
ret i32 %17
}