#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 off_t;
typedef scalar_t__ npieces;
typedef scalar_t__ max_msg_size;
typedef int exp_size;
typedef int ctm_size;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int chop_and_queue(int /*<<< orphan*/ *, char *, long, int, char *, char *);
int chop_and_send(int /*<<< orphan*/ *, char *, long, int, char *);
int /*<<< orphan*/ clean_up_queue(char *);
int chop_and_send_or_queue(FILE *dfp, char *delta, off_t ctm_size,
                           long max_msg_size, char *mail_alias,
                           char *queue_dir) {
  int npieces;
  long msg_size;
  long exp_size;
  int status;
  exp_size = ctm_size * 4 / 3;
  exp_size += (((exp_size) + ((72) - 1)) / (72));
  npieces = (((exp_size) + ((max_msg_size)-1)) / (max_msg_size));
  msg_size = (((ctm_size) + ((npieces)-1)) / (npieces));
  if (queue_dir == NULL)
    status = chop_and_send(dfp, delta, msg_size, npieces, mail_alias);
  else {
    status =
        chop_and_queue(dfp, delta, msg_size, npieces, mail_alias, queue_dir);
    if (status)
      clean_up_queue(queue_dir);
  }
  return status;
}


x86 assembly (clang, -O0):
<chop_and_send_or_queue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x2,%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
add    $0x47,%rax
mov    $0x48,%ecx
cqto
idiv   %rcx
add    -0x48(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    $0x1,%rcx
add    %rcx,%rax
cqto
idivq  -0x20(%rbp)
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    -0x34(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
cltd
idivl  -0x34(%rbp)
cltq
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d5 <chop_and_send_or_queue+0xa5>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%r8
call   1050 <chop_and_send@plt>
mov    %eax,-0x4c(%rbp)
jmp    120c <chop_and_send_or_queue+0xdc>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x34(%rbp),%ecx
mov    -0x28(%rbp),%r8
mov    -0x30(%rbp),%r9
call   1030 <chop_and_queue@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1207 <chop_and_send_or_queue+0xd7>
mov    -0x30(%rbp),%rdi
call   1040 <clean_up_queue@plt>
jmp    120c <chop_and_send_or_queue+0xdc>
mov    -0x4c(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop_and_send_or_queue>:
push   %r14
push   %rbx
push   %rax
mov    %r9,%r14
mov    %edx,%r9d
lea    0x0(,%r9,4),%eax
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rax
lea    (%rax,%rdx,1),%ebx
add    %edx,%eax
add    $0x47,%eax
cltq
imul   $0x38e38e39,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x24,%rax
add    %edx,%eax
add    %ebx,%eax
cltq
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,%rdx
or     %rcx,%rdx
shr    $0x20,%rdx
je     1195 <chop_and_send_or_queue+0x65>
cqto
idiv   %rcx
mov    %rax,%rcx
jmp    119b <chop_and_send_or_queue+0x6b>
xor    %edx,%edx
div    %ecx
mov    %eax,%ecx
lea    (%r9,%rcx,1),%eax
add    $0xffffffff,%eax
cltd
idiv   %ecx
movslq %eax,%rdx
test   %r14,%r14
je     11c5 <chop_and_send_or_queue+0x95>
mov    %r14,%r9
call   1030 <chop_and_queue@plt>
test   %eax,%eax
je     11d1 <chop_and_send_or_queue+0xa1>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <clean_up_queue@plt>
jmp    11d3 <chop_and_send_or_queue+0xa3>
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <chop_and_send@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @chop_and_send_or_queue(i32* %0, i8* %1, i32 %2, i64 %3, i8* %4, i8* %5) {
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i64
%15 = alloca i64
%16 = alloca i32
store i32* %0, i32** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i64 %3, i64* %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%17 = load i32, i32* %9
%18 = mul nsw i32 %17, 4
%19 = sdiv i32 %18, 3
%20 = sext i32 %19 to i64
store i64 %20, i64* %15
%21 = load i64, i64* %15
%22 = add nsw i64 %21, 71
%23 = sdiv i64 %22, 72
%24 = load i64, i64* %15
%25 = add nsw i64 %24, %23
store i64 %25, i64* %15
%26 = load i64, i64* %15
%27 = load i64, i64* %10
%28 = sub nsw i64 %27, 1
%29 = add nsw i64 %26, %28
%30 = load i64, i64* %10
%31 = sdiv i64 %29, %30
%32 = trunc i64 %31 to i32
store i32 %32, i32* %13
%33 = load i32, i32* %9
%34 = load i32, i32* %13
%35 = sub nsw i32 %34, 1
%36 = add nsw i32 %33, %35
%37 = load i32, i32* %13
%38 = sdiv i32 %36, %37
%39 = sext i32 %38 to i64
store i64 %39, i64* %14
%40 = load i8*, i8** %12
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %49
42: ; preds = %6
%43 = load i32*, i32** %7
%44 = load i8*, i8** %8
%45 = load i64, i64* %14
%46 = load i32, i32* %13
%47 = load i8*, i8** %11
%48 = call i32 @chop_and_send(i32* %43, i8* %44, i64 %45, i32 %46, i8* %47)
store i32 %48, i32* %16
br label %63
49: ; preds = %6
%50 = load i32*, i32** %7
%51 = load i8*, i8** %8
%52 = load i64, i64* %14
%53 = load i32, i32* %13
%54 = load i8*, i8** %11
%55 = load i8*, i8** %12
%56 = call i32 @chop_and_queue(i32* %50, i8* %51, i64 %52, i32 %53, i8* %54, i8* %55)
store i32 %56, i32* %16
%57 = load i32, i32* %16
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %49
%60 = load i8*, i8** %12
%61 = call i32 @clean_up_queue(i8* %60)
br label %62
62: ; preds = %59, %49
br label %63
63: ; preds = %62, %42
%64 = load i32, i32* %16
ret i32 %64
}

LLVM IR (-O2):
define i32 @chop_and_send_or_queue(i32* %0, i8* %1, i32 %2, i64 %3, i8* %4, i8* %5) {
%7 = shl nsw i32 %2, 2
%8 = sdiv i32 %7, 3
%9 = add nsw i32 %8, 71
%10 = sdiv i32 %9, 72
%11 = add nsw i32 %10, %8
%12 = sext i32 %11 to i64
%13 = add nsw i64 %3, -1
%14 = add nsw i64 %13, %12
%15 = sdiv i64 %14, %3
%16 = trunc i64 %15 to i32
%17 = add i32 %2, -1
%18 = add i32 %17, %16
%19 = sdiv i32 %18, %16
%20 = sext i32 %19 to i64
%21 = icmp eq i8* %5, null
br i1 %21, label %22, label %24
22: ; preds = %6
%23 = tail call i32 @chop_and_send(i32* %0, i8* %1, i64 %20, i32 %16, i8* %4)
br label %29
24: ; preds = %6
%25 = tail call i32 @chop_and_queue(i32* %0, i8* %1, i64 %20, i32 %16, i8* %4, i8* %5)
%26 = icmp eq i32 %25, 0
br i1 %26, label %29, label %27
27: ; preds = %24
%28 = tail call i32 @clean_up_queue(i8* %5)
br label %29
29: ; preds = %24, %27, %22
%30 = phi i32 [ %23, %22 ], [ %25, %27 ], [ 0, %24 ]
ret i32 %30
}