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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fwrite(void const *, size_t, int, int /*<<< orphan*/ *);
int32_t fslittle_test_create(const char *filename, const char *data,
                             size_t len) {
  int32_t ret = -1;
  FILE *fp = NULL;
  do {
  } while (0);
  fp = fopen(filename, "w+");
  if (fp == NULL) {
    return ret;
  }
  ret = fwrite((const void *)data, len, 1, fp);
  if (ret < 0) {
    fclose(fp);
    return ret;
  }
  fclose(fp);
  return ret;
}


x86 assembly (clang, -O0):
<fslittle_test_create>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
movq   $0x0,-0x30(%rbp)
jmp    1159 <fslittle_test_create+0x29>
mov    -0x10(%rbp),%rdi
lea    0xe9c(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1185 <fslittle_test_create+0x55>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d1 <fslittle_test_create+0xa1>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rcx
mov    $0x1,%edx
call   1050 <fwrite@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    11c0 <fslittle_test_create+0x90>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11d1 <fslittle_test_create+0xa1>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fslittle_test_create>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
lea    0xebe(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1172 <fslittle_test_create+0x42>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rax
jmp    1179 <fslittle_test_create+0x49>
mov    $0xffffffffffffffff,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"w+\00"
define i64 @fslittle_test_create(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i64 -1, i64* %8
store i32* null, i32** %9
br label %10
10: ; preds = %3
br label %11
11: ; preds = %10
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %9
%14 = load i32*, i32** %9
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load i64, i64* %8
store i64 %17, i64* %4
br label %33
18: ; preds = %11
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = load i32*, i32** %9
%22 = call i64 @fwrite(i8* %19, i64 %20, i32 1, i32* %21)
store i64 %22, i64* %8
%23 = load i64, i64* %8
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %18
%26 = load i32*, i32** %9
%27 = call i32 @fclose(i32* %26)
%28 = load i64, i64* %8
store i64 %28, i64* %4
br label %33
29: ; preds = %18
%30 = load i32*, i32** %9
%31 = call i32 @fclose(i32* %30)
%32 = load i64, i64* %8
store i64 %32, i64* %4
br label %33
33: ; preds = %29, %25, %16
%34 = load i64, i64* %4
ret i64 %34
}

LLVM IR (-O2):
@.str = [3 x i8] c"w+\00"
define i64 @fslittle_test_create(i8* nocapture %0, i8* nocapture %1, i64 %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %9, label %6
6: ; preds = %3
%7 = tail call i64 @fwrite(i8* %1, i64 %2, i32 1, i32* %4)
%8 = tail call i32 @fclose(i32* %4)
br label %9
9: ; preds = %6, %3
%10 = phi i64 [ -1, %3 ], [ %7, %6 ]
ret i64 %10
}