#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*/ foo(int *, int);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(int);
int /*<<< orphan*/ myMemcpy(int *, int *, int);
int /*<<< orphan*/ printf(char *, int);
int main() {
  int a = 2;
  int b = 0;
  int *dev_a;
  dev_a = (int *)malloc(1 * sizeof(int));
  myMemcpy(dev_a, &a, sizeof(int));
  foo(dev_a, a);
  myMemcpy(&b, dev_a, sizeof(int));
  printf("%d", b);
  assert(b == a + 2);
  free(dev_a);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x2,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1070 <myMemcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1080 <foo@plt>
mov    -0x18(%rbp),%rsi
lea    -0xc(%rbp),%rdi
mov    $0x4,%edx
call   1070 <myMemcpy@plt>
mov    -0xc(%rbp),%esi
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x2,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
movl   $0x2,0xc(%rsp)
movl   $0x0,0x8(%rsp)
mov    $0x4,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %rax,%rdi
mov    $0x4,%edx
call   1070 <myMemcpy@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1080 <foo@plt>
lea    0x8(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1070 <myMemcpy@plt>
mov    0x8(%rsp),%esi
lea    0xe43(%rip),%rdi
call   1040 <printf@plt>
mov    0xc(%rsp),%eax
add    $0x2,%eax
xor    %edi,%edi
cmp    %eax,0x8(%rsp)
sete   %dil
call   1050 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 2, i32* %2
store i32 0, i32* %3
%5 = call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %4
%7 = load i32*, i32** %4
%8 = call i32 @myMemcpy(i32* %7, i32* %2, i32 4)
%9 = load i32*, i32** %4
%10 = load i32, i32* %2
%11 = call i32 @foo(i32* %9, i32 %10)
%12 = load i32*, i32** %4
%13 = call i32 @myMemcpy(i32* %3, i32* %12, i32 4)
%14 = load i32, i32* %3
%15 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %3
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 2
%19 = icmp eq i32 %16, %18
%20 = zext i1 %19 to i32
%21 = call i32 @assert(i32 %20)
%22 = load i32*, i32** %4
%23 = call i32 @free(i32* %22)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 2, i32* %1
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = call i32 @myMemcpy(i32* %6, i32* %1, i32 4)
%8 = load i32, i32* %1
%9 = call i32 @foo(i32* %6, i32 %8)
%10 = call i32 @myMemcpy(i32* %2, i32* %6, i32 4)
%11 = load i32, i32* %2
%12 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i32, i32* %2
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 2
%16 = icmp eq i32 %13, %15
%17 = zext i1 %16 to i32
%18 = call i32 @assert(i32 %17)
%19 = call i32 @free(i32* %6)
ret i32 0
}