#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_NONBLOCK;
int O_WRONLY;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *getenv(char *);
int open(char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char **argv) {
  char *tmpdir;
  int pipe_fd;
  tmpdir = getenv("TMPDIR");
  if (!tmpdir)
    tmpdir = "/tmp";
  if (argc != 2) {
    fprintf(stderr, "Wrong number of arguments\n");
    exit(-1);
  }
  chdir(tmpdir);
  if ((pipe_fd = open("psplash_fifo", O_WRONLY | O_NONBLOCK)) == -1) {
    exit(-1);
  }
  write(pipe_fd, argv[1], strlen(argv[1]) + 1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe73(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ac <main+0x3c>
lea    0xe5f(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d5 <main+0x65>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe46(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1060 <chdir@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
or     (%rax),%esi
lea    0xe30(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1212 <main+0xa2>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <write@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe81(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x2,%ebp
jne    11e4 <main+0x74>
test   %rax,%rax
lea    0xe74(%rip),%rdi
cmovne %rax,%rdi
call   1060 <chdir@plt>
mov    0x2e25(%rip),%rax
mov    0x2e3e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe72(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     11f9 <main+0x89>
mov    %eax,%ebp
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <write@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Wrong number of arguments\0A\00"
@.str.3 = [13 x i8] c"psplash_fifo\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i8* %8, i8** %6
%9 = load i8*, i8** %6
%10 = icmp ne i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %12
12: ; preds = %11, %2
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 -1)
unreachable
19: ; preds = %12
%20 = load i8*, i8** %6
%21 = call i32 @chdir(i8* %20)
%22 = load i32, i32* @O_WRONLY
%23 = load i32, i32* @O_NONBLOCK
%24 = or i32 %22, %23
%25 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %24)
store i32 %25, i32* %7
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %19
%30 = load i32, i32* %7
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = call i64 @strlen(i8* %36)
%38 = add nsw i64 %37, 1
%39 = call i32 @write(i32 %30, i8* %33, i64 %38)
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"TMPDIR\00"
@.str.1 = [5 x i8] c"/tmp\00"
@stderr = global i32 0
@.str.2 = [27 x i8] c"Wrong number of arguments\0A\00"
@.str.3 = [13 x i8] c"psplash_fifo\00"
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = tail call i8* @getenv(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%8 = tail call i32 @exit(i32 -1)
unreachable
9: ; preds = %2
%10 = icmp eq i8* %3, null
%11 = select i1 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3
%12 = tail call i32 @chdir(i8* %11)
%13 = load i32, i32* @O_WRONLY
%14 = load i32, i32* @O_NONBLOCK
%15 = or i32 %14, %13
%16 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %9
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %9
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = tail call i64 @strlen(i8* dereferenceable(1) %22)
%24 = add nsw i64 %23, 1
%25 = tail call i32 @write(i32 %16, i8* %22, i64 %24)
ret i32 0
}