#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, int, int /*<<< orphan*/ *);
int write_block(char *fname, void *block) {
  FILE *f;
  size_t wrt;
  f = fopen(fname, "wb");
  if (f == NULL)
    return 1;
  wrt = fwrite(block, 1, 128, f);
  fclose(f);
  if (wrt == 128)
    return 0;
  return 2;
}


x86 assembly (clang, -O0):
<write_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb5(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    116b <write_block+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11b0 <write_block+0x80>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
mov    $0x80,%edx
call   1050 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
cmpq   $0x80,-0x28(%rbp)
jne    11a9 <write_block+0x79>
movl   $0x0,-0x4(%rbp)
jmp    11b0 <write_block+0x80>
movl   $0x2,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_block>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbp
lea    0xec3(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1177 <write_block+0x47>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x80,%edx
mov    %rax,%rcx
call   1050 <fwrite@plt>
xor    %ebp,%ebp
cmp    $0x80,%rax
setne  %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    %ebp,%ebp
jmp    117c <write_block+0x4c>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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