#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*/ XORblock(char *, char *, char *, int);
char *alloca(int);
int /*<<< orphan*/ diffuse(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int AF_merge(unsigned char *src, unsigned char *dst, int afsize, int stripes) {
  int i;
  char *bufblock;
  int blocksize = afsize / stripes;
  bufblock = alloca(blocksize);
  memset(bufblock, 0, blocksize);
  for (i = 0; i < (stripes - 1); i++) {
    XORblock((char *)(src + (blocksize * i)), bufblock, bufblock, blocksize);
    diffuse((unsigned char *)bufblock, (unsigned char *)bufblock, blocksize);
  }
  XORblock((char *)(src + blocksize * (stripes - 1)), bufblock, (char *)dst,
           blocksize);
  return 0;
}


x86 assembly (clang, -O0):
<AF_merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cltd
idivl  -0x18(%rbp)
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
call   1050 <alloca@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d0 <AF_merge+0x90>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%eax
imul   -0x1c(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <XORblock@plt>
mov    -0x28(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1060 <diffuse@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1181 <AF_merge+0x41>
mov    -0x8(%rbp),%rdi
mov    -0x2c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
cltq
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1040 <XORblock@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<AF_merge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %ecx,%ebp
mov    %edx,%eax
mov    %rsi,0x10(%rsp)
mov    %rdi,%r15
cltd
idiv   %ecx
mov    %eax,%r12d
mov    %eax,%edi
call   1050 <alloca@plt>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %r12d,%edx
call   1030 <memset@plt>
lea    -0x1(%rbp),%eax
mov    %eax,0xc(%rsp)
cmp    $0x2,%ebp
jl     11b8 <AF_merge+0x78>
movslq %r12d,%r14
mov    0xc(%rsp),%r13d
mov    %r15,%rbp
xchg   %ax,%ax
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %rbx,%rdx
mov    %r12d,%ecx
call   1040 <XORblock@plt>
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1060 <diffuse@plt>
add    %r14,%rbp
add    $0xffffffffffffffff,%r13
jne    1190 <AF_merge+0x50>
mov    %r12d,%eax
imul   0xc(%rsp),%eax
cltq
add    %rax,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    0x10(%rsp),%rdx
mov    %r12d,%ecx
call   1040 <XORblock@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @AF_merge(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %7
%13 = load i32, i32* %8
%14 = sdiv i32 %12, %13
store i32 %14, i32* %11
%15 = load i32, i32* %11
%16 = call i8* @alloca(i32 %15)
store i8* %16, i8** %10
%17 = load i8*, i8** %10
%18 = load i32, i32* %11
%19 = call i32 @memset(i8* %17, i32 0, i32 %18)
store i32 0, i32* %9
br label %20
20: ; preds = %40, %4
%21 = load i32, i32* %9
%22 = load i32, i32* %8
%23 = sub nsw i32 %22, 1
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %43
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i32, i32* %11
%28 = load i32, i32* %9
%29 = mul nsw i32 %27, %28
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %26, i64 %30
%32 = load i8*, i8** %10
%33 = load i8*, i8** %10
%34 = load i32, i32* %11
%35 = call i32 @XORblock(i8* %31, i8* %32, i8* %33, i32 %34)
%36 = load i8*, i8** %10
%37 = load i8*, i8** %10
%38 = load i32, i32* %11
%39 = call i32 @diffuse(i8* %36, i8* %37, i32 %38)
br label %40
40: ; preds = %25
%41 = load i32, i32* %9
%42 = add nsw i32 %41, 1
store i32 %42, i32* %9
br label %20
43: ; preds = %20
%44 = load i8*, i8** %5
%45 = load i32, i32* %11
%46 = load i32, i32* %8
%47 = sub nsw i32 %46, 1
%48 = mul nsw i32 %45, %47
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %44, i64 %49
%51 = load i8*, i8** %10
%52 = load i8*, i8** %6
%53 = load i32, i32* %11
%54 = call i32 @XORblock(i8* %50, i8* %51, i8* %52, i32 %53)
ret i32 0
}

LLVM IR (-O2):
define i32 @AF_merge(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = sdiv i32 %2, %3
%6 = tail call i8* @alloca(i32 %5)
%7 = tail call i32 @memset(i8* %6, i32 0, i32 %5)
%8 = add i32 %3, -1
%9 = icmp sgt i32 %3, 1
br i1 %9, label %10, label %21
10: ; preds = %4
%11 = sext i32 %5 to i64
%12 = zext i32 %8 to i64
br label %13
13: ; preds = %10, %13
%14 = phi i64 [ 0, %10 ], [ %19, %13 ]
%15 = mul nsw i64 %14, %11
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = tail call i32 @XORblock(i8* %16, i8* %6, i8* %6, i32 %5)
%18 = tail call i32 @diffuse(i8* %6, i8* %6, i32 %5)
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %12
br i1 %20, label %21, label %13
21: ; preds = %13, %4
%22 = mul nsw i32 %5, %8
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
%25 = tail call i32 @XORblock(i8* %24, i8* %6, i8* %1, i32 %5)
ret i32 0
}