#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char const *, int, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
int rncryptorc_write_file(const char *outfile_path, const unsigned char *data,
                          int data_len) {
  int rc = 0x01;
  FILE *ofp = NULL;
  if (outfile_path == NULL || *outfile_path == '\0') {
    (void)fprintf(stderr, "File path can not be NULL\n");
    rc = 0x01;
    goto ExitProcessing;
  }
  if (data == NULL || data_len <= 0) {
    (void)fprintf(stderr, "Invalid data\n");
    rc = 0x01;
    goto ExitProcessing;
  }
  if (*outfile_path == '-') {
    ofp = stdout;
  } else {
    ofp = fopen(outfile_path, "wb");
    if (ofp == NULL) {
      (void)fprintf(stderr, "Could not create file %s\n", outfile_path);
      rc = 0x01;
      goto ExitProcessing;
    }
  }
  fwrite(data, sizeof(char), data_len, ofp);
  rc = 0x00;
ExitProcessing:
  if (ofp && ofp != stdout) {
    (void)fclose(ofp);
  }
  return (rc);
}


x86 assembly (clang, -O0):
<rncryptorc_write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     117d <rncryptorc_write_file+0x3d>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11a0 <rncryptorc_write_file+0x60>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x18(%rbp)
jmp    1262 <rncryptorc_write_file+0x122>
cmpq   $0x0,-0x10(%rbp)
je     11b5 <rncryptorc_write_file+0x75>
cmpl   $0x0,-0x14(%rbp)
jg     11d8 <rncryptorc_write_file+0x98>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x18(%rbp)
jmp    1262 <rncryptorc_write_file+0x122>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    11fb <rncryptorc_write_file+0xbb>
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    1246 <rncryptorc_write_file+0x106>
mov    -0x8(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1241 <rncryptorc_write_file+0x101>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdfe(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x18(%rbp)
jmp    1262 <rncryptorc_write_file+0x122>
jmp    1246 <rncryptorc_write_file+0x106>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
movl   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     128a <rncryptorc_write_file+0x14a>
mov    -0x20(%rbp),%rax
mov    0x2d60(%rip),%rcx
cmp    (%rcx),%rax
je     128a <rncryptorc_write_file+0x14a>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rncryptorc_write_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1174 <rncryptorc_write_file+0x34>
mov    %rdi,%rbp
mov    (%rdi),%al
test   %al,%al
je     1174 <rncryptorc_write_file+0x34>
mov    %rsi,%rbx
test   %rsi,%rsi
je     1186 <rncryptorc_write_file+0x46>
mov    %edx,%r14d
test   %edx,%edx
jle    1186 <rncryptorc_write_file+0x46>
cmp    $0x2d,%al
jne    11af <rncryptorc_write_file+0x6f>
mov    0x2e69(%rip),%rax
mov    (%rax),%r15
jmp    11c6 <rncryptorc_write_file+0x86>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
jmp    1196 <rncryptorc_write_file+0x56>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    0xe85(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe73(%rip),%rsi
mov    %rbp,%rdi
call   1050 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     11f6 <rncryptorc_write_file+0xb6>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %r15,%rcx
call   1060 <fwrite@plt>
xor    %ebx,%ebx
test   %r15,%r15
je     11a2 <rncryptorc_write_file+0x62>
mov    0x2df1(%rip),%rax
cmp    (%rax),%r15
je     11a2 <rncryptorc_write_file+0x62>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    11a2 <rncryptorc_write_file+0x62>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe26(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    119d <rncryptorc_write_file+0x5d>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"File path can not be NULL\0A\00"
@.str.1 = [14 x i8] c"Invalid data\0A\00"
@stdout = global i32* null
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [26 x i8] c"Could not create file %s\0A\00"
define i32 @rncryptorc_write_file(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 1, i32* %7
store i32* null, i32** %8
%9 = load i8*, i8** %4
%10 = icmp eq i8* %9, null
br i1 %10, label %16, label %11
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11, %3
%17 = load i32, i32* @stderr
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %7
br label %50
19: ; preds = %11
%20 = load i8*, i8** %5
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22, %19
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %7
br label %50
28: ; preds = %22
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 45
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = load i32*, i32** @stdout
store i32* %34, i32** %8
br label %45
35: ; preds = %28
%36 = load i8*, i8** %4
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %37, i32** %8
%38 = load i32*, i32** %8
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %4
%43 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %42)
store i32 1, i32* %7
br label %50
44: ; preds = %35
br label %45
45: ; preds = %44, %33
%46 = load i8*, i8** %5
%47 = load i32, i32* %6
%48 = load i32*, i32** %8
%49 = call i32 @fwrite(i8* %46, i32 1, i32 %47, i32* %48)
store i32 0, i32* %7
br label %50
50: ; preds = %45, %40, %25, %16
%51 = load i32*, i32** %8
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %60
53: ; preds = %50
%54 = load i32*, i32** %8
%55 = load i32*, i32** @stdout
%56 = icmp ne i32* %54, %55
br i1 %56, label %57, label %60
57: ; preds = %53
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
br label %60
60: ; preds = %57, %53, %50
%61 = load i32, i32* %7
ret i32 %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"File path can not be NULL\0A\00"
@.str.1 = [14 x i8] c"Invalid data\0A\00"
@stdout = global i32* null
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [26 x i8] c"Could not create file %s\0A\00"
define i32 @rncryptorc_write_file(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %8, label %5
5: ; preds = %3
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %5, %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %37
11: ; preds = %5
%12 = icmp eq i8* %1, null
%13 = icmp slt i32 %2, 1
%14 = or i1 %12, %13
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %37
18: ; preds = %11
%19 = icmp eq i8 %6, 45
br i1 %19, label %20, label %22
20: ; preds = %18
%21 = load i32*, i32** @stdout
br label %28
22: ; preds = %18
%23 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %37
28: ; preds = %20, %22
%29 = phi i32* [ %21, %20 ], [ %23, %22 ]
%30 = tail call i32 @fwrite(i8* %1, i32 1, i32 %2, i32* %29)
%31 = icmp eq i32* %29, null
%32 = load i32*, i32** @stdout
%33 = icmp eq i32* %29, %32
%34 = select i1 %31, i1 true, i1 %33
br i1 %34, label %37, label %35
35: ; preds = %28
%36 = tail call i32 @fclose(i32* %29)
br label %37
37: ; preds = %25, %15, %8, %35, %28
%38 = phi i32 [ 0, %35 ], [ 0, %28 ], [ 1, %8 ], [ 1, %15 ], [ 1, %25 ]
ret i32 %38
}