#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__ time_t;
typedef int pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ execv(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char const *);
int /*<<< orphan*/ msg(char *, int, ...);
int open(char *, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ pipe(int *);
int /*<<< orphan*/ strerror(scalar_t__);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ usleep(int);
int waitpid(int, int *, int /*<<< orphan*/);
int mail_send(const char *body) {
  char *argv[] = {"/undeadly.org/mini_sendmail", "-t", NULL};
  int fd[2], r, status;
  pid_t pid;
  FILE *f;
  time_t t;
  if (pipe(fd)) {
    msg("error mail_send: pipe: %s", strerror(errno));
    return (1);
  }
  if ((pid = fork()) < 0) {
    msg("error mail_send: fork: %s", strerror(errno));
    close(fd[0]);
    close(fd[1]);
    return (1);
  }
  if (!pid) {
    close(fd[1]);
    dup2(fd[0], STDIN_FILENO);
    dup2(open("/dev/null", O_WRONLY, 0), STDOUT_FILENO);
    dup2(open("/dev/null", O_WRONLY, 0), STDERR_FILENO);
    execv(argv[0], argv);
    exit(EXIT_FAILURE);
  }
  close(fd[0]);
  if (!(f = fdopen(fd[1], "w"))) {
    msg("error mail_send: fdopen: %s", strerror(errno));
    close(fd[1]);
    return (1);
  }
  fprintf(f, "%s\n", body);
  fflush(f);
  fclose(f);
  t = time(NULL) + 10;
  do {
    usleep(10000);
    r = waitpid(pid, &status, WNOHANG);
    if (r < 0) {
      if (errno != EINTR && errno != EAGAIN)
        msg("error mail_send: waitpid: %s", strerror(errno));
      else
        r = 0;
    }
  } while (!r && time(NULL) < t);
  if (!r) {
    msg("error mail_send: timeout waiting for child %u", (unsigned)pid);
    return (1);
  }
  if (r != pid) {
    msg("error mail_send: waitpid returned %u for child %u", (unsigned)r,
        (unsigned)pid);
    return (1);
  }
  if (!WIFEXITED(status)) {
    msg("error mail_send: abnormal exit of chhild %u", (unsigned)pid);
    return (1);
  }
  if (WEXITSTATUS(status)) {
    msg("error mail_send: exit status %d from child %u",
        (int)WEXITSTATUS(status), (unsigned)pid);
    return (1);
  }
  return (0);
}


x86 assembly (clang, -O0):
<mail_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2b8d(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0x2b8a(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2b87(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x38(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
je     128b <mail_send+0x6b>
mov    0x2d69(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xda7(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
mov    $0x0,%al
call   1120 <fork@plt>
mov    %eax,-0x44(%rbp)
cmp    $0x0,%eax
jge    12d9 <mail_send+0xb9>
mov    0x2d2b(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
cmpl   $0x0,-0x44(%rbp)
jne    1365 <mail_send+0x145>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%edi
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
lea    0xd47(%rip),%rdi
xor    %edx,%edx
call   10d0 <open@plt>
mov    %eax,%edi
mov    0x2cd4(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%esi
lea    0xd20(%rip),%rdi
xor    %edx,%edx
call   10d0 <open@plt>
mov    %eax,%edi
mov    0x2c85(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    -0x30(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1110 <execv@plt>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%edi
lea    0xce6(%rip),%rsi
call   10a0 <fdopen@plt>
mov    %rax,-0x50(%rbp)
cmp    $0x0,%rax
jne    13bd <mail_send+0x19d>
mov    0x2c3f(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xcbd(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xcaf(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
add    $0xa,%rax
mov    %rax,-0x58(%rbp)
mov    $0x2710,%edi
call   1140 <usleep@plt>
mov    -0x44(%rbp),%edi
mov    0x2bd8(%rip),%rax
mov    (%rax),%edx
lea    -0x40(%rbp),%rsi
call   10c0 <waitpid@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jge    1484 <mail_send+0x264>
mov    0x2ba9(%rip),%rax
mov    (%rax),%rax
mov    0x2b87(%rip),%rcx
cmp    (%rcx),%rax
je     1478 <mail_send+0x258>
mov    0x2b8f(%rip),%rax
mov    (%rax),%rax
mov    0x2b4d(%rip),%rcx
cmp    (%rcx),%rax
je     1478 <mail_send+0x258>
mov    0x2b75(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
mov    %eax,%esi
lea    0xc13(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
jmp    147f <mail_send+0x25f>
movl   $0x0,-0x3c(%rbp)
jmp    1484 <mail_send+0x264>
jmp    1489 <mail_send+0x269>
xor    %eax,%eax
cmpl   $0x0,-0x3c(%rbp)
mov    %al,-0x59(%rbp)
jne    14ab <mail_send+0x28b>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <time@plt>
cmp    -0x58(%rbp),%rax
setl   %al
mov    %al,-0x59(%rbp)
mov    -0x59(%rbp),%al
test   $0x1,%al
jne    13f4 <mail_send+0x1d4>
cmpl   $0x0,-0x3c(%rbp)
jne    14dd <mail_send+0x2bd>
mov    -0x44(%rbp),%esi
lea    0xbd2(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
mov    -0x3c(%rbp),%eax
cmp    -0x44(%rbp),%eax
je     1509 <mail_send+0x2e9>
mov    -0x3c(%rbp),%esi
mov    -0x44(%rbp),%edx
lea    0xbd4(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
mov    -0x40(%rbp),%edi
call   10e0 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    1537 <mail_send+0x317>
mov    -0x44(%rbp),%esi
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
mov    -0x40(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     1570 <mail_send+0x350>
mov    -0x40(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
mov    %eax,%esi
mov    -0x44(%rbp),%edx
lea    0xbcb(%rip),%rdi
mov    $0x0,%al
call   1130 <msg@plt>
movl   $0x1,-0x4(%rbp)
jmp    1577 <mail_send+0x357>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mail_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
mov    0x2b98(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0x2b7c(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
je     127c <mail_send+0x5c>
mov    0x2d71(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xdb1(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1130 <msg@plt>
jmp    13f4 <mail_send+0x1d4>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
js     13a2 <mail_send+0x182>
je     1439 <mail_send+0x219>
mov    %eax,%r15d
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
lea    0xdb5(%rip),%rsi
call   10a0 <fdopen@plt>
test   %rax,%rax
je     13cc <mail_send+0x1ac>
mov    %rax,%rbx
lea    0xdbb(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %rbx,%rdi
call   1090 <fflush@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %edi,%edi
call   1080 <time@plt>
mov    %rax,%rbx
add    $0xa,%rbx
mov    0x2cf0(%rip),%r12
lea    0x4(%rsp),%r14
mov    0x2cbc(%rip),%r13
jmp    1312 <mail_send+0xf2>
xchg   %ax,%ax
jne    1362 <mail_send+0x142>
xor    %edi,%edi
call   1080 <time@plt>
cmp    %rbx,%rax
jge    1408 <mail_send+0x1e8>
mov    $0x2710,%edi
call   1140 <usleep@plt>
mov    (%r12),%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   10c0 <waitpid@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1300 <mail_send+0xe0>
mov    0x2c98(%rip),%rax
mov    (%rax),%rdi
cmp    0x0(%r13),%rdi
je     1302 <mail_send+0xe2>
mov    0x2c50(%rip),%rax
cmp    (%rax),%rdi
je     1302 <mail_send+0xe2>
call   1100 <strerror@plt>
lea    0xd26(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1130 <msg@plt>
cmp    %r15d,%ebp
jne    1417 <mail_send+0x1f7>
mov    0x4(%rsp),%edi
call   10e0 <WIFEXITED@plt>
test   %eax,%eax
je     142c <mail_send+0x20c>
mov    0x4(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
test   %rax,%rax
je     1435 <mail_send+0x215>
mov    0x4(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
lea    0xd8a(%rip),%rdi
mov    %eax,%esi
jmp    1420 <mail_send+0x200>
mov    0x2c27(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc81(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1130 <msg@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
jmp    13eb <mail_send+0x1cb>
mov    0x2bfd(%rip),%rax
mov    (%rax),%rdi
call   1100 <strerror@plt>
lea    0xc7d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1130 <msg@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc8d(%rip),%rdi
mov    %r15d,%esi
jmp    1270 <mail_send+0x50>
lea    0xcac(%rip),%rdi
mov    %ebp,%esi
mov    %r15d,%edx
xor    %eax,%eax
call   1130 <msg@plt>
jmp    13f4 <mail_send+0x1d4>
lea    0xcc9(%rip),%rdi
jmp    140f <mail_send+0x1ef>
xor    %eax,%eax
jmp    13f9 <mail_send+0x1d9>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
mov    0x2b63(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
mov    0x2b45(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0xbee(%rip),%rbx
mov    %rbx,%rdi
xor    %edx,%edx
call   10d0 <open@plt>
mov    0x2b7a(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <dup2@plt>
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
xor    %edx,%edx
call   10d0 <open@plt>
mov    0x2b35(%rip),%rcx
mov    (%rcx),%esi
mov    %eax,%edi
call   1040 <dup2@plt>
lea    0xb5d(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1110 <execv@plt>
mov    0x2b0c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"/undeadly.org/mini_sendmail\00"
@.str.1 = [3 x i8] c"-t\00"
@__const.mail_send.argv = [3 x i8*] [i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [26 x i8] c"error mail_send: pipe: %s\00"
@errno = global i64 0
@.str.3 = [26 x i8] c"error mail_send: fork: %s\00"
@STDIN_FILENO = global i32 0
@.str.4 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [28 x i8] c"error mail_send: fdopen: %s\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@WNOHANG = global i32 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str.8 = [29 x i8] c"error mail_send: waitpid: %s\00"
@.str.9 = [46 x i8] c"error mail_send: timeout waiting for child %u\00"
@.str.10 = [50 x i8] c"error mail_send: waitpid returned %u for child %u\00"
@.str.11 = [44 x i8] c"error mail_send: abnormal exit of chhild %u\00"
@.str.12 = [46 x i8] c"error mail_send: exit status %d from child %u\00"
define i32 @mail_send(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [3 x i8*]
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i64
store i8* %0, i8** %3
%11 = bitcast [3 x i8*]* %4 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%13 = call i64 @pipe(i32* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %1
%16 = load i64, i64* @errno
%17 = call i32 @strerror(i64 %16)
%18 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %17)
store i32 1, i32* %2
br label %145
19: ; preds = %1
%20 = call i32 (...) @fork()
store i32 %20, i32* %8
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = call i32 @strerror(i64 %23)
%25 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
store i32 1, i32* %2
br label %145
32: ; preds = %19
%33 = load i32, i32* %8
%34 = icmp ne i32 %33, 0
br i1 %34, label %57, label %35
35: ; preds = %32
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%40 = load i32, i32* %39
%41 = load i32, i32* @STDIN_FILENO
%42 = call i32 @dup2(i32 %40, i32 %41)
%43 = load i32, i32* @O_WRONLY
%44 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %43, i32 0)
%45 = load i32, i32* @STDOUT_FILENO
%46 = call i32 @dup2(i32 %44, i32 %45)
%47 = load i32, i32* @O_WRONLY
%48 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 0)
%49 = load i32, i32* @STDERR_FILENO
%50 = call i32 @dup2(i32 %48, i32 %49)
%51 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%52 = load i8*, i8** %51
%53 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%54 = call i32 @execv(i8* %52, i8** %53)
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %32
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%59 = load i32, i32* %58
%60 = call i32 @close(i32 %59)
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%62 = load i32, i32* %61
%63 = call i32* @fdopen(i32 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %63, i32** %9
%64 = icmp ne i32* %63, null
br i1 %64, label %72, label %65
65: ; preds = %57
%66 = load i64, i64* @errno
%67 = call i32 @strerror(i64 %66)
%68 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %67)
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 @close(i32 %70)
store i32 1, i32* %2
br label %145
72: ; preds = %57
%73 = load i32*, i32** %9
%74 = load i8*, i8** %3
%75 = call i32 @fprintf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %74)
%76 = load i32*, i32** %9
%77 = call i32 @fflush(i32* %76)
%78 = load i32*, i32** %9
%79 = call i32 @fclose(i32* %78)
%80 = call i64 @time(i32* null)
%81 = add nsw i64 %80, 10
store i64 %81, i64* %10
br label %82
82: ; preds = %111, %72
%83 = call i32 @usleep(i32 10000)
%84 = load i32, i32* %8
%85 = load i32, i32* @WNOHANG
%86 = call i32 @waitpid(i32 %84, i32* %7, i32 %85)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %103
89: ; preds = %82
%90 = load i64, i64* @errno
%91 = load i64, i64* @EINTR
%92 = icmp ne i64 %90, %91
br i1 %92, label %93, label %101
93: ; preds = %89
%94 = load i64, i64* @errno
%95 = load i64, i64* @EAGAIN
%96 = icmp ne i64 %94, %95
br i1 %96, label %97, label %101
97: ; preds = %93
%98 = load i64, i64* @errno
%99 = call i32 @strerror(i64 %98)
%100 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %99)
br label %102
101: ; preds = %93, %89
store i32 0, i32* %6
br label %102
102: ; preds = %101, %97
br label %103
103: ; preds = %102, %82
br label %104
104: ; preds = %103
%105 = load i32, i32* %6
%106 = icmp ne i32 %105, 0
br i1 %106, label %111, label %107
107: ; preds = %104
%108 = call i64 @time(i32* null)
%109 = load i64, i64* %10
%110 = icmp slt i64 %108, %109
br label %111
111: ; preds = %107, %104
%112 = phi i1 [ false, %104 ], [ %110, %107 ]
br i1 %112, label %82, label %113
113: ; preds = %111
%114 = load i32, i32* %6
%115 = icmp ne i32 %114, 0
br i1 %115, label %119, label %116
116: ; preds = %113
%117 = load i32, i32* %8
%118 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i32 %117)
store i32 1, i32* %2
br label %145
119: ; preds = %113
%120 = load i32, i32* %6
%121 = load i32, i32* %8
%122 = icmp ne i32 %120, %121
br i1 %122, label %123, label %127
123: ; preds = %119
%124 = load i32, i32* %6
%125 = load i32, i32* %8
%126 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i32 %124, i32 %125)
store i32 1, i32* %2
br label %145
127: ; preds = %119
%128 = load i32, i32* %7
%129 = call i32 @WIFEXITED(i32 %128)
%130 = icmp ne i32 %129, 0
br i1 %130, label %134, label %131
131: ; preds = %127
%132 = load i32, i32* %8
%133 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0), i32 %132)
store i32 1, i32* %2
br label %145
134: ; preds = %127
%135 = load i32, i32* %7
%136 = call i64 @WEXITSTATUS(i32 %135)
%137 = icmp ne i64 %136, 0
br i1 %137, label %138, label %144
138: ; preds = %134
%139 = load i32, i32* %7
%140 = call i64 @WEXITSTATUS(i32 %139)
%141 = trunc i64 %140 to i32
%142 = load i32, i32* %8
%143 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.12, i64 0, i64 0), i32 %141, i32 %142)
store i32 1, i32* %2
br label %145
144: ; preds = %134
store i32 0, i32* %2
br label %145
145: ; preds = %144, %138, %131, %123, %116, %65, %22, %15
%146 = load i32, i32* %2
ret i32 %146
}

LLVM IR (-O2):
@.str = [28 x i8] c"/undeadly.org/mini_sendmail\00"
@.str.1 = [3 x i8] c"-t\00"
@__const.mail_send.argv = [3 x i8*] [i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* null]
@.str.2 = [26 x i8] c"error mail_send: pipe: %s\00"
@errno = global i64 0
@.str.3 = [26 x i8] c"error mail_send: fork: %s\00"
@STDIN_FILENO = global i32 0
@.str.4 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@EXIT_FAILURE = global i32 0
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [28 x i8] c"error mail_send: fdopen: %s\00"
@.str.7 = [4 x i8] c"%s\0A\00"
@WNOHANG = global i32 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str.8 = [29 x i8] c"error mail_send: waitpid: %s\00"
@.str.9 = [46 x i8] c"error mail_send: timeout waiting for child %u\00"
@.str.10 = [50 x i8] c"error mail_send: waitpid returned %u for child %u\00"
@.str.11 = [44 x i8] c"error mail_send: abnormal exit of chhild %u\00"
@.str.12 = [46 x i8] c"error mail_send: exit status %d from child %u\00"
define i32 @mail_send(i8* %0) {
%2 = alloca [3 x i8*]
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = bitcast [3 x i8*]* %2 to i8*
%6 = bitcast [2 x i32]* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%9 = call i64 @pipe(i32* %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %15, label %11
11: ; preds = %1
%12 = load i64, i64* @errno
%13 = call i32 @strerror(i64 %12)
%14 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %108
15: ; preds = %1
%16 = call i32 (...) @fork()
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = call i32 @strerror(i64 %19)
%21 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %8
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
br label %108
27: ; preds = %15
%28 = icmp eq i32 %16, 0
br i1 %28, label %29, label %48
29: ; preds = %27
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = load i32, i32* %8
%34 = load i32, i32* @STDIN_FILENO
%35 = call i32 @dup2(i32 %33, i32 %34)
%36 = load i32, i32* @O_WRONLY
%37 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %36, i32 0)
%38 = load i32, i32* @STDOUT_FILENO
%39 = call i32 @dup2(i32 %37, i32 %38)
%40 = load i32, i32* @O_WRONLY
%41 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32 %40, i32 0)
%42 = load i32, i32* @STDERR_FILENO
%43 = call i32 @dup2(i32 %41, i32 %42)
%44 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
%45 = call i32 @execv(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8** %44)
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %27
%49 = load i32, i32* %8
%50 = call i32 @close(i32 %49)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32* @fdopen(i32 %52, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%54 = icmp eq i32* %53, null
br i1 %54, label %55, label %61
55: ; preds = %48
%56 = load i64, i64* @errno
%57 = call i32 @strerror(i64 %56)
%58 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %51
%60 = call i32 @close(i32 %59)
br label %108
61: ; preds = %48
%62 = call i32 @fprintf(i32* %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %0)
%63 = call i32 @fflush(i32* %53)
%64 = call i32 @fclose(i32* %53)
%65 = call i64 @time(i32* null)
%66 = add nsw i64 %65, 10
br label %67
67: ; preds = %84, %61
%68 = call i32 @usleep(i32 10000)
%69 = load i32, i32* @WNOHANG
%70 = call i32 @waitpid(i32 %16, i32* %4, i32 %69)
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %82
72: ; preds = %67
%73 = load i64, i64* @errno
%74 = load i64, i64* @EINTR
%75 = icmp eq i64 %73, %74
%76 = load i64, i64* @EAGAIN
%77 = icmp eq i64 %73, %76
%78 = select i1 %75, i1 true, i1 %77
br i1 %78, label %84, label %79
79: ; preds = %72
%80 = call i32 @strerror(i64 %73)
%81 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.8, i64 0, i64 0), i32 %80)
br label %89
82: ; preds = %67
%83 = icmp eq i32 %70, 0
br i1 %83, label %84, label %89
84: ; preds = %72, %82
%85 = call i64 @time(i32* null)
%86 = icmp slt i64 %85, %66
br i1 %86, label %67, label %87
87: ; preds = %84
%88 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.9, i64 0, i64 0), i32 %16)
br label %108
89: ; preds = %82, %79
%90 = icmp eq i32 %70, %16
br i1 %90, label %93, label %91
91: ; preds = %89
%92 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i32 %70, i32 %16)
br label %108
93: ; preds = %89
%94 = load i32, i32* %4
%95 = call i32 @WIFEXITED(i32 %94)
%96 = icmp eq i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.11, i64 0, i64 0), i32 %16)
br label %108
99: ; preds = %93
%100 = load i32, i32* %4
%101 = call i64 @WEXITSTATUS(i32 %100)
%102 = icmp eq i64 %101, 0
br i1 %102, label %108, label %103
103: ; preds = %99
%104 = load i32, i32* %4
%105 = call i64 @WEXITSTATUS(i32 %104)
%106 = trunc i64 %105 to i32
%107 = call i32 (i8*, i32, ...) @msg(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.12, i64 0, i64 0), i32 %106, i32 %16)
br label %108
108: ; preds = %99, %103, %97, %91, %87, %55, %18, %11
%109 = phi i32 [ 1, %11 ], [ 1, %18 ], [ 1, %91 ], [ 1, %103 ], [ 1, %97 ], [ 1, %87 ], [ 1, %55 ], [ 0, %99 ]
ret i32 %109
}