#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int dosend(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
char *strchr(char *, char);
int mysendmail(char *filename) {
  FILE *stream;
  char inbuf[4098];
  char *p, *pp;
  int rc;
  if ((stream = fopen(filename, "r")) == NULL) {
    perror(filename);
    return -1;
  }
  if (fscanf(stream, "To: %s\n", inbuf) != 1) {
    perror(filename);
    return -1;
  }
  rc = dosend(inbuf, filename);
  if (fscanf(stream, "CC: %[^\n]", inbuf) == 1) {
    fclose(stream);
    p = inbuf;
    do {
      if ((pp = strchr(p, ',')) != NULL)
        *pp = '\0';
      rc = dosend(p, filename);
      if (pp)
        p = pp + 2;
    } while (pp != NULL);
  } else
    fclose(stream);
  return rc;
}


x86 assembly (clang, -O0):
<mysendmail>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe86(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11a2 <mysendmail+0x42>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <mysendmail+0x150>
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
je     11d7 <mysendmail+0x77>
mov    -0x10(%rbp),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b0 <mysendmail+0x150>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <dosend@plt>
mov    %eax,-0x1034(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1020(%rbp),%rdx
lea    0xe0b(%rip),%rsi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    129e <mysendmail+0x13e>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1028(%rbp),%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
je     1250 <mysendmail+0xf0>
mov    -0x1030(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1028(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <dosend@plt>
mov    %eax,-0x1034(%rbp)
cmpq   $0x0,-0x1030(%rbp)
je     1286 <mysendmail+0x126>
mov    -0x1030(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x1028(%rbp)
jmp    128b <mysendmail+0x12b>
cmpq   $0x0,-0x1030(%rbp)
jne    1224 <mysendmail+0xc4>
jmp    12a7 <mysendmail+0x147>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1034(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mysendmail>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1010,%rsp
mov    %rdi,%r14
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     122b <mysendmail+0xcb>
mov    %rax,%r15
lea    0xe71(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1050 <fscanf@plt>
cmp    $0x1,%eax
jne    122b <mysendmail+0xcb>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <dosend@plt>
mov    %eax,%r12d
lea    0xe4d(%rip),%rsi
mov    %r15,%rdi
mov    %rbx,%rdx
call   1050 <fscanf@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    1239 <mysendmail+0xd9>
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     121b <mysendmail+0xbb>
mov    %rax,%rbp
mov    %rsp,%rbx
nop
movb   $0x0,0x0(%rbp)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <dosend@plt>
mov    %rbp,%rbx
add    $0x2,%rbx
mov    %rbx,%rdi
mov    $0x2c,%esi
call   1040 <strchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11f0 <mysendmail+0x90>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <dosend@plt>
mov    %eax,%r12d
jmp    1239 <mysendmail+0xd9>
mov    %r14,%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"To: %s\0A\00"
@.str.2 = [10 x i8] c"CC: %[^\0A]\00"
define i32 @mysendmail(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca [4098 x i8]
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i8*, i8** %3
%14 = call i32 @perror(i8* %13)
store i32 -1, i32* %2
br label %60
15: ; preds = %1
%16 = load i32*, i32** %4
%17 = getelementptr inbounds [4098 x i8], [4098 x i8]* %5, i64 0, i64 0
%18 = call i32 @fscanf(i32* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = icmp ne i32 %18, 1
br i1 %19, label %20, label %23
20: ; preds = %15
%21 = load i8*, i8** %3
%22 = call i32 @perror(i8* %21)
store i32 -1, i32* %2
br label %60
23: ; preds = %15
%24 = getelementptr inbounds [4098 x i8], [4098 x i8]* %5, i64 0, i64 0
%25 = load i8*, i8** %3
%26 = call i32 @dosend(i8* %24, i8* %25)
store i32 %26, i32* %8
%27 = load i32*, i32** %4
%28 = getelementptr inbounds [4098 x i8], [4098 x i8]* %5, i64 0, i64 0
%29 = call i32 @fscanf(i32* %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %55
31: ; preds = %23
%32 = load i32*, i32** %4
%33 = call i32 @fclose(i32* %32)
%34 = getelementptr inbounds [4098 x i8], [4098 x i8]* %5, i64 0, i64 0
store i8* %34, i8** %6
br label %35
35: ; preds = %51, %31
%36 = load i8*, i8** %6
%37 = call i8* @strchr(i8* %36, i8 signext 44)
store i8* %37, i8** %7
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load i8*, i8** %7
store i8 0, i8* %40
br label %41
41: ; preds = %39, %35
%42 = load i8*, i8** %6
%43 = load i8*, i8** %3
%44 = call i32 @dosend(i8* %42, i8* %43)
store i32 %44, i32* %8
%45 = load i8*, i8** %7
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %50
47: ; preds = %41
%48 = load i8*, i8** %7
%49 = getelementptr inbounds i8, i8* %48, i64 2
store i8* %49, i8** %6
br label %50
50: ; preds = %47, %41
br label %51
51: ; preds = %50
%52 = load i8*, i8** %7
%53 = icmp ne i8* %52, null
br i1 %53, label %35, label %54
54: ; preds = %51
br label %58
55: ; preds = %23
%56 = load i32*, i32** %4
%57 = call i32 @fclose(i32* %56)
br label %58
58: ; preds = %55, %54
%59 = load i32, i32* %8
store i32 %59, i32* %2
br label %60
60: ; preds = %58, %20, %12
%61 = load i32, i32* %2
ret i32 %61
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"To: %s\0A\00"
@.str.2 = [10 x i8] c"CC: %[^\0A]\00"
define i32 @mysendmail(i8* %0) {
%2 = alloca [4098 x i8]
%3 = getelementptr inbounds [4098 x i8], [4098 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* %0)
br label %31
8: ; preds = %1
%9 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%10 = icmp eq i32 %9, 1
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = call i32 @perror(i8* %0)
br label %31
13: ; preds = %8
%14 = call i32 @dosend(i8* %3, i8* %0)
%15 = call i32 @fscanf(i32* %4, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%16 = icmp eq i32 %15, 1
%17 = call i32 @fclose(i32* %4)
br i1 %16, label %18, label %31
18: ; preds = %13
%19 = call i8* @strchr(i8* dereferenceable(1) %3, i8 signext 44)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %24
21: ; preds = %24, %18
%22 = phi i8* [ %3, %18 ], [ %28, %24 ]
%23 = call i32 @dosend(i8* %22, i8* %0)
br label %31
24: ; preds = %18, %24
%25 = phi i8* [ %29, %24 ], [ %19, %18 ]
%26 = phi i8* [ %28, %24 ], [ %3, %18 ]
store i8 0, i8* %25
%27 = call i32 @dosend(i8* %26, i8* %0)
%28 = getelementptr inbounds i8, i8* %25, i64 2
%29 = call i8* @strchr(i8* dereferenceable(1) %28, i8 signext 44)
%30 = icmp eq i8* %29, null
br i1 %30, label %21, label %24
31: ; preds = %13, %21, %11, %6
%32 = phi i32 [ -1, %6 ], [ -1, %11 ], [ %23, %21 ], [ %14, %13 ]
ret i32 %32
}