#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(char *);
int l_alloctmpsubst(int l, char **lsubst, char **ldir, int *err) {
  if ((*lsubst = (char *)calloc(l + 2, sizeof(char *))) == NULL) {
    *err = -3;
    return (-1);
  }
  if (ldir == NULL)
    return 0;
  if ((*ldir = (char *)calloc(l + 2, sizeof(char *))) == NULL) {
    free(*lsubst);
    *err = -3;
    return (-1);
  }
  return 0;
}


x86 assembly (clang, -O0):
<l_alloctmpsubst>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%edi
add    $0x2,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    -0x10(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    116e <l_alloctmpsubst+0x4e>
mov    -0x20(%rbp),%rax
movl   $0xfffffffd,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <l_alloctmpsubst+0xaf>
cmpq   $0x0,-0x18(%rbp)
jne    1185 <l_alloctmpsubst+0x65>
movl   $0x0,-0x4(%rbp)
jmp    11cf <l_alloctmpsubst+0xaf>
mov    -0x8(%rbp),%edi
add    $0x2,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    -0x18(%rbp),%rcx
mov    %rax,(%rcx)
cmp    $0x0,%rax
jne    11c8 <l_alloctmpsubst+0xa8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
movl   $0xfffffffd,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <l_alloctmpsubst+0xaf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_alloctmpsubst>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %edi,%ebx
add    $0x2,%ebx
mov    %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     116e <l_alloctmpsubst+0x4e>
xor    %ebp,%ebp
test   %r12,%r12
je     117a <l_alloctmpsubst+0x5a>
mov    %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
jne    117a <l_alloctmpsubst+0x5a>
mov    (%r15),%rdi
call   1030 <free@plt>
movl   $0xfffffffd,(%r14)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @l_alloctmpsubst(i32 %0, i8** %1, i8** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8**
%9 = alloca i32*
store i32 %0, i32* %6
store i8** %1, i8*** %7
store i8** %2, i8*** %8
store i32* %3, i32** %9
%10 = load i32, i32* %6
%11 = add nsw i32 %10, 2
%12 = call i64 @calloc(i32 %11, i32 8)
%13 = inttoptr i64 %12 to i8*
%14 = load i8**, i8*** %7
store i8* %13, i8** %14
%15 = icmp eq i8* %13, null
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = load i32*, i32** %9
store i32 -3, i32* %17
store i32 -1, i32* %5
br label %35
18: ; preds = %4
%19 = load i8**, i8*** %8
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %5
br label %35
22: ; preds = %18
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 2
%25 = call i64 @calloc(i32 %24, i32 8)
%26 = inttoptr i64 %25 to i8*
%27 = load i8**, i8*** %8
store i8* %26, i8** %27
%28 = icmp eq i8* %26, null
br i1 %28, label %29, label %34
29: ; preds = %22
%30 = load i8**, i8*** %7
%31 = load i8*, i8** %30
%32 = call i32 @free(i8* %31)
%33 = load i32*, i32** %9
store i32 -3, i32* %33
store i32 -1, i32* %5
br label %35
34: ; preds = %22
store i32 0, i32* %5
br label %35
35: ; preds = %34, %29, %21, %16
%36 = load i32, i32* %5
ret i32 %36
}

LLVM IR (-O2):
define i32 @l_alloctmpsubst(i32 %0, i8** nocapture %1, i8** writeonly %2, i32* nocapture writeonly %3) {
%5 = add nsw i32 %0, 2
%6 = tail call i64 @calloc(i32 %5, i32 8)
%7 = inttoptr i64 %6 to i8*
store i8* %7, i8** %1
%8 = icmp eq i64 %6, 0
br i1 %8, label %18, label %9
9: ; preds = %4
%10 = icmp eq i8** %2, null
br i1 %10, label %19, label %11
11: ; preds = %9
%12 = tail call i64 @calloc(i32 %5, i32 8)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %2
%14 = icmp eq i64 %12, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %1
%17 = tail call i32 @free(i8* %16)
br label %18
18: ; preds = %4, %15
store i32 -3, i32* %3
br label %19
19: ; preds = %18, %11, %9
%20 = phi i32 [ 0, %9 ], [ 0, %11 ], [ -1, %18 ]
ret i32 %20
}