#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*/ assert(int);
int /*<<< orphan*/ copy_int(int, void *, int);
int /*<<< orphan*/ free(void *);
void *malloc(int);
int main(int argc, char *argv[]) {
  int maxbytes = sizeof(int) * 10;
  void *buf = malloc(maxbytes);
  int val;
  val = 0x12345678;
  copy_int(val, buf, maxbytes);
  assert(*(int *)buf == val);
  val = 0xAABBCCDD;
  copy_int(val, buf, 0);
  assert(*(int *)buf != val);
  free(buf);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x28,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x12345678,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <copy_int@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movl   $0xaabbccdd,-0x24(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
xor    %edx,%edx
call   1050 <copy_int@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
cmp    -0x24(%rbp),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x28,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x12345678,%edi
mov    %rax,%rsi
mov    $0x28,%edx
call   1050 <copy_int@plt>
xor    %edi,%edi
cmpl   $0x12345678,(%rbx)
sete   %dil
call   1040 <assert@plt>
mov    $0xaabbccdd,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <copy_int@plt>
xor    %edi,%edi
cmpl   $0xaabbccdd,(%rbx)
setne  %dil
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 40, i32* %6
%9 = load i32, i32* %6
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %7
store i32 305419896, i32* %8
%11 = load i32, i32* %8
%12 = load i8*, i8** %7
%13 = load i32, i32* %6
%14 = call i32 @copy_int(i32 %11, i8* %12, i32 %13)
%15 = load i8*, i8** %7
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %16
%18 = load i32, i32* %8
%19 = icmp eq i32 %17, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
store i32 -1430532899, i32* %8
%22 = load i32, i32* %8
%23 = load i8*, i8** %7
%24 = call i32 @copy_int(i32 %22, i8* %23, i32 0)
%25 = load i8*, i8** %7
%26 = bitcast i8* %25 to i32*
%27 = load i32, i32* %26
%28 = load i32, i32* %8
%29 = icmp ne i32 %27, %28
%30 = zext i1 %29 to i32
%31 = call i32 @assert(i32 %30)
%32 = load i8*, i8** %7
%33 = call i32 @free(i8* %32)
ret i32 0
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(40) i8* @malloc(i32 40)
%4 = tail call i32 @copy_int(i32 305419896, i8* %3, i32 40)
%5 = bitcast i8* %3 to i32*
%6 = load i32, i32* %5
%7 = icmp eq i32 %6, 305419896
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @copy_int(i32 -1430532899, i8* %3, i32 0)
%11 = load i32, i32* %5
%12 = icmp ne i32 %11, -1430532899
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @free(i8* %3)
ret i32 0
}