#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*/ err(int, char *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
char *strregerror(int errcode, regex_t *preg) {
  static char *oe;
  size_t s;
  if (oe != NULL)
    free(oe);
  s = regerror(errcode, preg, NULL, 0);
  if ((oe = malloc(s)) == NULL)
    err(1, "malloc");
  (void)regerror(errcode, preg, oe, s);
  return (oe);
}


x86 assembly (clang, -O0):
<strregerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,0x2ef1(%rip)
je     1169 <strregerror+0x29>
mov    0x2ee4(%rip),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1040 <regerror@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,0x2eb8(%rip)
cmp    $0x0,%rax
jne    11ab <strregerror+0x6b>
mov    $0x1,%edi
lea    0xe5a(%rip),%rsi
call   1050 <err@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e8f(%rip),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <regerror@plt>
mov    0x2e7f(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strregerror>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2ef8(%rip),%rdi
test   %rdi,%rdi
je     115a <strregerror+0x1a>
call   1030 <free@plt>
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <regerror@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <malloc@plt>
mov    %rax,0x2ece(%rip)
test   %rax,%rax
jne    1197 <strregerror+0x57>
lea    0xe7a(%rip),%rsi
mov    $0x1,%edi
call   1050 <err@plt>
mov    0x2eb1(%rip),%rax
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1040 <regerror@plt>
mov    0x2e9a(%rip),%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@strregerror.oe = internal unnamed_addr global i8* null
@.str = [7 x i8] c"malloc\00"
define i8* @strregerror(i32 %0, i32* %1) {
%3 = load i8*, i8** @strregerror.oe
%4 = icmp eq i8* %3, null
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @free(i8* %3)
br label %7
7: ; preds = %5, %2
%8 = tail call i64 @regerror(i32 %0, i32* %1, i8* null, i64 0)
%9 = tail call i8* @malloc(i64 %8)
store i8* %9, i8** @strregerror.oe
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %14
11: ; preds = %7
%12 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%13 = load i8*, i8** @strregerror.oe
br label %14
14: ; preds = %11, %7
%15 = phi i8* [ %13, %11 ], [ %9, %7 ]
%16 = tail call i64 @regerror(i32 %0, i32* %1, i8* %15, i64 %8)
%17 = load i8*, i8** @strregerror.oe
ret i8* %17
}