#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ stderr;
unsigned char *cpGRIBsec(unsigned char *section) {
  int len;
  unsigned char *newsection;
  if (section == NULL)
    return NULL;
  len = ((int)((section[0] << 16) + (section[1] << 8) + section[2]));
  if ((newsection = (unsigned char *)malloc(len)) == NULL) {
    fprintf(stderr, "ran out of memory in cp_section\n");
    exit(8);
  }
  memcpy(newsection, section, len);
  return newsection;
}


x86 assembly (clang, -O0):
<cpGRIBsec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <cpGRIBsec+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11d5 <cpGRIBsec+0x95>
mov    -0x10(%rbp),%rax
movzbl (%rax),%eax
shl    $0x10,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
add    %ecx,%eax
mov    -0x10(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    11bd <cpGRIBsec+0x7d>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x8,%edi
call   1060 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpGRIBsec>:
push   %rbp
push   %r14
push   %rbx
test   %rdi,%rdi
je     117f <cpGRIBsec+0x3f>
mov    %rdi,%rbx
movzbl (%rdi),%eax
shl    $0x10,%eax
movzbl 0x1(%rdi),%ecx
shl    $0x8,%ecx
or     %eax,%ecx
movzbl 0x2(%rdi),%ebp
or     %ecx,%ebp
mov    %ebp,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     118a <cpGRIBsec+0x4a>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
jmp    1182 <cpGRIBsec+0x42>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%edi
lea    0xe66(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x8,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"ran out of memory in cp_section\0A\00"
define i8* @cpGRIBsec(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %9
8: ; preds = %1
store i8* null, i8** %2
br label %40
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = getelementptr inbounds i8, i8* %10, i64 0
%12 = load i8, i8* %11
%13 = zext i8 %12 to i32
%14 = shl i32 %13, 16
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = shl i32 %18, 8
%20 = add nsw i32 %14, %19
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = load i8, i8* %22
%24 = zext i8 %23 to i32
%25 = add nsw i32 %20, %24
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %5
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %34
30: ; preds = %9
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%33 = call i32 @exit(i32 8)
unreachable
34: ; preds = %9
%35 = load i8*, i8** %5
%36 = load i8*, i8** %3
%37 = load i32, i32* %4
%38 = call i32 @memcpy(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %5
store i8* %39, i8** %2
br label %40
40: ; preds = %34, %8
%41 = load i8*, i8** %2
ret i8* %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"ran out of memory in cp_section\0A\00"
define i8* @cpGRIBsec(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %25, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = zext i8 %4 to i32
%6 = shl nuw nsw i32 %5, 16
%7 = getelementptr inbounds i8, i8* %0, i64 1
%8 = load i8, i8* %7
%9 = zext i8 %8 to i32
%10 = shl nuw nsw i32 %9, 8
%11 = or i32 %10, %6
%12 = getelementptr inbounds i8, i8* %0, i64 2
%13 = load i8, i8* %12
%14 = zext i8 %13 to i32
%15 = or i32 %11, %14
%16 = tail call i64 @malloc(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = icmp eq i64 %16, 0
br i1 %18, label %19, label %23
19: ; preds = %3
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @exit(i32 8)
unreachable
23: ; preds = %3
%24 = tail call i32 @memcpy(i8* %17, i8* %0, i32 %15)
br label %25
25: ; preds = %1, %23
%26 = phi i8* [ %17, %23 ], [ null, %1 ]
ret i8* %26
}