#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ build_sys_string(char *, char *, char **);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ get_line(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ stdin;
void mail_if_output(char *subject, char **address_list) {
  char sys_string[1024];
  char input_buffer[1024];
  FILE *output_pipe = {0};
  build_sys_string(sys_string, subject, address_list);
  while (get_line(input_buffer, stdin)) {
    if (output_pipe) {
      fprintf(output_pipe, "%s\n", input_buffer);
    } else if (*input_buffer) {
      output_pipe = popen(sys_string, "w");
      fprintf(output_pipe, "%s\n", input_buffer);
    }
  }
  if (output_pipe)
    pclose(output_pipe);
}


x86 assembly (clang, -O0):
<mail_if_output>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x818(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   1050 <build_sys_string@plt>
lea    -0x810(%rbp),%rdi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
call   1030 <get_line@plt>
cmp    $0x0,%rax
je     1219 <mail_if_output+0xc9>
cmpq   $0x0,-0x818(%rbp)
je     11ce <mail_if_output+0x7e>
mov    -0x818(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    0xe3c(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1214 <mail_if_output+0xc4>
cmpb   $0x0,-0x810(%rbp)
je     120f <mail_if_output+0xbf>
lea    -0x410(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1070 <popen@plt>
mov    %rax,-0x818(%rbp)
mov    -0x818(%rbp),%rdi
lea    -0x810(%rbp),%rdx
lea    0xdf6(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1214 <mail_if_output+0xc4>
jmp    1182 <mail_if_output+0x32>
cmpq   $0x0,-0x818(%rbp)
je     1233 <mail_if_output+0xe3>
mov    -0x818(%rbp),%rdi
call   1040 <pclose@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mail_if_output>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%rdx
mov    %rdi,%rsi
lea    0x400(%rsp),%rdi
call   1050 <build_sys_string@plt>
mov    0x2e6d(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rsp,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11fd <mail_if_output+0xad>
xor    %ebx,%ebx
lea    0xe70(%rip),%r14
lea    0x400(%rsp),%r15
lea    0xe5d(%rip),%r12
mov    %rsp,%r13
jmp    11ce <mail_if_output+0x7e>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1060 <fprintf@plt>
mov    0x0(%rbp),%esi
mov    %r13,%rdi
call   1030 <get_line@plt>
test   %rax,%rax
je     11f0 <mail_if_output+0xa0>
test   %rbx,%rbx
jne    11b0 <mail_if_output+0x60>
cmpb   $0x0,(%rsp)
je     11ec <mail_if_output+0x9c>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <popen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
jmp    11b3 <mail_if_output+0x63>
xor    %ebx,%ebx
jmp    11be <mail_if_output+0x6e>
test   %rbx,%rbx
je     11fd <mail_if_output+0xad>
mov    %rbx,%rdi
call   1040 <pclose@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"w\00"
define void @mail_if_output(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca i32*
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32* null, i32** %7
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %3
%10 = load i8**, i8*** %4
%11 = call i32 @build_sys_string(i8* %8, i8* %9, i8** %10)
br label %12
12: ; preds = %35, %2
%13 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%14 = load i32, i32* @stdin
%15 = call i64 @get_line(i8* %13, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %36
17: ; preds = %12
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = load i32*, i32** %7
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @fprintf(i32* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %35
24: ; preds = %17
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%26 = load i8, i8* %25
%27 = icmp ne i8 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %24
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%30 = call i32* @popen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %30, i32** %7
%31 = load i32*, i32** %7
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%33 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %28, %24
br label %35
35: ; preds = %34, %20
br label %12
36: ; preds = %12
%37 = load i32*, i32** %7
%38 = icmp ne i32* %37, null
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32*, i32** %7
%41 = call i32 @pclose(i32* %40)
br label %42
42: ; preds = %39, %36
ret void
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [2 x i8] c"w\00"
define void @mail_if_output(i8* %0, i8** %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @build_sys_string(i8* %5, i8* %0, i8** %1)
%8 = load i32, i32* @stdin
%9 = call i64 @get_line(i8* %6, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %31, label %11
11: ; preds = %2, %22
%12 = phi i32* [ %23, %22 ], [ null, %2 ]
%13 = icmp eq i32* %12, null
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 @fprintf(i32* %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %22
16: ; preds = %11
%17 = load i8, i8* %6
%18 = icmp eq i8 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %16
%20 = call i32* @popen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %22
22: ; preds = %16, %19, %14
%23 = phi i32* [ %12, %14 ], [ %20, %19 ], [ null, %16 ]
%24 = load i32, i32* @stdin
%25 = call i64 @get_line(i8* %6, i32 %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %11
27: ; preds = %22
%28 = icmp eq i32* %23, null
br i1 %28, label %31, label %29
29: ; preds = %27
%30 = call i32 @pclose(i32* %23)
br label %31
31: ; preds = %2, %29, %27
ret void
}