#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 */
struct zip_error {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _zip_error_set(struct zip_error *, int, int /*<<< orphan*/);
void *malloc(size_t);
int /*<<< orphan*/ memcpy(void *, void const *, size_t);
void *_zip_memdup(const void *mem, size_t len, struct zip_error *error) {
  void *ret;
  ret = malloc(len);
  if (!ret) {
    _zip_error_set(error, 14, 0);
    return NULL;
  }
  memcpy(ret, mem, len);
  return ret;
}


x86 assembly (clang, -O0):
<_zip_memdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1179 <_zip_memdup+0x49>
mov    -0x20(%rbp),%rdi
mov    $0xe,%esi
xor    %edx,%edx
call   1050 <_zip_error_set@plt>
movq   $0x0,-0x8(%rbp)
jmp    1192 <_zip_memdup+0x62>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_zip_memdup>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1161 <_zip_memdup+0x31>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1030 <memcpy@plt>
jmp    1170 <_zip_memdup+0x40>
mov    %r14,%rdi
mov    $0xe,%esi
xor    %edx,%edx
call   1050 <_zip_error_set@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.zip_error = type { i32 }
define i8* @_zip_memdup(i8* %0, i64 %1, %struct.zip_error* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.zip_error*
%8 = alloca i8*
store i8* %0, i8** %5
store i64 %1, i64* %6
store %struct.zip_error* %2, %struct.zip_error** %7
%9 = load i64, i64* %6
%10 = call i8* @malloc(i64 %9)
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = icmp ne i8* %11, null
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load %struct.zip_error*, %struct.zip_error** %7
%15 = call i32 @_zip_error_set(%struct.zip_error* %14, i32 14, i32 0)
store i8* null, i8** %4
br label %22
16: ; preds = %3
%17 = load i8*, i8** %8
%18 = load i8*, i8** %5
%19 = load i64, i64* %6
%20 = call i32 @memcpy(i8* %17, i8* %18, i64 %19)
%21 = load i8*, i8** %8
store i8* %21, i8** %4
br label %22
22: ; preds = %16, %13
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
%struct.zip_error = type { i32 }
define i8* @_zip_memdup(i8* %0, i64 %1, %struct.zip_error* %2) {
%4 = tail call i8* @malloc(i64 %1)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @_zip_error_set(%struct.zip_error* %2, i32 14, i32 0)
br label %10
8: ; preds = %3
%9 = tail call i32 @memcpy(i8* %4, i8* %0, i64 %1)
br label %10
10: ; preds = %8, %6
ret i8* %4
}