#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*/ FormatError(char *, int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned int);
void Cast(unsigned char *a, unsigned int _a_high, unsigned char *b_,
          unsigned int _b_high) {
  unsigned int i;
  unsigned char b[_b_high + 1];
  memcpy(b, b_, _b_high + 1);
  if (_a_high == _b_high) {
    for (i = 0; i <= _a_high; i++) {
      a[i] = b[i];
    }
  } else {
    FormatError((char *)"cast failed", 11);
  }
}


x86 assembly (clang, -O0):
<Cast>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
mov    -0xc(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b4 <Cast+0x94>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
ja     11af <Cast+0x8f>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1181 <Cast+0x61>
jmp    11c5 <Cast+0xa5>
lea    0xe45(%rip),%rdi
mov    $0xb,%esi
call   1030 <FormatError@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Cast>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
lea    0x1(%r15),%eax
mov    %rsp,%rbx
lea    0xf(%rax),%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    %eax,%edx
call   1040 <memcpy@plt>
cmp    %r15d,%r12d
jne    116f <Cast+0x4f>
mov    %r15d,%edx
add    $0x1,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <memcpy@plt>
jmp    1180 <Cast+0x60>
lea    0xe8a(%rip),%rdi
mov    $0xb,%esi
call   1030 <FormatError@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"cast failed\00"
define void @Cast(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i64
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%12 = load i32, i32* %8
%13 = add i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %10
%16 = alloca i8, i64 %14
store i64 %14, i64* %11
%17 = load i8*, i8** %7
%18 = load i32, i32* %8
%19 = add i32 %18, 1
%20 = call i32 @memcpy(i8* %16, i8* %17, i32 %19)
%21 = load i32, i32* %6
%22 = load i32, i32* %8
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %42
24: ; preds = %4
store i32 0, i32* %9
br label %25
25: ; preds = %38, %24
%26 = load i32, i32* %9
%27 = load i32, i32* %6
%28 = icmp ule i32 %26, %27
br i1 %28, label %29, label %41
29: ; preds = %25
%30 = load i32, i32* %9
%31 = zext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %16, i64 %31
%33 = load i8, i8* %32
%34 = load i8*, i8** %5
%35 = load i32, i32* %9
%36 = zext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
store i8 %33, i8* %37
br label %38
38: ; preds = %29
%39 = load i32, i32* %9
%40 = add i32 %39, 1
store i32 %40, i32* %9
br label %25
41: ; preds = %25
br label %44
42: ; preds = %4
%43 = call i32 @FormatError(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
br label %44
44: ; preds = %42, %41
%45 = load i8*, i8** %10
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"cast failed\00"
define void @Cast(i8* nocapture writeonly %0, i32 %1, i8* %2, i32 %3) {
%5 = add i32 %3, 1
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @memcpy(i8* %7, i8* %2, i32 %5)
%9 = icmp eq i32 %1, %3
br i1 %9, label %10, label %13
10: ; preds = %4
%11 = zext i32 %3 to i64
%12 = add nuw nsw i64 %11, 1
br label %15
13: ; preds = %4
%14 = call i32 @FormatError(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11)
br label %15
15: ; preds = %10, %13
ret void
}