#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 /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char const *);
scalar_t__ write(int, char const *, scalar_t__);
int write_to_file(const char *fcp_file, const char *command) {
  int rc = 0, fh = 0;
  fh = open(fcp_file, O_WRONLY);
  if (fh == -1) {
    {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "Could not open %s", fcp_file);
      perror("");
    };
    rc = -1;
    goto out;
  }
  if (write(fh, command, strlen(command)) != strlen(command)) {
    {
      fprintf(stderr, "ERROR: ");
      fprintf(stderr, "Write to %s failed", fcp_file);
      perror("");
    };
    rc = -1;
    goto out;
  };
out:
  if (fh)
    close(fh);
  return rc;
}


x86 assembly (clang, -O0):
<write_to_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11e7 <write_to_file+0x87>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
lea    0xe53(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe40(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xe31(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    1279 <write_to_file+0x119>
mov    -0x18(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     1274 <write_to_file+0x114>
mov    0x2daf(%rip),%rax
mov    (%rax),%edi
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xda4(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x14(%rbp)
jmp    1279 <write_to_file+0x119>
jmp    1279 <write_to_file+0x119>
cmpl   $0x0,-0x18(%rbp)
je     128b <write_to_file+0x12b>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_to_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     11c5 <write_to_file+0x65>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
xor    %ebx,%ebx
cmp    %rax,%rbp
jne    1202 <write_to_file+0xa2>
test   %r15d,%r15d
je     11b8 <write_to_file+0x58>
mov    %r15d,%edi
call   1050 <close@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e14(%rip),%rbx
mov    (%rbx),%edi
lea    0xe2b(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe23(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xe11(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11b0 <write_to_file+0x50>
mov    0x2dd7(%rip),%rbx
mov    (%rbx),%edi
lea    0xdee(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdf8(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xdd4(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
test   %r15d,%r15d
jne    11b0 <write_to_file+0x50>
jmp    11b8 <write_to_file+0x58>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str = [8 x i8] c"ERROR: \00"
@.str.1 = [18 x i8] c"Could not open %s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [19 x i8] c"Write to %s failed\00"
define i32 @write_to_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
store i32 0, i32* %6
%7 = load i8*, i8** %3
%8 = load i32, i32* @O_WRONLY
%9 = call i32 @open(i8* %7, i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %36
19: ; preds = %2
%20 = load i32, i32* %6
%21 = load i8*, i8** %4
%22 = load i8*, i8** %4
%23 = call i64 @strlen(i8* %22)
%24 = call i64 @write(i32 %20, i8* %21, i64 %23)
%25 = load i8*, i8** %4
%26 = call i64 @strlen(i8* %25)
%27 = icmp ne i64 %24, %26
br i1 %27, label %28, label %35
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %3
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %5
br label %36
35: ; preds = %19
br label %36
36: ; preds = %35, %28, %12
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
br label %42
42: ; preds = %39, %36
%43 = load i32, i32* %5
ret i32 %43
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@stderr = global i32 0
@.str = [8 x i8] c"ERROR: \00"
@.str.1 = [18 x i8] c"Could not open %s\00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [19 x i8] c"Write to %s failed\00"
define i32 @write_to_file(i8* %0, i8* nocapture %1) {
%3 = load i32, i32* @O_WRONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %12
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %26
12: ; preds = %2
%13 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%14 = tail call i64 @write(i32 %4, i8* %1, i64 %13)
%15 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%16 = icmp eq i64 %14, %15
br i1 %16, label %23, label %17
17: ; preds = %12
%18 = load i32, i32* @stderr
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%22 = tail call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %12, %17
%24 = phi i32 [ -1, %17 ], [ 0, %12 ]
%25 = icmp eq i32 %4, 0
br i1 %25, label %29, label %26
26: ; preds = %6, %23
%27 = phi i32 [ -1, %6 ], [ %24, %23 ]
%28 = tail call i32 @close(i32 %4)
br label %29
29: ; preds = %26, %23
%30 = phi i32 [ %27, %26 ], [ %24, %23 ]
ret i32 %30
}