#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*/ free(unsigned char *);
unsigned char *malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, unsigned char, int);
unsigned char *sizeAlign(unsigned char *data, int size, int align,
                         unsigned char fill, int *outSize) {
  int newSize;
  unsigned char *result;
  newSize = (size + (align - 1));
  newSize /= align;
  newSize *= align;
  *outSize = newSize;
  result = malloc(newSize);
  memcpy(result, data, size);
  memset(result + size, fill, newSize - size);
  free(data);
  return result;
}


x86 assembly (clang, -O0):
<sizeAlign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %cl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
add    %ecx,%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x24(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
imul   -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
movslq -0xc(%rbp),%rax
add    %rax,%rdi
mov    -0x11(%rbp),%al
mov    -0x24(%rbp),%edx
sub    -0xc(%rbp),%edx
movzbl %al,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sizeAlign>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r14d
mov    %edx,%ecx
mov    %esi,%r12d
mov    %rdi,%r15
lea    (%r12,%rcx,1),%ebx
add    $0xffffffff,%ebx
mov    %ebx,%eax
cltd
idiv   %ecx
sub    %edx,%ebx
mov    %ebx,(%r8)
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r12d,%edx
call   1050 <memcpy@plt>
movslq %r12d,%rax
lea    (%rax,%rbp,1),%rdi
sub    %eax,%ebx
mov    %r14d,%esi
mov    %ebx,%edx
call   1040 <memset@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @sizeAlign(i8* %0, i32 %1, i32 %2, i8 zeroext %3, i32* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i8*
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i8 %3, i8* %9
store i32* %4, i32** %10
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = sub nsw i32 %14, 1
%16 = add nsw i32 %13, %15
store i32 %16, i32* %11
%17 = load i32, i32* %8
%18 = load i32, i32* %11
%19 = sdiv i32 %18, %17
store i32 %19, i32* %11
%20 = load i32, i32* %8
%21 = load i32, i32* %11
%22 = mul nsw i32 %21, %20
store i32 %22, i32* %11
%23 = load i32, i32* %11
%24 = load i32*, i32** %10
store i32 %23, i32* %24
%25 = load i32, i32* %11
%26 = call i8* @malloc(i32 %25)
store i8* %26, i8** %12
%27 = load i8*, i8** %12
%28 = load i8*, i8** %6
%29 = load i32, i32* %7
%30 = call i32 @memcpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %12
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
%35 = load i8, i8* %9
%36 = load i32, i32* %11
%37 = load i32, i32* %7
%38 = sub nsw i32 %36, %37
%39 = call i32 @memset(i8* %34, i8 zeroext %35, i32 %38)
%40 = load i8*, i8** %6
%41 = call i32 @free(i8* %40)
%42 = load i8*, i8** %12
ret i8* %42
}

LLVM IR (-O2):
define i8* @sizeAlign(i8* %0, i32 %1, i32 %2, i8 zeroext %3, i32* nocapture writeonly %4) {
%6 = add i32 %1, -1
%7 = add i32 %6, %2
%8 = srem i32 %7, %2
%9 = sub i32 %7, %8
store i32 %9, i32* %4
%10 = tail call i8* @malloc(i32 %9)
%11 = tail call i32 @memcpy(i8* %10, i8* %0, i32 %1)
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = sub nsw i32 %9, %1
%15 = tail call i32 @memset(i8* %13, i8 zeroext %3, i32 %14)
%16 = tail call i32 @free(i8* %0)
ret i8* %10
}