#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*/ _log_error(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int, int);
void *sagetv_malloc2(int size, int line) {
  char *p;
  ;
  if (size < 0 || size > 1024 * 64) {
    char buf[128];
    sprintf(buf, "!!!Memeory alloc size invalid size:%d TSParser.c::line %d\n",
            size, line);
    _log_error(buf);
    return NULL;
  }
  p = (char *)malloc(size);
  if (p)
    memset(p, 0, size);
  else {
    char buf[128];
    sprintf(buf, "!!!Memeory alloc failed  size:%d TSParser.c::line %d\n", size,
            line);
    _log_error(buf);
  }
  return (void *)p;
}


x86 assembly (clang, -O0):
<sagetv_malloc2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1168 <sagetv_malloc2+0x28>
cmpl   $0x10000,-0xc(%rbp)
jle    119a <sagetv_malloc2+0x5a>
lea    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe84(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1050 <_log_error@plt>
movq   $0x0,-0x8(%rbp)
jmp    11f1 <sagetv_malloc2+0xb1>
mov    -0xc(%rbp),%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11c4 <sagetv_malloc2+0x84>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11e9 <sagetv_malloc2+0xa9>
lea    -0x120(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x10(%rbp),%ecx
lea    0xe63(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1050 <_log_error@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sagetv_malloc2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
cmp    $0x10001,%edi
jb     117d <sagetv_malloc2+0x3d>
lea    0xe9f(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <_log_error@plt>
xor    %ebx,%ebx
jmp    11b9 <sagetv_malloc2+0x79>
mov    %ebp,%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     119a <sagetv_malloc2+0x5a>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <memset@plt>
jmp    11b9 <sagetv_malloc2+0x79>
lea    0xe9a(%rip),%rsi
mov    %rsp,%r15
mov    %r15,%rdi
mov    %ebp,%edx
mov    %r14d,%ecx
call   1060 <sprintf@plt>
mov    %r15,%rdi
call   1050 <_log_error@plt>
mov    %rbx,%rax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [59 x i8] c"!!!Memeory alloc size invalid size:%d TSParser.c::line %d\0A\00"
@.str.1 = [54 x i8] c"!!!Memeory alloc failed size:%d TSParser.c::line %d\0A\00"
define i8* @sagetv_malloc2(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [128 x i8]
%8 = alloca [128 x i8]
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 0
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp sgt i32 %12, 65536
br i1 %13, label %14, label %21
14: ; preds = %11, %2
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%16 = load i32, i32* %4
%17 = load i32, i32* %5
%18 = call i32 @sprintf(i8* %15, i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = call i32 @_log_error(i8* %19)
store i8* null, i8** %3
br label %40
21: ; preds = %11
%22 = load i32, i32* %4
%23 = call i64 @malloc(i32 %22)
%24 = inttoptr i64 %23 to i8*
store i8* %24, i8** %6
%25 = load i8*, i8** %6
%26 = icmp ne i8* %25, null
br i1 %26, label %27, label %31
27: ; preds = %21
%28 = load i8*, i8** %6
%29 = load i32, i32* %4
%30 = call i32 @memset(i8* %28, i32 0, i32 %29)
br label %38
31: ; preds = %21
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%33 = load i32, i32* %4
%34 = load i32, i32* %5
%35 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%37 = call i32 @_log_error(i8* %36)
br label %38
38: ; preds = %31, %27
%39 = load i8*, i8** %6
store i8* %39, i8** %3
br label %40
40: ; preds = %38, %14
%41 = load i8*, i8** %3
ret i8* %41
}

LLVM IR (-O2):
@.str = [59 x i8] c"!!!Memeory alloc size invalid size:%d TSParser.c::line %d\0A\00"
@.str.1 = [54 x i8] c"!!!Memeory alloc failed size:%d TSParser.c::line %d\0A\00"
define i8* @sagetv_malloc2(i32 %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = icmp ugt i32 %0, 65536
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%8 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1)
%9 = call i32 @_log_error(i8* %7)
br label %20
10: ; preds = %2
%11 = tail call i64 @malloc(i32 %0)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @memset(i8* %12, i32 0, i32 %0)
br label %20
16: ; preds = %10
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%18 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1)
%19 = call i32 @_log_error(i8* %17)
br label %20
20: ; preds = %14, %16, %6
%21 = phi i8* [ null, %6 ], [ %12, %16 ], [ %12, %14 ]
ret i8* %21
}