#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*/ atm_cell_create_with_header(unsigned char *, unsigned char *,
                                               unsigned char *);
int /*<<< orphan*/ atm_header_create(unsigned char *, int, int, int,
                                     int /*<<< orphan*/);
int aal5_frame_to_atm_cells(unsigned char *atm_cells, unsigned char *aal5_frame,
                            int length, int vpi, int vci) {
  unsigned char *src, *dst;
  unsigned char header[5];
  unsigned int cells;
  if (length % 48)
    return (-1);
  cells = length / 48 - 1;
  src = aal5_frame + 48 * cells;
  dst = atm_cells + (5 + 48) * cells;
  atm_header_create(header, vpi, vci, 1, 0);
  atm_cell_create_with_header(dst, src, header);
  atm_header_create(header, vpi, vci, 0, 0);
  while (cells--) {
    src -= 48;
    dst -= (5 + 48);
    atm_cell_create_with_header(dst, src, header);
  }
  return ((length / 48) * (5 + 48));
}


x86 assembly (clang, -O0):
<aal5_frame_to_atm_cells>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
mov    $0x30,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     115a <aal5_frame_to_atm_cells+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    121d <aal5_frame_to_atm_cells+0xfd>
mov    -0x1c(%rbp),%eax
mov    $0x30,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x44(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x30,-0x44(%rbp),%ecx
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x35,-0x44(%rbp),%ecx
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
lea    -0x3d(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1040 <atm_header_create@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x3d(%rbp),%rdx
call   1030 <atm_cell_create_with_header@plt>
lea    -0x3d(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
xor    %r8d,%r8d
mov    %r8d,%ecx
call   1040 <atm_header_create@plt>
mov    -0x44(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x44(%rbp)
cmp    $0x0,%eax
je     120c <aal5_frame_to_atm_cells+0xec>
mov    -0x30(%rbp),%rax
add    $0xffffffffffffffd0,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
add    $0xffffffffffffffcb,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
lea    -0x3d(%rbp),%rdx
call   1030 <atm_cell_create_with_header@plt>
jmp    11ca <aal5_frame_to_atm_cells+0xaa>
mov    -0x1c(%rbp),%eax
mov    $0x30,%ecx
cltd
idiv   %ecx
imul   $0x35,%eax,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aal5_frame_to_atm_cells>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebx
imul   $0xaaaaaaab,%edx,%ecx
add    $0x2aaaaaa0,%ecx
ror    $0x4,%ecx
mov    $0xffffffff,%eax
cmp    $0x5555554,%ecx
ja     1230 <aal5_frame_to_atm_cells+0x110>
mov    %r8d,%ebp
mov    %rdi,%r14
movslq %edx,%rax
imul   $0x2aaaaaab,%rax,%r12
mov    %r12,%rax
shr    $0x3f,%rax
sar    $0x23,%r12
add    %eax,%r12d
lea    -0x1(%r12),%r15d
mov    %r15d,%eax
shl    $0x4,%eax
lea    (%rax,%rax,2),%ecx
mov    %rsi,0x18(%rsp)
mov    %rcx,0x10(%rsp)
lea    (%rsi,%rcx,1),%rax
mov    %rax,0x20(%rsp)
imul   $0x35,%r15d,%eax
mov    %rax,0x8(%rsp)
lea    (%rdi,%rax,1),%r13
lea    0x3(%rsp),%rdi
mov    %ebx,%esi
mov    %r8d,%edx
mov    $0x1,%ecx
xor    %r8d,%r8d
call   1040 <atm_header_create@plt>
mov    %r13,%rdi
mov    0x20(%rsp),%rsi
lea    0x3(%rsp),%rdx
call   1030 <atm_cell_create_with_header@plt>
lea    0x3(%rsp),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1040 <atm_header_create@plt>
test   %r15d,%r15d
je     122c <aal5_frame_to_atm_cells+0x10c>
mov    0x8(%rsp),%rax
lea    (%rax,%r14,1),%rbx
add    $0xffffffffffffffcb,%rbx
mov    0x18(%rsp),%rax
mov    0x10(%rsp),%rcx
lea    (%rcx,%rax,1),%rbp
add    $0xffffffffffffffd0,%rbp
lea    0x3(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1030 <atm_cell_create_with_header@plt>
add    $0xffffffffffffffcb,%rbx
add    $0xffffffffffffffd0,%rbp
add    $0xffffffff,%r15d
jne    1210 <aal5_frame_to_atm_cells+0xf0>
imul   $0x35,%r12d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @aal5_frame_to_atm_cells(i8* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca [5 x i8]
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %6, i64 0, i64 0
%8 = srem i32 %2, 48
%9 = sdiv i32 %2, 48
%10 = icmp eq i32 %8, 0
br i1 %10, label %11, label %34
11: ; preds = %5
%12 = add nsw i32 %9, -1
%13 = mul i32 %12, 48
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = mul i32 %12, 53
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = call i32 @atm_header_create(i8* %7, i32 %3, i32 %4, i32 1, i32 0)
%20 = call i32 @atm_cell_create_with_header(i8* %18, i8* %15, i8* %7)
%21 = call i32 @atm_header_create(i8* %7, i32 %3, i32 %4, i32 0, i32 0)
%22 = icmp eq i32 %12, 0
br i1 %22, label %32, label %23
23: ; preds = %11, %23
%24 = phi i32 [ %27, %23 ], [ %12, %11 ]
%25 = phi i8* [ %29, %23 ], [ %18, %11 ]
%26 = phi i8* [ %28, %23 ], [ %15, %11 ]
%27 = add i32 %24, -1
%28 = getelementptr inbounds i8, i8* %26, i64 -48
%29 = getelementptr inbounds i8, i8* %25, i64 -53
%30 = call i32 @atm_cell_create_with_header(i8* %29, i8* %28, i8* %7)
%31 = icmp eq i32 %27, 0
br i1 %31, label %32, label %23
32: ; preds = %23, %11
%33 = mul nsw i32 %9, 53
br label %34
34: ; preds = %5, %32
%35 = phi i32 [ %33, %32 ], [ -1, %5 ]
ret i32 %35
}