#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*/ free(char *);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
char *xmalloc(size_t);
char *strregerror(int errcode, regex_t *preg) {
  char buf[1];
  static char *oe;
  size_t s;
  if (oe != NULL)
    free(oe);
  s = regerror(errcode, preg, buf, 0);
  oe = xmalloc(s);
  (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,0x2ef9(%rip)
je     1159 <strregerror+0x29>
mov    0x2eec(%rip),%rdi
call   1030 <free@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    -0x11(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <regerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <xmalloc@plt>
mov    %rax,0x2ebf(%rip)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2eb1(%rip),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <regerror@plt>
mov    0x2ea1(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strregerror>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
mov    0x2efc(%rip),%rdi
test   %rdi,%rdi
je     114e <strregerror+0x1e>
call   1030 <free@plt>
lea    0xf(%rsp),%rdx
mov    %ebp,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1050 <regerror@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <xmalloc@plt>
mov    %rax,0x2ecf(%rip)
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbx,%rcx
call   1050 <regerror@plt>
mov    0x2eb8(%rip),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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