#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*/ clearerr(int /*<<< orphan*/ *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int fwrite(char *, unsigned long, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_error(char *, char *);
int id3_write_file(char *src, unsigned long size, FILE *fp, char *fn) {
  if (fwrite(src, size, 1, fp) != 1) {
    print_error("id3_write_file: Error writing to %s", fn);
    fclose(fp);
    return 0;
  }
  if (ferror(fp) != 0) {
    print_error("id3_write_file: Error writing to %s", fn);
    clearerr(fp);
    fclose(fp);
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<id3_write_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
je     11ac <id3_write_file+0x5c>
mov    -0x28(%rbp),%rsi
lea    0xe6e(%rip),%rdi
call   1040 <print_error@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <id3_write_file+0xa4>
mov    -0x20(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ed <id3_write_file+0x9d>
mov    -0x28(%rbp),%rsi
lea    0xe36(%rip),%rdi
call   1040 <print_error@plt>
mov    -0x20(%rbp),%rdi
call   1060 <clearerr@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11f4 <id3_write_file+0xa4>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3_write_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%r14
mov    %rdx,%rbx
mov    $0x1,%ebp
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fwrite@plt>
cmp    $0x1,%eax
jne    1197 <id3_write_file+0x47>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     11b0 <id3_write_file+0x60>
lea    0xe7b(%rip),%rdi
mov    %r14,%rsi
call   1040 <print_error@plt>
mov    %rbx,%rdi
call   1060 <clearerr@plt>
jmp    11a6 <id3_write_file+0x56>
lea    0xe62(%rip),%rdi
mov    %r14,%rsi
call   1040 <print_error@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [36 x i8] c"id3_write_file: Error writing to %s\00"
define i32 @id3_write_file(i8* %0, i64 %1, i32* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32* %2, i32** %8
store i8* %3, i8** %9
%10 = load i8*, i8** %6
%11 = load i64, i64* %7
%12 = load i32*, i32** %8
%13 = call i32 @fwrite(i8* %10, i64 %11, i32 1, i32* %12)
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %20
15: ; preds = %4
%16 = load i8*, i8** %9
%17 = call i32 @print_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32*, i32** %8
%19 = call i32 @fclose(i32* %18)
store i32 0, i32* %5
br label %32
20: ; preds = %4
%21 = load i32*, i32** %8
%22 = call i64 @ferror(i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i8*, i8** %9
%26 = call i32 @print_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %8
%28 = call i32 @clearerr(i32* %27)
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %5
br label %32
31: ; preds = %20
store i32 1, i32* %5
br label %32
32: ; preds = %31, %24, %15
%33 = load i32, i32* %5
ret i32 %33
}

LLVM IR (-O2):
@.str = [36 x i8] c"id3_write_file: Error writing to %s\00"
define i32 @id3_write_file(i8* nocapture %0, i64 %1, i32* nocapture %2, i8* %3) {
%5 = tail call i32 @fwrite(i8* %0, i64 %1, i32 1, i32* %2)
%6 = icmp eq i32 %5, 1
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = tail call i32 @print_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %15
9: ; preds = %4
%10 = tail call i64 @ferror(i32* %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = tail call i32 @print_error(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %3)
%14 = tail call i32 @clearerr(i32* %2)
br label %15
15: ; preds = %7, %12
%16 = tail call i32 @fclose(i32* %2)
br label %17
17: ; preds = %15, %9
%18 = phi i32 [ 1, %9 ], [ 0, %15 ]
ret i32 %18
}