#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 *_talloc_named_const(void const *, size_t, char const *);
int /*<<< orphan*/ lock();
int /*<<< orphan*/ unlock();
void *_talloc_array(const void *ctx, size_t el_size, unsigned count,
                    const char *name) {
  void *p;
  if (count >= 0x10000000 / el_size) {
    return NULL;
  }
  lock();
  p = _talloc_named_const(ctx, el_size * count, name);
  unlock();
  return p;
}


x86 assembly (clang, -O0):
<_talloc_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
mov    %rax,-0x38(%rbp)
mov    $0x10000000,%eax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jb     1178 <_talloc_array+0x48>
movq   $0x0,-0x8(%rbp)
jmp    11aa <_talloc_array+0x7a>
mov    $0x0,%al
call   1040 <lock@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%eax
imul   %rax,%rsi
mov    -0x28(%rbp),%rdx
call   1050 <_talloc_named_const@plt>
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <unlock@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_talloc_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %edx,%ebx
cmp    $0x10000000,%rsi
ja     115f <_talloc_array+0x2f>
mov    $0x10000000,%eax
xor    %edx,%edx
div    %r12d
cmp    %rbx,%rax
ja     1166 <_talloc_array+0x36>
xor    %eax,%eax
jmp    118c <_talloc_array+0x5c>
xor    %eax,%eax
cmp    %rbx,%rax
jbe    115b <_talloc_array+0x2b>
xor    %eax,%eax
call   1040 <lock@plt>
imul   %r12,%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <_talloc_named_const@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <unlock@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @_talloc_array(i8* %0, i64 %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
store i8* %0, i8** %6
store i64 %1, i64* %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%11 = load i32, i32* %8
%12 = zext i32 %11 to i64
%13 = load i64, i64* %7
%14 = udiv i64 268435456, %13
%15 = icmp uge i64 %12, %14
br i1 %15, label %16, label %17
16: ; preds = %4
store i8* null, i8** %5
br label %28
17: ; preds = %4
%18 = call i32 (...) @lock()
%19 = load i8*, i8** %6
%20 = load i64, i64* %7
%21 = load i32, i32* %8
%22 = zext i32 %21 to i64
%23 = mul i64 %20, %22
%24 = load i8*, i8** %9
%25 = call i8* @_talloc_named_const(i8* %19, i64 %23, i8* %24)
store i8* %25, i8** %10
%26 = call i32 (...) @unlock()
%27 = load i8*, i8** %10
store i8* %27, i8** %5
br label %28
28: ; preds = %17, %16
%29 = load i8*, i8** %5
ret i8* %29
}

LLVM IR (-O2):
define i8* @_talloc_array(i8* %0, i64 %1, i32 %2, i8* %3) {
%5 = zext i32 %2 to i64
%6 = udiv i64 268435456, %1
%7 = icmp ugt i64 %6, %5
br i1 %7, label %8, label %13
8: ; preds = %4
%9 = tail call i32 (...) @lock()
%10 = mul i64 %5, %1
%11 = tail call i8* @_talloc_named_const(i8* %0, i64 %10, i8* %3)
%12 = tail call i32 (...) @unlock()
br label %13
13: ; preds = %4, %8
%14 = phi i8* [ %11, %8 ], [ null, %4 ]
ret i8* %14
}