#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*/ memmove(unsigned char *, unsigned char *, size_t);
int normalize_bignum(unsigned char *buf, size_t buf_size, size_t num_size) {
  if (buf_size < num_size)
    return -1;
  memmove(buf + buf_size - num_size, buf, num_size);
  while (num_size < buf_size) {
    *buf++ = 0;
    num_size++;
  }
  return 0;
}


x86 assembly (clang, -O0):
<normalize_bignum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    113e <normalize_bignum+0x2e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1194 <normalize_bignum+0x84>
mov    -0x10(%rbp),%rdi
add    -0x18(%rbp),%rdi
xor    %eax,%eax
sub    -0x20(%rbp),%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1030 <memmove@plt>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    118d <normalize_bignum+0x7d>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115c <normalize_bignum+0x4c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<normalize_bignum>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebp
cmp    %rdx,%rsi
jb     115e <normalize_bignum+0x3e>
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
add    %rsi,%rdi
sub    %rdx,%rdi
mov    %r14,%rsi
call   1040 <memmove@plt>
xor    %ebp,%ebp
sub    %rbx,%r15
jbe    115e <normalize_bignum+0x3e>
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15,%rdx
call   1030 <memset@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @normalize_bignum(i8* %0, i64 %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%8 = load i64, i64* %6
%9 = load i64, i64* %7
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %12
11: ; preds = %3
store i32 -1, i32* %4
br label %32
12: ; preds = %3
%13 = load i8*, i8** %5
%14 = load i64, i64* %6
%15 = getelementptr inbounds i8, i8* %13, i64 %14
%16 = load i64, i64* %7
%17 = sub i64 0, %16
%18 = getelementptr inbounds i8, i8* %15, i64 %17
%19 = load i8*, i8** %5
%20 = load i64, i64* %7
%21 = call i32 @memmove(i8* %18, i8* %19, i64 %20)
br label %22
22: ; preds = %26, %12
%23 = load i64, i64* %7
%24 = load i64, i64* %6
%25 = icmp ult i64 %23, %24
br i1 %25, label %26, label %31
26: ; preds = %22
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 0, i8* %27
%29 = load i64, i64* %7
%30 = add i64 %29, 1
store i64 %30, i64* %7
br label %22
31: ; preds = %22
store i32 0, i32* %4
br label %32
32: ; preds = %31, %11
%33 = load i32, i32* %4
ret i32 %33
}

LLVM IR (-O2):
define i32 @normalize_bignum(i8* %0, i64 %1, i64 %2) {
%4 = icmp ult i64 %1, %2
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = getelementptr inbounds i8, i8* %0, i64 %1
%7 = sub i64 0, %2
%8 = getelementptr inbounds i8, i8* %6, i64 %7
%9 = tail call i32 @memmove(i8* %8, i8* %0, i64 %2)
%10 = icmp ugt i64 %1, %2
br i1 %10, label %11, label %13
11: ; preds = %5
%12 = sub i64 %1, %2
br label %13
13: ; preds = %11, %5, %3
%14 = phi i32 [ -1, %3 ], [ 0, %5 ], [ 0, %11 ]
ret i32 %14
}