#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 */
struct hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ hostname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int LOG_ERR;
int LOG_USER;
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *, char *,
                           char const *, char const *, char const *,
                           char const *);
struct hostent *gethostbyname(char *);
scalar_t__ gethostname(char *, int);
int h_errno;
int /*<<< orphan*/ *popen(char const *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *);
int /*<<< orphan*/ strerror(int);
int /*<<< orphan*/ syslog(int, char *, ...);
int send_mail(const char *exe_name, const char *core_dir, const char *core_name,
              const char *email) {
  char hostname[255];
  struct hostent *fqdn;
  const char *fqdn_name;
  FILE *fp;
  if (!email)
    return 0;
  fp = popen(email, "w");
  if (!fp) {
    int err = errno;
    syslog(LOG_USER | LOG_ERR, "popen(%s) error: %d (%s)", email, err,
           strerror(err));
    return err;
  }
  if (gethostname(hostname, sizeof(hostname))) {
    int err = errno;
    syslog(LOG_USER | LOG_ERR, "gethostname error: %d (%s)", err,
           strerror(err));
    snprintf(hostname, sizeof(hostname), "(unknown-host)");
  }
  fqdn = gethostbyname(hostname);
  if (!fqdn) {
    int err = h_errno;
    syslog(LOG_USER | LOG_ERR, "gethostbyname(%s) error: %d", hostname, err);
    fqdn_name = hostname;
  } else {
    fqdn_name = fqdn->h_name;
  }
  fprintf(
      fp,
      "Subject: [core_dump] %s crashed on %s\r\n\r\n!!!!! Crash encountered on "
      "%s !!!!!!!!!\r\nexecutable name: %s\r\ncore file name: %s/%s\r\n",
      exe_name, hostname, fqdn_name, exe_name, core_dir, core_name);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<send_mail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11b2 <send_mail+0x32>
movl   $0x0,-0x4(%rbp)
jmp    13ad <send_mail+0x22d>
mov    -0x28(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1080 <popen@plt>
mov    %rax,-0x148(%rbp)
cmpq   $0x0,-0x148(%rbp)
jne    1252 <send_mail+0xd2>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14c(%rbp)
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    0x2dca(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x164(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x160(%rbp)
mov    -0x14c(%rbp),%eax
mov    %eax,-0x158(%rbp)
mov    -0x14c(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x164(%rbp),%edi
mov    -0x160(%rbp),%rdx
mov    -0x158(%rbp),%ecx
mov    %eax,%r8d
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
mov    -0x14c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13ad <send_mail+0x22d>
lea    -0x130(%rbp),%rdi
mov    $0xff,%esi
call   1090 <gethostname@plt>
cmp    $0x0,%rax
je     12df <send_mail+0x15f>
mov    0x2d5c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x150(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    0x2d34(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x16c(%rbp)
mov    -0x150(%rbp),%eax
mov    %eax,-0x168(%rbp)
mov    -0x150(%rbp),%edi
call   10a0 <strerror@plt>
mov    -0x16c(%rbp),%edi
mov    -0x168(%rbp),%edx
mov    %eax,%ecx
lea    0xd5b(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
lea    -0x130(%rbp),%rdi
mov    $0xff,%esi
lea    0xd5c(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x130(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x138(%rbp)
cmpq   $0x0,-0x138(%rbp)
jne    134f <send_mail+0x1cf>
mov    0x2cd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x154(%rbp)
mov    0x2cd2(%rip),%rax
mov    (%rax),%edi
mov    0x2ca1(%rip),%rax
or     (%rax),%edi
lea    -0x130(%rbp),%rdx
mov    -0x154(%rbp),%ecx
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1070 <syslog@plt>
lea    -0x130(%rbp),%rax
mov    %rax,-0x140(%rbp)
jmp    1360 <send_mail+0x1e0>
mov    -0x138(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x140(%rbp)
mov    -0x148(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x130(%rbp),%rcx
mov    -0x140(%rbp),%r8
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%r10
mov    -0x20(%rbp),%rax
lea    0xcd5(%rip),%rsi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1060 <fprintf@plt>
mov    -0x148(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x180,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<send_mail>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
xor    %r13d,%r13d
test   %rcx,%rcx
je     12e6 <send_mail+0x166>
mov    %rcx,%rbp
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe50(%rip),%rsi
mov    %rcx,%rdi
call   1080 <popen@plt>
test   %rax,%rax
je     124e <send_mail+0xce>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
call   1090 <gethostname@plt>
test   %rax,%rax
je     1237 <send_mail+0xb7>
mov    0x2df1(%rip),%rax
mov    (%rax),%ebp
mov    0x2e00(%rip),%rax
mov    0x2dd1(%rip),%rcx
mov    %r15,0x8(%rsp)
mov    %r14,%r15
mov    (%rcx),%r14d
or     (%rax),%r14d
mov    %ebp,%edi
call   10a0 <strerror@plt>
lea    0xe10(%rip),%rsi
mov    %r14d,%edi
mov    %r15,%r14
mov    0x8(%rsp),%r15
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <syslog@plt>
lea    0xe0e(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0xff,%esi
call   1040 <snprintf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     128d <send_mail+0x10d>
mov    (%rax),%rbp
jmp    12b9 <send_mail+0x139>
mov    0x2d7b(%rip),%rax
mov    (%rax),%r13d
mov    0x2d89(%rip),%rax
mov    0x2d5a(%rip),%rcx
mov    (%rcx),%ebx
or     (%rax),%ebx
mov    %r13d,%edi
call   10a0 <strerror@plt>
lea    0xd89(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %r13d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1070 <syslog@plt>
jmp    12e6 <send_mail+0x166>
mov    0x2d4c(%rip),%rax
mov    (%rax),%ecx
mov    0x2d4b(%rip),%rax
mov    0x2d1c(%rip),%rdx
mov    (%rdx),%edi
or     (%rax),%edi
lea    0xd96(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1070 <syslog@plt>
lea    0xda1(%rip),%rsi
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %r12,%rdx
mov    %rbp,%r8
mov    %r12,%r9
push   %r15
push   %r14
call   1060 <fprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r13d,%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.hostent = type { i8* }
@.str = [2 x i8] c"w\00"
@errno = global i32 0
@LOG_USER = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [25 x i8] c"popen(%s) error: %d (%s)\00"
@.str.2 = [27 x i8] c"gethostname error: %d (%s)\00"
@.str.3 = [15 x i8] c"(unknown-host)\00"
@h_errno = global i32 0
@.str.4 = [28 x i8] c"gethostbyname(%s) error: %d\00"
@.str.5 = [127 x i8] c"Subject: [core_dump] %s crashed on %s\0D\0A\0D\0A!!!!! Crash encountered on %s !!!!!!!!!\0D\0Aexecutable name: %s\0D\0Acore file name: %s/%s\0D\0A\00"
define i32 @send_mail(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [255 x i8]
%11 = alloca %struct.hostent*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
%17 = load i8*, i8** %9
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %4
store i32 0, i32* %5
br label %80
20: ; preds = %4
%21 = load i8*, i8** %9
%22 = call i32* @popen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %22, i32** %13
%23 = load i32*, i32** %13
%24 = icmp ne i32* %23, null
br i1 %24, label %36, label %25
25: ; preds = %20
%26 = load i32, i32* @errno
store i32 %26, i32* %14
%27 = load i32, i32* @LOG_USER
%28 = load i32, i32* @LOG_ERR
%29 = or i32 %27, %28
%30 = load i8*, i8** %9
%31 = load i32, i32* %14
%32 = load i32, i32* %14
%33 = call i32 @strerror(i32 %32)
%34 = call i32 (i32, i8*, ...) @syslog(i32 %29, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %30, i32 %31, i32 %33)
%35 = load i32, i32* %14
store i32 %35, i32* %5
br label %80
36: ; preds = %20
%37 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%38 = call i64 @gethostname(i8* %37, i32 255)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %36
%41 = load i32, i32* @errno
store i32 %41, i32* %15
%42 = load i32, i32* @LOG_USER
%43 = load i32, i32* @LOG_ERR
%44 = or i32 %42, %43
%45 = load i32, i32* %15
%46 = load i32, i32* %15
%47 = call i32 @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @syslog(i32 %44, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %45, i32 %47)
%49 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%50 = call i32 @snprintf(i8* %49, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %51
51: ; preds = %40, %36
%52 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%53 = call %struct.hostent* @gethostbyname(i8* %52)
store %struct.hostent* %53, %struct.hostent** %11
%54 = load %struct.hostent*, %struct.hostent** %11
%55 = icmp ne %struct.hostent* %54, null
br i1 %55, label %65, label %56
56: ; preds = %51
%57 = load i32, i32* @h_errno
store i32 %57, i32* %16
%58 = load i32, i32* @LOG_USER
%59 = load i32, i32* @LOG_ERR
%60 = or i32 %58, %59
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%62 = load i32, i32* %16
%63 = call i32 (i32, i8*, ...) @syslog(i32 %60, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %61, i32 %62)
%64 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
store i8* %64, i8** %12
br label %69
65: ; preds = %51
%66 = load %struct.hostent*, %struct.hostent** %11
%67 = getelementptr inbounds %struct.hostent, %struct.hostent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
store i8* %68, i8** %12
br label %69
69: ; preds = %65, %56
%70 = load i32*, i32** %13
%71 = load i8*, i8** %6
%72 = getelementptr inbounds [255 x i8], [255 x i8]* %10, i64 0, i64 0
%73 = load i8*, i8** %12
%74 = load i8*, i8** %6
%75 = load i8*, i8** %7
%76 = load i8*, i8** %8
%77 = call i32 @fprintf(i32* %70, i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str.5, i64 0, i64 0), i8* %71, i8* %72, i8* %73, i8* %74, i8* %75, i8* %76)
%78 = load i32*, i32** %13
%79 = call i32 @fclose(i32* %78)
store i32 0, i32* %5
br label %80
80: ; preds = %69, %25, %19
%81 = load i32, i32* %5
ret i32 %81
}

LLVM IR (-O2):
%struct.hostent = type { i8* }
@.str = [2 x i8] c"w\00"
@errno = global i32 0
@LOG_USER = global i32 0
@LOG_ERR = global i32 0
@.str.1 = [25 x i8] c"popen(%s) error: %d (%s)\00"
@.str.2 = [27 x i8] c"gethostname error: %d (%s)\00"
@.str.3 = [15 x i8] c"(unknown-host)\00"
@h_errno = global i32 0
@.str.4 = [28 x i8] c"gethostbyname(%s) error: %d\00"
@.str.5 = [127 x i8] c"Subject: [core_dump] %s crashed on %s\0D\0A\0D\0A!!!!! Crash encountered on %s !!!!!!!!!\0D\0Aexecutable name: %s\0D\0Acore file name: %s/%s\0D\0A\00"
define i32 @send_mail(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca [255 x i8]
%6 = getelementptr inbounds [255 x i8], [255 x i8]* %5, i64 0, i64 0
%7 = icmp eq i8* %3, null
br i1 %7, label %45, label %8
8: ; preds = %4
%9 = tail call i32* @popen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* @errno
%13 = load i32, i32* @LOG_USER
%14 = load i32, i32* @LOG_ERR
%15 = or i32 %14, %13
%16 = tail call i32 @strerror(i32 %12)
%17 = tail call i32 (i32, i8*, ...) @syslog(i32 %15, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %12, i32 %16)
br label %45
18: ; preds = %8
%19 = call i64 @gethostname(i8* %6, i32 255)
%20 = icmp eq i64 %19, 0
br i1 %20, label %29, label %21
21: ; preds = %18
%22 = load i32, i32* @errno
%23 = load i32, i32* @LOG_USER
%24 = load i32, i32* @LOG_ERR
%25 = or i32 %24, %23
%26 = call i32 @strerror(i32 %22)
%27 = call i32 (i32, i8*, ...) @syslog(i32 %25, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %22, i32 %26)
%28 = call i32 @snprintf(i8* %6, i32 255, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %21, %18
%30 = call %struct.hostent* @gethostbyname(i8* %6)
%31 = icmp eq %struct.hostent* %30, null
br i1 %31, label %32, label %38
32: ; preds = %29
%33 = load i32, i32* @h_errno
%34 = load i32, i32* @LOG_USER
%35 = load i32, i32* @LOG_ERR
%36 = or i32 %35, %34
%37 = call i32 (i32, i8*, ...) @syslog(i32 %36, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %6, i32 %33)
br label %41
38: ; preds = %29
%39 = getelementptr inbounds %struct.hostent, %struct.hostent* %30, i64 0, i32 0
%40 = load i8*, i8** %39
br label %41
41: ; preds = %38, %32
%42 = phi i8* [ %40, %38 ], [ %6, %32 ]
%43 = call i32 @fprintf(i32* %9, i8* getelementptr inbounds ([127 x i8], [127 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %6, i8* %42, i8* %0, i8* %1, i8* %2)
%44 = call i32 @fclose(i32* %9)
br label %45
45: ; preds = %4, %41, %11
%46 = phi i32 [ 0, %41 ], [ %12, %11 ], [ 0, %4 ]
ret i32 %46
}