#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 *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int main() {
  FILE *f = fopen("test", "wb");
  char buf[] = "abcdefg";
  if (fwrite(buf, 1, 5, f) != 5)
    return -1;
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    0xeab(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x5,%edx
call   1050 <fwrite@plt>
cmp    $0x5,%eax
je     118d <main+0x5d>
movl   $0xffffffff,-0x4(%rbp)
jmp    119d <main+0x6d>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,%rbx
movabs $0x67666564636261,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x5,%edx
mov    %rbx,%rcx
call   1050 <fwrite@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0x5,%ecx
jne    1187 <main+0x57>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [5 x i8] c"test\00"
@.str.1 = [3 x i8] c"wb\00"
@__const.main.buf = [8 x i8] c"abcdefg\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca [8 x i8]
store i32 0, i32* %1
%4 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = bitcast [8 x i8]* %3 to i8*
%6 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%7 = load i32*, i32** %2
%8 = call i32 @fwrite(i8* %6, i32 1, i32 5, i32* %7)
%9 = icmp ne i32 %8, 5
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %14
11: ; preds = %0
%12 = load i32*, i32** %2
%13 = call i32 @fclose(i32* %12)
store i32 0, i32* %1
br label %14
14: ; preds = %11, %10
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
@.str = [5 x i8] c"test\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @main() {
%1 = alloca i64
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%3 = bitcast i64* %1 to i8*
store i64 29104508263162465, i64* %1
%4 = call i32 @fwrite(i8* %3, i32 1, i32 5, i32* %2)
%5 = icmp eq i32 %4, 5
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @fclose(i32* %2)
br label %8
8: ; preds = %0, %6
%9 = phi i32 [ 0, %6 ], [ -1, %0 ]
ret i32 %9
}