#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;

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int);
char *malloc(size_t);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
char *regex_get_error(int errcode, regex_t *compiled) {
  size_t length;
  char *buf;
  length = regerror(errcode, compiled, NULL, 0);
  buf = malloc(length);
  if (buf == 0) {
    error("Virtual memory exhausted\n");
    exit(1);
  }
  regerror(errcode, compiled, buf, length);
  return buf;
}


x86 assembly (clang, -O0):
<regex_get_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1030 <regerror@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <regex_get_error+0x54>
lea    0xe7b(%rip),%rdi
call   1050 <error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1030 <regerror@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<regex_get_error>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <regerror@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <malloc@plt>
test   %rax,%rax
je     1188 <regex_get_error+0x48>
mov    %rax,%rbp
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1030 <regerror@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe71(%rip),%rdi
call   1050 <error@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [26 x i8] c"Virtual memory exhausted\0A\00"
define i8* @regex_get_error(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
store i32 %0, i32* %3
store i32* %1, i32** %4
%7 = load i32, i32* %3
%8 = load i32*, i32** %4
%9 = call i64 @regerror(i32 %7, i32* %8, i8* null, i64 0)
store i64 %9, i64* %5
%10 = load i64, i64* %5
%11 = call i8* @malloc(i64 %10)
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %3
%19 = load i32*, i32** %4
%20 = load i8*, i8** %6
%21 = load i64, i64* %5
%22 = call i64 @regerror(i32 %18, i32* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %6
ret i8* %23
}

LLVM IR (-O2):
@.str = [26 x i8] c"Virtual memory exhausted\0A\00"
define i8* @regex_get_error(i32 %0, i32* %1) {
%3 = tail call i64 @regerror(i32 %0, i32* %1, i8* null, i64 0)
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @exit(i32 1)
unreachable
9: ; preds = %2
%10 = tail call i64 @regerror(i32 %0, i32* %1, i8* %4, i64 %3)
ret i8* %4
}