#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ free(unsigned char *);
unsigned char *malloc(int);
scalar_t__ sisReadOffset(int /*<<< orphan*/ *, unsigned char *, int, int,
                         char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *);
char *sisReadOffsetAlloc(FILE *fp, int len, int off, char *err, int errlen) {
  unsigned char *buf = malloc(len + 1);
  if (!buf) {
    snprintf(err, errlen, "Out of memory");
    return NULL;
  }
  buf[len] = '\0';
  if (sisReadOffset(fp, buf, len, off, err, errlen)) {
    free(buf);
    return NULL;
  }
  return buf;
}


x86 assembly (clang, -O0):
<sisReadOffsetAlloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1194 <sisReadOffsetAlloc+0x54>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
lea    0xe7e(%rip),%rdx
call   1040 <snprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e3 <sisReadOffsetAlloc+0xa3>
mov    -0x30(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8
mov    -0x24(%rbp),%r9d
call   1050 <sisReadOffset@plt>
cmp    $0x0,%rax
je     11db <sisReadOffsetAlloc+0x9b>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11e3 <sisReadOffsetAlloc+0xa3>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sisReadOffsetAlloc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rcx,%r12
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%r13
lea    0x1(%rbp),%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1195 <sisReadOffsetAlloc+0x55>
mov    %rax,%rbx
movslq %ebp,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r15d,%ecx
mov    %r12,%r8
mov    %r14d,%r9d
call   1050 <sisReadOffset@plt>
test   %rax,%rax
je     11a9 <sisReadOffsetAlloc+0x69>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11a7 <sisReadOffsetAlloc+0x67>
lea    0xe64(%rip),%rdx
mov    %r12,%rdi
mov    %r14d,%esi
call   1040 <snprintf@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Out of memory\00"
define i8* @sisReadOffsetAlloc(i32* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8*
store i32* %0, i32** %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%13 = load i32, i32* %8
%14 = add nsw i32 %13, 1
%15 = call i8* @malloc(i32 %14)
store i8* %15, i8** %12
%16 = load i8*, i8** %12
%17 = icmp ne i8* %16, null
br i1 %17, label %22, label %18
18: ; preds = %5
%19 = load i8*, i8** %10
%20 = load i32, i32* %11
%21 = call i32 @snprintf(i8* %19, i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* null, i8** %6
br label %40
22: ; preds = %5
%23 = load i8*, i8** %12
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8 0, i8* %26
%27 = load i32*, i32** %7
%28 = load i8*, i8** %12
%29 = load i32, i32* %8
%30 = load i32, i32* %9
%31 = load i8*, i8** %10
%32 = load i32, i32* %11
%33 = call i64 @sisReadOffset(i32* %27, i8* %28, i32 %29, i32 %30, i8* %31, i32 %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %22
%36 = load i8*, i8** %12
%37 = call i32 @free(i8* %36)
store i8* null, i8** %6
br label %40
38: ; preds = %22
%39 = load i8*, i8** %12
store i8* %39, i8** %6
br label %40
40: ; preds = %38, %35, %18
%41 = load i8*, i8** %6
ret i8* %41
}

LLVM IR (-O2):
@.str = [14 x i8] c"Out of memory\00"
define i8* @sisReadOffsetAlloc(i32* %0, i32 %1, i32 %2, i8* %3, i32 %4) {
%6 = add nsw i32 %1, 1
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @snprintf(i8* %3, i32 %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %5
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %7, i64 %12
store i8 0, i8* %13
%14 = tail call i64 @sisReadOffset(i32* %0, i8* %7, i32 %1, i32 %2, i8* %3, i32 %4)
%15 = icmp eq i64 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = tail call i32 @free(i8* %7)
br label %18
18: ; preds = %11, %16, %9
%19 = phi i8* [ null, %16 ], [ null, %9 ], [ %7, %11 ]
ret i8* %19
}