#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 O_NDELAY;
int O_NOCTTY;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int console_open(int);
int /*<<< orphan*/ puts(char *);
int strlen(char *);
int write(int, char *, int);
void print_console(char *s) {
  int fd;
  if ((fd = console_open(O_WRONLY | O_NOCTTY | O_NDELAY)) >= 0) {
    int l = strlen(s);
    if (write(fd, s, l) != l)
      puts("init: can't write to system console");
    close(fd);
  } else {
    puts("init: can't open system console");
  }
}


x86 assembly (clang, -O0):
<print_console>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
mov    0x2e74(%rip),%rax
or     (%rax),%edi
mov    0x2e63(%rip),%rax
or     (%rax),%edi
call   1050 <console_open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     11c5 <print_console+0x75>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1040 <write@plt>
cmp    -0x10(%rbp),%eax
je     11b8 <print_console+0x68>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%edi
call   1070 <close@plt>
jmp    11d1 <print_console+0x81>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_console>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e6d(%rip),%rcx
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %rdi,%r14
mov    0x2e68(%rip),%rcx
or     (%rcx),%eax
mov    %eax,%edi
call   1050 <console_open@plt>
test   %eax,%eax
js     11b0 <print_console+0x60>
mov    %eax,%ebx
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebp
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    %ebp,%eax
je     11a5 <print_console+0x55>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1070 <close@plt>
lea    0xe6d(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [36 x i8] c"init: can't write to system console\00"
@.str.1 = [32 x i8] c"init: can't open system console\00"
define void @print_console(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_NOCTTY
%7 = or i32 %5, %6
%8 = load i32, i32* @O_NDELAY
%9 = or i32 %7, %8
%10 = call i32 @console_open(i32 %9)
store i32 %10, i32* %3
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %26
12: ; preds = %1
%13 = load i8*, i8** %2
%14 = call i32 @strlen(i8* %13)
store i32 %14, i32* %4
%15 = load i32, i32* %3
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = call i32 @write(i32 %15, i8* %16, i32 %17)
%19 = load i32, i32* %4
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = call i32 @puts(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %12
%24 = load i32, i32* %3
%25 = call i32 @close(i32 %24)
br label %28
26: ; preds = %1
%27 = call i32 @puts(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %26, %23
ret void
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_NOCTTY = global i32 0
@O_NDELAY = global i32 0
@.str = [36 x i8] c"init: can't write to system console\00"
@.str.1 = [32 x i8] c"init: can't open system console\00"
define void @print_console(i8* %0) {
%2 = load i32, i32* @O_WRONLY
%3 = load i32, i32* @O_NOCTTY
%4 = or i32 %3, %2
%5 = load i32, i32* @O_NDELAY
%6 = or i32 %4, %5
%7 = tail call i32 @console_open(i32 %6)
%8 = icmp sgt i32 %7, -1
br i1 %8, label %9, label %17
9: ; preds = %1
%10 = tail call i32 @strlen(i8* %0)
%11 = tail call i32 @write(i32 %7, i8* %0, i32 %10)
%12 = icmp eq i32 %11, %10
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
%16 = tail call i32 @close(i32 %7)
br label %19
17: ; preds = %1
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
ret void
}