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

/* Variables and functions */
int O_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ close(int);
int open(char *, int);
int strlen(char const *);
scalar_t__ write(int, char const *, size_t);
bool usplash_command(const char *cmd) {
  int wrfd;
  ssize_t len;
  size_t towrite = strlen(cmd) + 1;
  size_t written = 0;
  wrfd = open("/dev/.initramfs/usplash_fifo", O_WRONLY | O_NONBLOCK);
  if (wrfd < 0)
    return false;
  while (written < towrite) {
    len = write(wrfd, cmd + written, towrite - written);
    if (len <= 0)
      break;
    written += len;
  }
  close(wrfd);
  if (written != towrite)
    return false;
  else
    return true;
}


x86 assembly (clang, -O0):
<usplash_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
mov    0x2e72(%rip),%rax
or     (%rax),%esi
lea    0xe81(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    119d <usplash_command+0x5d>
movl   $0x0,-0x4(%rbp)
jmp    1216 <usplash_command+0xd6>
jmp    11a2 <usplash_command+0x62>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    11ed <usplash_command+0xad>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rdx
sub    -0x30(%rbp),%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jg     11dc <usplash_command+0x9c>
jmp    11ed <usplash_command+0xad>
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11a2 <usplash_command+0x62>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     120f <usplash_command+0xcf>
movl   $0x0,-0x4(%rbp)
jmp    1216 <usplash_command+0xd6>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usplash_command>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    0x2e76(%rip),%rax
mov    0x2e87(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe94(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11c1 <usplash_command+0x81>
mov    %eax,%r12d
add    $0x1,%r14d
movslq %r14d,%rbx
xor    %ebp,%ebp
test   %ebx,%ebx
je     11af <usplash_command+0x6f>
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r15,%rbp,1),%rsi
mov    %rbx,%rdx
sub    %rbp,%rdx
mov    %r12d,%edi
call   1030 <write@plt>
test   %rax,%rax
jle    11af <usplash_command+0x6f>
add    %rax,%rbp
cmp    %rbx,%rbp
jb     1190 <usplash_command+0x50>
mov    %r12d,%edi
call   1050 <close@plt>
xor    %eax,%eax
cmp    %rbx,%rbp
sete   %al
jmp    11c3 <usplash_command+0x83>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"/dev/.initramfs/usplash_fifo\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @usplash_command(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @strlen(i8* %8)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
store i64 %11, i64* %6
store i64 0, i64* %7
%12 = load i32, i32* @O_WRONLY
%13 = load i32, i32* @O_NONBLOCK
%14 = or i32 %12, %13
%15 = call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %14)
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %1
store i32 0, i32* %2
br label %48
19: ; preds = %1
br label %20
20: ; preds = %36, %19
%21 = load i64, i64* %7
%22 = load i64, i64* %6
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32, i32* %4
%26 = load i8*, i8** %3
%27 = load i64, i64* %7
%28 = getelementptr inbounds i8, i8* %26, i64 %27
%29 = load i64, i64* %6
%30 = load i64, i64* %7
%31 = sub i64 %29, %30
%32 = call i64 @write(i32 %25, i8* %28, i64 %31)
store i64 %32, i64* %5
%33 = load i64, i64* %5
%34 = icmp sle i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %24
br label %40
36: ; preds = %24
%37 = load i64, i64* %5
%38 = load i64, i64* %7
%39 = add i64 %38, %37
store i64 %39, i64* %7
br label %20
40: ; preds = %35, %20
%41 = load i32, i32* %4
%42 = call i32 @close(i32 %41)
%43 = load i64, i64* %7
%44 = load i64, i64* %6
%45 = icmp ne i64 %43, %44
br i1 %45, label %46, label %47
46: ; preds = %40
store i32 0, i32* %2
br label %48
47: ; preds = %40
store i32 1, i32* %2
br label %48
48: ; preds = %47, %46, %18
%49 = load i32, i32* %2
ret i32 %49
}

LLVM IR (-O2):
@.str = [29 x i8] c"/dev/.initramfs/usplash_fifo\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @usplash_command(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 1
%4 = sext i32 %3 to i64
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp slt i32 %8, 0
br i1 %9, label %26, label %10
10: ; preds = %1
%11 = icmp eq i32 %3, 0
br i1 %11, label %21, label %14
12: ; preds = %14
%13 = icmp ult i64 %20, %4
br i1 %13, label %14, label %21
14: ; preds = %10, %12
%15 = phi i64 [ %20, %12 ], [ 0, %10 ]
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = sub i64 %4, %15
%18 = tail call i64 @write(i32 %8, i8* %16, i64 %17)
%19 = icmp slt i64 %18, 1
%20 = add i64 %18, %15
br i1 %19, label %21, label %12
21: ; preds = %12, %14, %10
%22 = phi i64 [ 0, %10 ], [ %15, %14 ], [ %20, %12 ]
%23 = tail call i32 @close(i32 %8)
%24 = icmp eq i64 %22, %4
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %21, %1
%27 = phi i32 [ 0, %1 ], [ %25, %21 ]
ret i32 %27
}