#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 /*<<< orphan*/ fwrite(char *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
int main() {
  FILE *fp;
  char input[100] = "fwrite test string\n";
  fp = fopen("fwrite.txt", "w");
  if (fp == NULL)
    return -1;
  fwrite(input, strlen(input), 1, fp);
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe93(%rip),%rsi
mov    $0x64,%edx
call   1050 <memcpy@plt>
lea    0xee6(%rip),%rdi
lea    0xeea(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a5 <main+0x55>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <main+0x89>
lea    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movaps 0xf02(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xee6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeca(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xeae(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe92(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe76(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xec7(%rip),%rdi
lea    0xecb(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11da <main+0x9a>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1060 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11df <main+0x9f>
mov    $0xffffffff,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

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

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