#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*/ err(char *, ...);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int pclose(int /*<<< orphan*/ *);
int close_sendmail(FILE *fp) {
  int status;
  fflush(fp);
  if (ferror(fp)) {
    err("error writing to sendmail");
    return 0;
  }
  if ((status = pclose(fp)) != 0)
    err("sendmail failed with status %d", status);
  return (status == 0);
}


x86 assembly (clang, -O0):
<close_sendmail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fflush@plt>
mov    -0x10(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1182 <close_sendmail+0x42>
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1050 <err@plt>
movl   $0x0,-0x4(%rbp)
jmp    11b7 <close_sendmail+0x77>
mov    -0x10(%rbp),%rdi
call   1040 <pclose@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     11a8 <close_sendmail+0x68>
mov    -0x14(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1050 <err@plt>
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<close_sendmail>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <fflush@plt>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     116a <close_sendmail+0x2a>
lea    0xea1(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <err@plt>
jmp    1190 <close_sendmail+0x50>
mov    %rbx,%rdi
call   1040 <pclose@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1188 <close_sendmail+0x48>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <err@plt>
xor    %ebp,%ebp
test   %ebx,%ebx
sete   %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"error writing to sendmail\00"
@.str.1 = [31 x i8] c"sendmail failed with status %d\00"
define i32 @close_sendmail(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
store i32* %0, i32** %3
%5 = load i32*, i32** %3
%6 = call i32 @fflush(i32* %5)
%7 = load i32*, i32** %3
%8 = call i64 @ferror(i32* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 (i8*, ...) @err(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %23
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call i32 @pclose(i32* %13)
store i32 %14, i32* %4
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* %4
%18 = call i32 (i8*, ...) @err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %12
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
store i32 %22, i32* %2
br label %23
23: ; preds = %19, %10
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [26 x i8] c"error writing to sendmail\00"
@.str.1 = [31 x i8] c"sendmail failed with status %d\00"
define i32 @close_sendmail(i32* nocapture %0) {
%2 = tail call i32 @fflush(i32* %0)
%3 = tail call i64 @ferror(i32* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = tail call i32 (i8*, ...) @err(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %14
7: ; preds = %1
%8 = tail call i32 @pclose(i32* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @err(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %8)
br label %12
12: ; preds = %10, %7
%13 = zext i1 %9 to i32
br label %14
14: ; preds = %12, %5
%15 = phi i32 [ 0, %5 ], [ %13, %12 ]
ret i32 %15
}