#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 */
char *build_path(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char const *, int, int, int /*<<< orphan*/ *);
void cache_set(const char *name, const char *data, int size) {
  char *path;
  FILE *file;
  path = build_path(name);
  file = fopen(path, "wb");
  free(path);
  if (!file) {
    return;
  }
  fwrite(data, 1, size, file);
  fclose(file);
}


x86 assembly (clang, -O0):
<cache_set>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <build_path@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x28(%rbp)
jne    119d <cache_set+0x4d>
jmp    11bb <cache_set+0x6b>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cache_set>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%r15
call   1040 <build_path@plt>
mov    %rax,%rbx
lea    0xe94(%rip),%rsi
mov    %rax,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %rbp,%rbp
je     11a9 <cache_set+0x59>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
mov    %rbp,%rcx
call   1070 <fwrite@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fclose@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define void @cache_set(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%9 = load i8*, i8** %4
%10 = call i8* @build_path(i8* %9)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i8*, i8** %7
%14 = call i32 @free(i8* %13)
%15 = load i32*, i32** %8
%16 = icmp ne i32* %15, null
br i1 %16, label %18, label %17
17: ; preds = %3
br label %25
18: ; preds = %3
%19 = load i8*, i8** %5
%20 = load i32, i32* %6
%21 = load i32*, i32** %8
%22 = call i32 @fwrite(i8* %19, i32 1, i32 %20, i32* %21)
%23 = load i32*, i32** %8
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %18, %17
ret void
}

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