#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 /*<<< orphan*/ close_sendmail(int /*<<< orphan*/ *);
int encode_body(int /*<<< orphan*/ *, int /*<<< orphan*/ *, long,
                unsigned int *);
int /*<<< orphan*/ err(char *, char *, int, int, char *);
int /*<<< orphan*/ *open_sendmail();
int /*<<< orphan*/ write_header(int /*<<< orphan*/ *, char *, char *, int, int);
int /*<<< orphan*/ write_trailer(int /*<<< orphan*/ *, unsigned int);
int chop_and_send(FILE *dfp, char *delta, long msg_size, int npieces,
                  char *mail_alias) {
  int pce;
  FILE *sfp;
  unsigned sum;
  for (pce = 1; pce <= npieces; pce++) {
    int read_error;
    if ((sfp = open_sendmail()) == NULL)
      return 1;
    write_header(sfp, mail_alias, delta, pce, npieces);
    read_error = encode_body(sfp, dfp, msg_size, &sum);
    if (!read_error)
      write_trailer(sfp, sum);
    if (!close_sendmail(sfp) || read_error)
      return 1;
    err("%s %d/%d sent to %s", delta, pce, npieces, mail_alias);
  }
  return 0;
}


x86 assembly (clang, -O0):
<chop_and_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jg     1245 <chop_and_send+0xe5>
mov    $0x0,%al
call   1080 <open_sendmail@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    11af <chop_and_send+0x4f>
movl   $0x1,-0x4(%rbp)
jmp    124c <chop_and_send+0xec>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x24(%rbp),%r8d
call   1070 <write_header@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x44(%rbp),%rcx
call   1050 <encode_body@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x0,-0x48(%rbp)
jne    11f5 <chop_and_send+0x95>
mov    -0x40(%rbp),%rdi
mov    -0x44(%rbp),%esi
call   1060 <write_trailer@plt>
mov    -0x40(%rbp),%rdi
call   1030 <close_sendmail@plt>
cmp    $0x0,%eax
je     1211 <chop_and_send+0xb1>
cmpl   $0x0,-0x48(%rbp)
je     121d <chop_and_send+0xbd>
movl   $0x1,-0x4(%rbp)
jmp    124c <chop_and_send+0xec>
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    -0x30(%rbp),%r8
lea    0xdce(%rip),%rdi
call   1040 <err@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1182 <chop_and_send+0x22>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop_and_send>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rdi,0x8(%rsp)
test   %ecx,%ecx
jle    122a <chop_and_send+0xca>
mov    %r8,%r12
mov    %ecx,%ebp
mov    %rsi,%rbx
mov    %ecx,%r13d
neg    %r13d
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1080 <open_sendmail@plt>
test   %rax,%rax
je     1236 <chop_and_send+0xd6>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1070 <write_header@plt>
mov    %r15,%rdi
mov    0x8(%rsp),%rsi
mov    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1050 <encode_body@plt>
test   %eax,%eax
jne    122e <chop_and_send+0xce>
mov    0x4(%rsp),%esi
mov    %r15,%rdi
call   1060 <write_trailer@plt>
mov    %r15,%rdi
call   1030 <close_sendmail@plt>
test   %eax,%eax
je     1236 <chop_and_send+0xd6>
lea    0xdff(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
mov    %r12,%r8
call   1040 <err@plt>
lea    (%r14,%r13,1),%eax
add    $0x1,%eax
mov    %r14d,%ecx
add    $0x1,%ecx
mov    %ecx,%r14d
cmp    $0x1,%eax
jne    11a0 <chop_and_send+0x40>
xor    %eax,%eax
jmp    123b <chop_and_send+0xdb>
mov    %r15,%rdi
call   1030 <close_sendmail@plt>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"%s %d/%d sent to %s\00"
define i32 @chop_and_send(i32* %0, i8* %1, i64 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i64 %2, i64* %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 1, i32* %12
br label %16
16: ; preds = %55, %5
%17 = load i32, i32* %12
%18 = load i32, i32* %10
%19 = icmp sle i32 %17, %18
br i1 %19, label %20, label %58
20: ; preds = %16
%21 = call i32* (...) @open_sendmail()
store i32* %21, i32** %13
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %24
23: ; preds = %20
store i32 1, i32* %6
br label %59
24: ; preds = %20
%25 = load i32*, i32** %13
%26 = load i8*, i8** %11
%27 = load i8*, i8** %8
%28 = load i32, i32* %12
%29 = load i32, i32* %10
%30 = call i32 @write_header(i32* %25, i8* %26, i8* %27, i32 %28, i32 %29)
%31 = load i32*, i32** %13
%32 = load i32*, i32** %7
%33 = load i64, i64* %9
%34 = call i32 @encode_body(i32* %31, i32* %32, i64 %33, i32* %14)
store i32 %34, i32* %15
%35 = load i32, i32* %15
%36 = icmp ne i32 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %24
%38 = load i32*, i32** %13
%39 = load i32, i32* %14
%40 = call i32 @write_trailer(i32* %38, i32 %39)
br label %41
41: ; preds = %37, %24
%42 = load i32*, i32** %13
%43 = call i32 @close_sendmail(i32* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = load i32, i32* %15
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %45, %41
store i32 1, i32* %6
br label %59
49: ; preds = %45
%50 = load i8*, i8** %8
%51 = load i32, i32* %12
%52 = load i32, i32* %10
%53 = load i8*, i8** %11
%54 = call i32 @err(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %50, i32 %51, i32 %52, i8* %53)
br label %55
55: ; preds = %49
%56 = load i32, i32* %12
%57 = add nsw i32 %56, 1
store i32 %57, i32* %12
br label %16
58: ; preds = %16
store i32 0, i32* %6
br label %59
59: ; preds = %58, %48, %23
%60 = load i32, i32* %6
ret i32 %60
}

LLVM IR (-O2):
@.str = [20 x i8] c"%s %d/%d sent to %s\00"
define i32 @chop_and_send(i32* %0, i8* %1, i64 %2, i32 %3, i8* %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = icmp slt i32 %3, 1
br i1 %8, label %28, label %9
9: ; preds = %5, %24
%10 = phi i32 [ %26, %24 ], [ 1, %5 ]
%11 = call i32* (...) @open_sendmail()
%12 = icmp eq i32* %11, null
br i1 %12, label %28, label %13
13: ; preds = %9
%14 = call i32 @write_header(i32* %11, i8* %4, i8* %1, i32 %10, i32 %3)
%15 = call i32 @encode_body(i32* %11, i32* %0, i64 %2, i32* %6)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i32 @close_sendmail(i32* %11)
br label %28
19: ; preds = %13
%20 = load i32, i32* %6
%21 = call i32 @write_trailer(i32* %11, i32 %20)
%22 = call i32 @close_sendmail(i32* %11)
%23 = icmp eq i32 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = call i32 @err(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %10, i32 %3, i8* %4)
%26 = add nuw i32 %10, 1
%27 = icmp eq i32 %10, %3
br i1 %27, label %28, label %9
28: ; preds = %19, %9, %24, %5, %17
%29 = phi i32 [ 1, %17 ], [ 0, %5 ], [ 1, %19 ], [ 1, %9 ], [ 0, %24 ]
ret i32 %29
}