#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 */
void *foveon_camf_matrix(unsigned int *, char const *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ memcpy(void *, void *, int);
int foveon_fixed(void *ptr, int size, const char *name) {
  void *dp;
  unsigned dim[3];
  if (!name)
    return 0;
  dp = foveon_camf_matrix(dim, name);
  if (!dp)
    return 0;
  memcpy(ptr, dp, size * 4);
  free(dp);
  return 1;
}


x86 assembly (clang, -O0):
<foveon_fixed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    115a <foveon_fixed+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <foveon_fixed+0x75>
lea    -0x34(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <foveon_camf_matrix@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1182 <foveon_fixed+0x52>
movl   $0x0,-0x4(%rbp)
jmp    11a5 <foveon_fixed+0x75>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
shl    $0x2,%edx
call   1040 <memcpy@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foveon_fixed>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
test   %rdx,%rdx
je     117b <foveon_fixed+0x4b>
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xc(%rsp),%rdi
mov    %rdx,%rsi
call   1050 <foveon_camf_matrix@plt>
test   %rax,%rax
je     117b <foveon_fixed+0x4b>
mov    %rax,%rbx
shl    $0x2,%r15d
mov    %r14,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @foveon_fixed(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [3 x i32]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %13, label %12
12: ; preds = %3
store i32 0, i32* %4
br label %28
13: ; preds = %3
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %9, i64 0, i64 0
%15 = load i8*, i8** %7
%16 = call i8* @foveon_camf_matrix(i32* %14, i8* %15)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
%18 = icmp ne i8* %17, null
br i1 %18, label %20, label %19
19: ; preds = %13
store i32 0, i32* %4
br label %28
20: ; preds = %13
%21 = load i8*, i8** %5
%22 = load i8*, i8** %8
%23 = load i32, i32* %6
%24 = mul nsw i32 %23, 4
%25 = call i32 @memcpy(i8* %21, i8* %22, i32 %24)
%26 = load i8*, i8** %8
%27 = call i32 @free(i8* %26)
store i32 1, i32* %4
br label %28
28: ; preds = %20, %19, %12
%29 = load i32, i32* %4
ret i32 %29
}

LLVM IR (-O2):
define i32 @foveon_fixed(i8* %0, i32 %1, i8* %2) {
%4 = alloca [3 x i32]
%5 = bitcast [3 x i32]* %4 to i8*
%6 = icmp eq i8* %2, null
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %4, i64 0, i64 0
%9 = call i8* @foveon_camf_matrix(i32* %8, i8* %2)
%10 = icmp eq i8* %9, null
br i1 %10, label %15, label %11
11: ; preds = %7
%12 = shl nsw i32 %1, 2
%13 = call i32 @memcpy(i8* %0, i8* %9, i32 %12)
%14 = call i32 @free(i8* %9)
br label %15
15: ; preds = %7, %3, %11
%16 = phi i32 [ 1, %11 ], [ 0, %3 ], [ 0, %7 ]
ret i32 %16
}