#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 *);
size_t fwrite(void *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int putData(char *filename, size_t size, void *buffer) {
  FILE *fp;
  size_t asize;
  if ((fp = fopen(filename, "wb")) != (FILE *)NULL) {
    asize = fwrite(buffer, 1, size, fp);
    fclose(fp);
    printf("Successfully wrote %lu bytes.\n", asize);
  } else {
    printf("error: Unable to open: %s.\n", filename);
  }
  return 0;
}


x86 assembly (clang, -O0):
<putData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11ac <putData+0x6c>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rsi
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11be <putData+0x7e>
mov    -0x8(%rbp),%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putData>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xea8(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118f <putData+0x4f>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r14,%rdx
mov    %rax,%rcx
call   1060 <fwrite@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe79(%rip),%rdi
mov    %r14,%rsi
jmp    1199 <putData+0x59>
lea    0xe8c(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [31 x i8] c"Successfully wrote %lu bytes.\0A\00"
@.str.2 = [28 x i8] c"error: Unable to open: %s.\0A\00"
define i32 @putData(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i64
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %21
12: ; preds = %3
%13 = load i8*, i8** %6
%14 = load i64, i64* %5
%15 = load i32*, i32** %7
%16 = call i64 @fwrite(i8* %13, i32 1, i64 %14, i32* %15)
store i64 %16, i64* %8
%17 = load i32*, i32** %7
%18 = call i32 @fclose(i32* %17)
%19 = load i64, i64* %8
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 %19)
br label %24
21: ; preds = %3
%22 = load i8*, i8** %4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %12
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [31 x i8] c"Successfully wrote %lu bytes.\0A\00"
@.str.2 = [28 x i8] c"error: Unable to open: %s.\0A\00"
define i32 @putData(i8* %0, i64 %1, i8* nocapture %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 %10, label %6
6: ; preds = %3
%7 = tail call i64 @fwrite(i8* %2, i32 1, i64 %1, i32* %4)
%8 = tail call i32 @fclose(i32* %4)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i64 %7)
br label %12
10: ; preds = %3
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %12
12: ; preds = %10, %6
ret i32 0
}