#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 */
char *alloca(size_t);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ perror(char *);
size_t regerror(int, int /*<<< orphan*/ const *, char *, size_t);
int /*<<< orphan*/ stderr;
void do_regerror(int errcode, const regex_t *preg) {
  char *errbuf;
  size_t errbuf_size;
  errbuf_size = regerror(errcode, preg, NULL, 0);
  errbuf = alloca(errbuf_size);
  if (!errbuf) {
    perror("alloca");
    return;
  }
  regerror(errcode, preg, errbuf, errbuf_size);
  fprintf(stderr, "%s\n", errbuf);
}


x86 assembly (clang, -O0):
<do_regerror>:
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   1050 <regerror@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <alloca@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    118f <do_regerror+0x4f>
lea    0xe7b(%rip),%rdi
call   1060 <perror@plt>
jmp    11bc <do_regerror+0x7c>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
call   1050 <regerror@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe50(%rip),%rsi
call   1030 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_regerror>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %edi,%r15d
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <regerror@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1040 <alloca@plt>
test   %rax,%rax
je     119c <do_regerror+0x5c>
mov    %rax,%rbx
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rax,%rdx
mov    %rbp,%rcx
call   1050 <regerror@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fprintf@plt>
lea    0xe5d(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <perror@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"alloca\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define void @do_regerror(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
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* %6
%10 = load i64, i64* %6
%11 = call i8* @alloca(i64 %10)
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = icmp ne i8* %12, null
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %25
16: ; preds = %2
%17 = load i32, i32* %3
%18 = load i32*, i32** %4
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = call i64 @regerror(i32 %17, i32* %18, i8* %19, i64 %20)
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %5
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %16, %14
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"alloca\00"
@stderr = global i32 0
@.str.1 = [4 x i8] c"%s\0A\00"
define void @do_regerror(i32 %0, i32* %1) {
%3 = tail call i64 @regerror(i32 %0, i32* %1, i8* null, i64 0)
%4 = tail call i8* @alloca(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
br label %12
8: ; preds = %2
%9 = tail call i64 @regerror(i32 %0, i32* %1, i8* %4, i64 %3)
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %4)
br label %12
12: ; preds = %8, %6
ret void
}