#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 *, char *);
long fwrite(char *, int, long, int /*<<< orphan*/ *);
long csc_file_store(char *path, int ovrd, char *src, long len) {
  FILE *fp;
  long n, amnt;
  if (ovrd) {
    fp = fopen(path, "w");
  } else {
    fp = fopen(path, "a");
  }
  if (fp == NULL) {
    return (0xC0000000 | (7));
  }
  amnt = 0;
  while (1) {
    n = fwrite(src + amnt, 1, len - amnt, fp);
    amnt += n;
    if (amnt == len) {
      break;
    }
  }
  fclose(fp);
  return amnt;
}


x86 assembly (clang, -O0):
<csc_file_store>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     116a <csc_file_store+0x3a>
mov    -0x10(%rbp),%rdi
lea    0xea4(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
jmp    117e <csc_file_store+0x4e>
mov    -0x10(%rbp),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1197 <csc_file_store+0x67>
mov    $0xc0000007,%eax
mov    %rax,-0x8(%rbp)
jmp    11f6 <csc_file_store+0xc6>
movq   $0x0,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
add    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rdx
sub    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fwrite@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    11e0 <csc_file_store+0xb0>
jmp    11e5 <csc_file_store+0xb5>
jmp    119f <csc_file_store+0x6f>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_file_store>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r12
mov    %rdx,%r14
test   %esi,%esi
lea    0xebb(%rip),%rax
lea    0xeb2(%rip),%rsi
cmove  %rax,%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1199 <csc_file_store+0x69>
mov    %rax,%r15
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r14,%rbx,1),%rdi
mov    %r12,%rdx
sub    %rbx,%rdx
mov    $0x1,%esi
mov    %r15,%rcx
call   1050 <fwrite@plt>
add    %rax,%rbx
cmp    %r12,%rbx
jne    1170 <csc_file_store+0x40>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    119f <csc_file_store+0x6f>
mov    $0xc0000007,%r12d
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
define i64 @csc_file_store(i8* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i64
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load i8*, i8** %6
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %10
br label %21
18: ; preds = %4
%19 = load i8*, i8** %6
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %10
br label %21
21: ; preds = %18, %15
%22 = load i32*, i32** %10
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %25
24: ; preds = %21
store i64 3221225479, i64* %5
br label %47
25: ; preds = %21
store i64 0, i64* %12
br label %26
26: ; preds = %25, %42
%27 = load i8*, i8** %8
%28 = load i64, i64* %12
%29 = getelementptr inbounds i8, i8* %27, i64 %28
%30 = load i64, i64* %9
%31 = load i64, i64* %12
%32 = sub nsw i64 %30, %31
%33 = load i32*, i32** %10
%34 = call i64 @fwrite(i8* %29, i32 1, i64 %32, i32* %33)
store i64 %34, i64* %11
%35 = load i64, i64* %11
%36 = load i64, i64* %12
%37 = add nsw i64 %36, %35
store i64 %37, i64* %12
%38 = load i64, i64* %12
%39 = load i64, i64* %9
%40 = icmp eq i64 %38, %39
br i1 %40, label %41, label %42
41: ; preds = %26
br label %43
42: ; preds = %26
br label %26
43: ; preds = %41
%44 = load i32*, i32** %10
%45 = call i32 @fclose(i32* %44)
%46 = load i64, i64* %12
store i64 %46, i64* %5
br label %47
47: ; preds = %43, %24
%48 = load i64, i64* %5
ret i64 %48
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"a\00"
define i64 @csc_file_store(i8* nocapture %0, i32 %1, i8* nocapture %2, i64 %3) {
%5 = icmp eq i32 %1, 0
%6 = select i1 %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%7 = tail call i32* @fopen(i8* %0, i8* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %18, label %9
9: ; preds = %4, %9
%10 = phi i64 [ %14, %9 ], [ 0, %4 ]
%11 = getelementptr inbounds i8, i8* %2, i64 %10
%12 = sub nsw i64 %3, %10
%13 = tail call i64 @fwrite(i8* %11, i32 1, i64 %12, i32* %7)
%14 = add nsw i64 %13, %10
%15 = icmp eq i64 %14, %3
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = tail call i32 @fclose(i32* %7)
br label %18
18: ; preds = %4, %16
%19 = phi i64 [ %3, %16 ], [ 3221225479, %4 ]
ret i64 %19
}