#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(size_t);
size_t regerror(int, int /*<<< orphan*/ *, char *, size_t);
int /*<<< orphan*/ stderr;
int er_error(int i, regex_t reg) {
  size_t length;
  char *buffer = NULL;
  length = regerror(i, &reg, NULL, 0);
  if ((buffer = (char *)malloc(length)) == NULL) {
    fprintf(stderr, "error: malloc buffer\n");
    exit(1);
  }
  regerror(i, &reg, buffer, length);
  fprintf(stderr, "%s\n", buffer);
  free(buffer);
  exit(1);
}


x86 assembly (clang, -O0):
<er_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rdx
call   1050 <regerror@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b5 <er_error+0x65>
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x8(%rbp),%rsi
call   1050 <regerror@plt>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<er_error>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <regerror@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
jne    119e <er_error+0x4e>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rsi
mov    %r14d,%edi
mov    %rax,%rdx
mov    %rbp,%rcx
call   1050 <regerror@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"error: malloc buffer\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @er_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
store i8* null, i8** %6
%7 = load i32, i32* %3
%8 = call i64 @regerror(i32 %7, i32* %4, i8* null, i64 0)
store i64 %8, i64* %5
%9 = load i64, i64* %5
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i32, i32* %3
%19 = load i8*, i8** %6
%20 = load i64, i64* %5
%21 = call i64 @regerror(i32 %18, i32* %4, i8* %19, i64 %20)
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %6
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %6
%26 = call i32 @free(i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"error: malloc buffer\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @er_error(i32 %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = call i64 @regerror(i32 %0, i32* %3, i8* null, i64 0)
%5 = call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = call i64 @regerror(i32 %0, i32* %3, i8* %6, i64 %4)
%14 = load i32, i32* @stderr
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%16 = call i32 @free(i8* %6)
%17 = call i32 @exit(i32 1)
unreachable
}