#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char);
int /*<<< orphan*/ strlen(char *);
int write(int, char *, int /*<<< orphan*/);
int send_cmd(char *fifo_filename, char *cmd) {
  int fifo_fd = open(fifo_filename, O_WRONLY | O_NONBLOCK);
  if (fifo_fd < 0) {
    fprintf(stderr, "vegas_fits_writer: Error opening control fifo %s\n",
            fifo_filename);
    perror("open");
    char ns[1];
    strcpy(ns, '\n');
    strcat(cmd, ns);
    write(fifo_fd, cmd, strlen(cmd));
    if (write(fifo_fd, cmd, strlen(cmd)) == -1) {
      perror("write error");
    }
    return (0);
  }
}


x86 assembly (clang, -O0):
<send_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
mov    0x2e54(%rip),%rax
or     (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    124e <send_cmd+0xde>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe44(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe6a(%rip),%rdi
call   1080 <perror@plt>
lea    -0x1d(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    -0x1d(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1247 <send_cmd+0xd7>
lea    0xdf5(%rip),%rdi
call   1080 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_cmd>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e43(%rip),%rax
mov    0x2e5c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     11a4 <send_cmd+0x34>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %eax,%ebp
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
lea    0xe6d(%rip),%rdi
call   1080 <perror@plt>
lea    0xf(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strcpy@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
jne    1199 <send_cmd+0x29>
lea    0xe1c(%rip),%rdi
call   1080 <perror@plt>
jmp    1199 <send_cmd+0x29>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"vegas_fits_writer: Error opening control fifo %s\0A\00"
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [12 x i8] c"write error\00"
define i32 @send_cmd(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [1 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %9, %10
%12 = call i32 @open(i8* %8, i32 %11)
store i32 %12, i32* %6
%13 = load i32, i32* %6
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %39
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%20 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%21 = call i32 @strcpy(i8* %20, i8 signext 10)
%22 = load i8*, i8** %5
%23 = getelementptr inbounds [1 x i8], [1 x i8]* %7, i64 0, i64 0
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = load i32, i32* %6
%26 = load i8*, i8** %5
%27 = load i8*, i8** %5
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @write(i32 %25, i8* %26, i32 %28)
%30 = load i32, i32* %6
%31 = load i8*, i8** %5
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @write(i32 %30, i8* %31, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %15
%37 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %15
store i32 0, i32* %3
br label %39
39: ; preds = %38, %2
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_NONBLOCK = global i32 0
@stderr = global i32 0
@.str = [50 x i8] c"vegas_fits_writer: Error opening control fifo %s\0A\00"
@.str.1 = [5 x i8] c"open\00"
@.str.2 = [12 x i8] c"write error\00"
define i32 @send_cmd(i8* %0, i8* %1) {
%3 = alloca [1 x i8]
%4 = load i32, i32* @O_WRONLY
%5 = load i32, i32* @O_NONBLOCK
%6 = or i32 %5, %4
%7 = tail call i32 @open(i8* %0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %24
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%14 = call i32 @strcpy(i8* %13, i8 signext 10)
%15 = call i32 @strcat(i8* %1, i8* %13)
%16 = call i32 @strlen(i8* %1)
%17 = call i32 @write(i32 %7, i8* %1, i32 %16)
%18 = call i32 @strlen(i8* %1)
%19 = call i32 @write(i32 %7, i8* %1, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %9
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %21, %9
br label %24
24: ; preds = %2, %23
ret i32 0
}