#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 scalar_t__ off_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ close_sendmail(int /*<<< orphan*/ *);
int /*<<< orphan*/ err(char *, char *);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ *open_sendmail();
int /*<<< orphan*/ sprintf(char *, char *, char *, char *, int, int);
int /*<<< orphan*/ unlink(char *);
int apologise(char *delta, off_t ctm_size, long max_ctm_size, char *mail_alias,
              char *queue_dir) {
  FILE *sfp;
  char qname[PATH_MAX];
  if (queue_dir == NULL) {
    sfp = open_sendmail();
    if (sfp == NULL)
      return 1;
  } else {
    sprintf((qname), "%s/%s+%03d-%03d", (queue_dir), (delta), (1), (1));
    sfp = fopen(qname, "w");
    if (sfp == NULL) {
      err("cannot open '%s' for writing", qname);
      return 1;
    }
  }
  fprintf(sfp, "From: owner-%s\n", mail_alias);
  fprintf(sfp, "To: %s\n", mail_alias);
  fprintf(sfp, "Subject: ctm-notice %s\n\n", delta);
  fprintf(sfp, "%s is %ld bytes.  The limit is %ld bytes.\n\n", delta,
          (long)ctm_size, max_ctm_size);
  fprintf(sfp, "You can retrieve this delta via ftp.\n");
  if (queue_dir == NULL) {
    if (!close_sendmail(sfp))
      return 1;
  } else {
    if (fclose(sfp) != 0) {
      err("error writing '%s'", qname);
      unlink(qname);
      return 1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<apologise>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1201 <apologise+0x81>
mov    $0x0,%al
call   10a0 <open_sendmail@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11fc <apologise+0x7c>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1362 <apologise+0x1e2>
jmp    1269 <apologise+0xe9>
mov    -0x58(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdec(%rip),%rsi
mov    $0x1,%r9d
mov    %r9d,%r8d
call   1090 <sprintf@plt>
mov    -0x58(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1264 <apologise+0xe4>
mov    -0x58(%rbp),%rsi
lea    0xdc6(%rip),%rdi
call   1070 <err@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1362 <apologise+0x1e2>
jmp    1269 <apologise+0xe9>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdb7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1310 <apologise+0x190>
mov    -0x38(%rbp),%rdi
call   1060 <close_sendmail@plt>
cmp    $0x0,%eax
jne    130b <apologise+0x18b>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1362 <apologise+0x1e2>
jmp    1354 <apologise+0x1d4>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     134f <apologise+0x1cf>
mov    -0x58(%rbp),%rsi
lea    0xd84(%rip),%rdi
call   1070 <err@plt>
mov    -0x58(%rbp),%rdi
call   1030 <unlink@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1362 <apologise+0x1e2>
jmp    1354 <apologise+0x1d4>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apologise>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r13
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
test   %r8,%r8
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %r8,-0x30(%rbp)
mov    %rcx,%rbx
je     1224 <apologise+0x94>
lea    0xe27(%rip),%rsi
mov    $0x1,%r15d
mov    %r14,%rdi
mov    %r8,%rdx
mov    %r13,%rcx
mov    $0x1,%r8d
mov    $0x1,%r9d
call   1090 <sprintf@plt>
lea    0xe10(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1237 <apologise+0xa7>
lea    0xdfb(%rip),%rdi
mov    %r14,%rsi
call   1070 <err@plt>
jmp    12ec <apologise+0x15c>
xor    %eax,%eax
call   10b0 <open_sendmail@plt>
mov    %rax,%r12
test   %rax,%rax
je     12e6 <apologise+0x156>
lea    0xdf1(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xded(%rip),%rsi
mov    %r12,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xde1(%rip),%rsi
mov    %r12,%rdi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xde6(%rip),%rsi
mov    %r12,%rdi
mov    %r13,%rdx
mov    -0x38(%rbp),%rcx
mov    -0x40(%rbp),%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xdf6(%rip),%rdi
mov    $0x25,%esi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
cmpq   $0x0,-0x30(%rbp)
je     12d5 <apologise+0x145>
mov    %r12,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     12e1 <apologise+0x151>
lea    0xdef(%rip),%rdi
mov    %r14,%rsi
call   1070 <err@plt>
mov    %r14,%rdi
call   1030 <unlink@plt>
jmp    12e6 <apologise+0x156>
mov    %r12,%rdi
call   1060 <close_sendmail@plt>
test   %eax,%eax
je     12e6 <apologise+0x156>
xor    %r15d,%r15d
jmp    12ec <apologise+0x15c>
mov    $0x1,%r15d
mov    %r15d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [16 x i8] c"%s/%s+%03d-%03d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"cannot open '%s' for writing\00"
@.str.3 = [16 x i8] c"From: owner-%s\0A\00"
@.str.4 = [8 x i8] c"To: %s\0A\00"
@.str.5 = [25 x i8] c"Subject: ctm-notice %s\0A\0A\00"
@.str.6 = [44 x i8] c"%s is %ld bytes. The limit is %ld bytes.\0A\0A\00"
@.str.7 = [38 x i8] c"You can retrieve this delta via ftp.\0A\00"
@.str.8 = [19 x i8] c"error writing '%s'\00"
define i32 @apologise(i8* %0, i64 %1, i64 %2, i8* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i32
store i8* %0, i8** %7
store i64 %1, i64* %8
store i64 %2, i64* %9
store i8* %3, i8** %10
store i8* %4, i8** %11
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %13
%19 = alloca i8, i64 %17
store i64 %17, i64* %14
%20 = load i8*, i8** %11
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %28
22: ; preds = %5
%23 = call i32* (...) @open_sendmail()
store i32* %23, i32** %12
%24 = load i32*, i32** %12
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 1, i32* %6
store i32 1, i32* %15
br label %72
27: ; preds = %22
br label %38
28: ; preds = %5
%29 = load i8*, i8** %11
%30 = load i8*, i8** %7
%31 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %29, i8* %30, i32 1, i32 1)
%32 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %32, i32** %12
%33 = load i32*, i32** %12
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %37
35: ; preds = %28
%36 = call i32 @err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %19)
store i32 1, i32* %6
store i32 1, i32* %15
br label %72
37: ; preds = %28
br label %38
38: ; preds = %37, %27
%39 = load i32*, i32** %12
%40 = load i8*, i8** %10
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = load i32*, i32** %12
%43 = load i8*, i8** %10
%44 = call i32 (i32*, i8*, ...) @fprintf(i32* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %12
%46 = load i8*, i8** %7
%47 = call i32 (i32*, i8*, ...) @fprintf(i32* %45, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %46)
%48 = load i32*, i32** %12
%49 = load i8*, i8** %7
%50 = load i64, i64* %8
%51 = load i64, i64* %9
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %48, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %49, i64 %50, i64 %51)
%53 = load i32*, i32** %12
%54 = call i32 (i32*, i8*, ...) @fprintf(i32* %53, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0))
%55 = load i8*, i8** %11
%56 = icmp eq i8* %55, null
br i1 %56, label %57, label %63
57: ; preds = %38
%58 = load i32*, i32** %12
%59 = call i32 @close_sendmail(i32* %58)
%60 = icmp ne i32 %59, 0
br i1 %60, label %62, label %61
61: ; preds = %57
store i32 1, i32* %6
store i32 1, i32* %15
br label %72
62: ; preds = %57
br label %71
63: ; preds = %38
%64 = load i32*, i32** %12
%65 = call i64 @fclose(i32* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %70
67: ; preds = %63
%68 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %19)
%69 = call i32 @unlink(i8* %19)
store i32 1, i32* %6
store i32 1, i32* %15
br label %72
70: ; preds = %63
br label %71
71: ; preds = %70, %62
store i32 0, i32* %6
store i32 1, i32* %15
br label %72
72: ; preds = %71, %67, %61, %35, %26
%73 = load i8*, i8** %13
%74 = load i32, i32* %6
ret i32 %74
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@.str = [16 x i8] c"%s/%s+%03d-%03d\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [29 x i8] c"cannot open '%s' for writing\00"
@.str.3 = [16 x i8] c"From: owner-%s\0A\00"
@.str.4 = [8 x i8] c"To: %s\0A\00"
@.str.5 = [25 x i8] c"Subject: ctm-notice %s\0A\0A\00"
@.str.6 = [44 x i8] c"%s is %ld bytes. The limit is %ld bytes.\0A\0A\00"
@.str.7 = [38 x i8] c"You can retrieve this delta via ftp.\0A\00"
@.str.8 = [19 x i8] c"error writing '%s'\00"
define i32 @apologise(i8* %0, i64 %1, i64 %2, i8* %3, i8* %4) {
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = icmp eq i8* %4, null
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = tail call i32* (...) @open_sendmail()
%12 = icmp eq i32* %11, null
br i1 %12, label %36, label %19
13: ; preds = %5
%14 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %4, i8* %0, i32 1, i32 1)
%15 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @err(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %36
19: ; preds = %13, %10
%20 = phi i32* [ %11, %10 ], [ %15, %13 ]
%21 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%22 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %3)
%23 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %0)
%24 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0), i8* %0, i64 %1, i64 %2)
%25 = tail call i64 @fwrite(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i64 37, i64 1, i32* %20)
br i1 %9, label %26, label %29
26: ; preds = %19
%27 = tail call i32 @close_sendmail(i32* %20)
%28 = icmp eq i32 %27, 0
br i1 %28, label %36, label %35
29: ; preds = %19
%30 = tail call i64 @fclose(i32* %20)
%31 = icmp eq i64 %30, 0
br i1 %31, label %35, label %32
32: ; preds = %29
%33 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %8)
%34 = call i32 @unlink(i8* %8)
br label %36
35: ; preds = %29, %26
br label %36
36: ; preds = %26, %10, %35, %32, %17
%37 = phi i32 [ 0, %35 ], [ 1, %32 ], [ 1, %17 ], [ 1, %10 ], [ 1, %26 ]
ret i32 %37
}