#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 do_ping_pong(int, char *, int);
int sprintf(char *, char *, char *);
int set_envelope(int fd, char *from, char *rcpt) {
  int rc;
  char buff[1024];
  rc = sprintf(buff, "MAIL FROM:<%s>\n", from);
  rc = do_ping_pong(fd, buff, rc);
  if (rc < 0) {
    close(fd);
    return rc;
  }
  rc = sprintf(buff, "RCPT TO:<%s>\n", rcpt);
  rc = do_ping_pong(fd, buff, rc);
  return rc;
}


x86 assembly (clang, -O0):
<set_envelope>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xea8(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <do_ping_pong@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1192 <set_envelope+0x62>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <set_envelope+0x97>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe6c(%rip),%rsi
call   1050 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <do_ping_pong@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_envelope>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %edi,%ebx
lea    0xeb6(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
call   1050 <sprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <do_ping_pong@plt>
test   %eax,%eax
js     118a <set_envelope+0x5a>
lea    0xea4(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r14,%rdx
call   1050 <sprintf@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1030 <do_ping_pong@plt>
mov    %eax,%ebp
jmp    1193 <set_envelope+0x63>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"MAIL FROM:<%s>\0A\00"
@.str.1 = [14 x i8] c"RCPT TO:<%s>\0A\00"
define i32 @set_envelope(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [1024 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %6
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %11)
store i32 %12, i32* %8
%13 = load i32, i32* %5
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%15 = load i32, i32* %8
%16 = call i32 @do_ping_pong(i32 %13, i8* %14, i32 %15)
store i32 %16, i32* %8
%17 = load i32, i32* %8
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* %5
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %8
store i32 %22, i32* %4
br label %32
23: ; preds = %3
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%25 = load i8*, i8** %7
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 %26, i32* %8
%27 = load i32, i32* %5
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* %8
%30 = call i32 @do_ping_pong(i32 %27, i8* %28, i32 %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
store i32 %31, i32* %4
br label %32
32: ; preds = %23, %19
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
@.str = [16 x i8] c"MAIL FROM:<%s>\0A\00"
@.str.1 = [14 x i8] c"RCPT TO:<%s>\0A\00"
define i32 @set_envelope(i32 %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
%7 = call i32 @do_ping_pong(i32 %0, i8* %5, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = call i32 @close(i32 %0)
br label %14
11: ; preds = %3
%12 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%13 = call i32 @do_ping_pong(i32 %0, i8* %5, i32 %12)
br label %14
14: ; preds = %11, %9
%15 = phi i32 [ %7, %9 ], [ %13, %11 ]
ret i32 %15
}