#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 */
scalar_t__ fclose(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ weprintf(char *, char const *);
int fshut(FILE *fp, const char *fname) {
  int ret = 0;
  fflush(fp);
  if (ferror(fp) && !ret) {
    weprintf("ferror %s:", fname);
    ret = 1;
  }
  if (fclose(fp) && !ret) {
    weprintf("fclose %s:", fname);
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<fshut>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <fflush@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1194 <fshut+0x54>
cmpl   $0x0,-0x14(%rbp)
jne    1194 <fshut+0x54>
mov    -0x10(%rbp),%rsi
lea    0xe78(%rip),%rdi
call   1060 <weprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     11c8 <fshut+0x88>
cmpl   $0x0,-0x14(%rbp)
jne    11c8 <fshut+0x88>
mov    -0x10(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1060 <weprintf@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fshut>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1050 <fflush@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1175 <fshut+0x35>
lea    0xe9d(%rip),%rdi
mov    %r14,%rsi
call   1060 <weprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1191 <fshut+0x51>
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     119e <fshut+0x5e>
lea    0xe82(%rip),%rdi
mov    %r14,%rsi
call   1060 <weprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
jmp    1196 <fshut+0x56>

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

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