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

/* Variables and functions */
scalar_t__ malloc(size_t);
size_t regerror(int, int /*<<< orphan*/ *, char *, int);
char *regerr(regex_t *preg, int errcode) {
  size_t errlen;
  char *errbuf;
  errlen = regerror(errcode, preg, NULL, 0);
  errbuf = (char *)malloc(errlen + 1);
  if (errbuf == 0) {
    return NULL;
  } else {
    regerror(errcode, preg, errbuf, sizeof(errbuf));
    return errbuf;
  }
}


x86 assembly (clang, -O0):
<regerr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <regerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116e <regerr+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    118b <regerr+0x6b>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    $0x8,%ecx
call   1030 <regerror@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regerr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
xor    %ebp,%ebp
mov    %esi,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <regerror@plt>
lea    0x1(%rax),%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1164 <regerr+0x44>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
mov    $0x8,%ecx
call   1030 <regerror@plt>
mov    %rbx,%rbp
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @regerr(i32* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i64
%7 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = load i32*, i32** %4
%10 = call i64 @regerror(i32 %8, i32* %9, i8* null, i32 0)
store i64 %10, i64* %6
%11 = load i64, i64* %6
%12 = add i64 %11, 1
%13 = call i64 @malloc(i64 %12)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %2
store i8* null, i8** %3
br label %24
18: ; preds = %2
%19 = load i32, i32* %5
%20 = load i32*, i32** %4
%21 = load i8*, i8** %7
%22 = call i64 @regerror(i32 %19, i32* %20, i8* %21, i32 8)
%23 = load i8*, i8** %7
store i8* %23, i8** %3
br label %24
24: ; preds = %18, %17
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
define i8* @regerr(i32* %0, i32 %1) {
%3 = tail call i64 @regerror(i32 %1, i32* %0, i8* null, i32 0)
%4 = add i64 %3, 1
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i64 @regerror(i32 %1, i32* %0, i8* %6, i32 8)
br label %10
10: ; preds = %2, %8
%11 = phi i8* [ %6, %8 ], [ null, %2 ]
ret i8* %11
}