#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ execl(char *, char *, char *, char const *,
                         int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ restore_sigmask();
int run_sendmail(const char *dest) {
  int pid;
  int p[2];
  pipe(p);
  pid = fork();
  switch (pid) {
  case 0:
    restore_sigmask();
    close(0);
    close(1);
    close(2);
    close(p[1]);
    dup2(p[0], 0);
    execl("/usr/sbin/sendmail", "sendmail", "-oi", dest, NULL);
    error("run sendmail");
  case -1:
    error("fork sendmail");
  default:
    close(p[0]);
  }
  return p[1];
}


x86 assembly (clang, -O0):
<run_sendmail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x14(%rbp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
sub    $0xffffffff,%eax
je     1216 <run_sendmail+0xa6>
jmp    11a3 <run_sendmail+0x33>
mov    -0x18(%rbp),%eax
test   %eax,%eax
jne    1222 <run_sendmail+0xb2>
jmp    11b3 <run_sendmail+0x43>
mov    $0x0,%al
call   1040 <restore_sigmask@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%rcx
lea    0xe0e(%rip),%rdi
lea    0xe30(%rip),%rsi
lea    0xe13(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1080 <execl@plt>
lea    0xe06(%rip),%rdi
call   1070 <error@plt>
lea    0xe07(%rip),%rdi
call   1070 <error@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_sendmail>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11f4 <run_sendmail+0x84>
test   %eax,%eax
jne    1200 <run_sendmail+0x90>
xor    %eax,%eax
call   1040 <restore_sigmask@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    $0x2,%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xe31(%rip),%rdi
lea    0xe53(%rip),%rsi
lea    0xe36(%rip),%rdx
mov    %rbx,%rcx
xor    %r8d,%r8d
call   1080 <execl@plt>
lea    0xe28(%rip),%rdi
call   1070 <error@plt>
lea    0xe29(%rip),%rdi
call   1070 <error@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [19 x i8] c"/usr/sbin/sendmail\00"
@.str.1 = [9 x i8] c"sendmail\00"
@.str.2 = [4 x i8] c"-oi\00"
@.str.3 = [13 x i8] c"run sendmail\00"
@.str.4 = [14 x i8] c"fork sendmail\00"
define i32 @run_sendmail(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [2 x i32]
store i8* %0, i8** %2
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
store i32 %7, i32* %3
%8 = load i32, i32* %3
switch i32 %8, label %25 [
i32 0, label %9
i32 -1, label %23
]
9: ; preds = %1
%10 = call i32 (...) @restore_sigmask()
%11 = call i32 @close(i32 0)
%12 = call i32 @close(i32 1)
%13 = call i32 @close(i32 2)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%18 = load i32, i32* %17
%19 = call i32 @dup2(i32 %18, i32 0)
%20 = load i8*, i8** %2
%21 = call i32 @execl(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %20, i32* null)
%22 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %1, %9
%24 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %1, %23
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
br label %29
29: ; preds = %25
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%31 = load i32, i32* %30
ret i32 %31
}

LLVM IR (-O2):
@.str = [19 x i8] c"/usr/sbin/sendmail\00"
@.str.1 = [9 x i8] c"sendmail\00"
@.str.2 = [4 x i8] c"-oi\00"
@.str.3 = [13 x i8] c"run sendmail\00"
@.str.4 = [14 x i8] c"fork sendmail\00"
define i32 @run_sendmail(i8* %0) {
%2 = alloca [2 x i32]
%3 = bitcast [2 x i32]* %2 to i8*
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = call i32 (...) @fork()
switch i32 %6, label %21 [
i32 0, label %7
i32 -1, label %19
]
7: ; preds = %1
%8 = call i32 (...) @restore_sigmask()
%9 = call i32 @close(i32 0)
%10 = call i32 @close(i32 1)
%11 = call i32 @close(i32 2)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = load i32, i32* %4
%16 = call i32 @dup2(i32 %15, i32 0)
%17 = call i32 @execl(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32* null)
%18 = call i32 @error(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
br label %19
19: ; preds = %1, %7
%20 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %1, %19
%22 = load i32, i32* %4
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%25 = load i32, i32* %24
ret i32 %25
}