#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*/ sprintf(char *, char *, char *, char *, ...);
char *strdup(char *);
scalar_t__ timlib_file_exists(char *);
char *email_sendmail_command(char *to_address, char *subject,
                             char *attachment_filename) {
  char sendmail_command[2048];
  if (attachment_filename && *attachment_filename &&
      timlib_file_exists(attachment_filename)) {
    sprintf(sendmail_command, "mutt -s \"%s\" -a %s -- %s", subject,
            attachment_filename, to_address);
  } else {
    sprintf(sendmail_command, "mutt -s \"%s\" %s", subject, to_address);
  }
  return strdup(sendmail_command);
}


x86 assembly (clang, -O0):
<email_sendmail_command>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119b <email_sendmail_command+0x6b>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119b <email_sendmail_command+0x6b>
mov    -0x18(%rbp),%rdi
call   1030 <timlib_file_exists@plt>
cmp    $0x0,%rax
je     119b <email_sendmail_command+0x6b>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%r8
lea    0xe71(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
jmp    11b8 <email_sendmail_command+0x88>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x8(%rbp),%rcx
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <sprintf@plt>
lea    -0x820(%rbp),%rdi
call   1050 <strdup@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<email_sendmail_command>:
push   %r15
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
test   %rdx,%rdx
je     1178 <email_sendmail_command+0x48>
mov    %rdx,%rbx
cmpb   $0x0,(%rdx)
je     1178 <email_sendmail_command+0x48>
mov    %rbx,%rdi
call   1030 <timlib_file_exists@plt>
test   %rax,%rax
je     1178 <email_sendmail_command+0x48>
lea    0xe9d(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %rbx,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1040 <sprintf@plt>
jmp    118f <email_sendmail_command+0x5f>
lea    0xe9a(%rip),%rsi
mov    %rsp,%rdi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %rsp,%rdi
call   1050 <strdup@plt>
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [25 x i8] c"mutt -s \22%s\22 -a %s -- %s\00"
@.str.1 = [16 x i8] c"mutt -s \22%s\22 %s\00"
define i8* @email_sendmail_command(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca [2048 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %25
10: ; preds = %3
%11 = load i8*, i8** %6
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = load i8*, i8** %6
%17 = call i64 @timlib_file_exists(i8* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %15
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%21 = load i8*, i8** %5
%22 = load i8*, i8** %6
%23 = load i8*, i8** %4
%24 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %21, i8* %22, i8* %23)
br label %30
25: ; preds = %15, %10, %3
%26 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = load i8*, i8** %4
%29 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %28)
br label %30
30: ; preds = %25, %19
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%32 = call i8* @strdup(i8* %31)
ret i8* %32
}

LLVM IR (-O2):
@.str = [25 x i8] c"mutt -s \22%s\22 -a %s -- %s\00"
@.str.1 = [16 x i8] c"mutt -s \22%s\22 %s\00"
define noalias i8* @email_sendmail_command(i8* %0, i8* %1, i8* %2) {
%4 = alloca [2048 x i8]
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %2, null
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = load i8, i8* %2
%9 = icmp eq i8 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %7
%11 = tail call i64 @timlib_file_exists(i8* %2)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2, i8* %0)
br label %17
15: ; preds = %10, %7, %3
%16 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %1, i8* %0)
br label %17
17: ; preds = %15, %13
%18 = call i8* @strdup(i8* %5)
ret i8* %18
}