#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 */

/* Variables and functions */
int /*<<< orphan*/ ex_err(char *, char *, int);
int /*<<< orphan*/ ex_fstrncpy(char *, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
void EXERR(char *pname, char *err_string, int *errcode, int pnamelen,
           int err_stringlen) {
  char *proc_name, *error_string;
  if (!(proc_name = malloc((pnamelen + 1) * sizeof(char)))) {
    ex_err("exerr", "Error: failed to allocate space for process name buffer",
           1000);
    return;
  }
  if (!(error_string = malloc((err_stringlen + 1) * sizeof(char)))) {
    free(proc_name);
    ex_err("exerr", "Error: failed to allocate space for error msg buffer",
           1000);
    return;
  }
  ex_fstrncpy(proc_name, pname, pnamelen);
  ex_fstrncpy(error_string, err_string, err_stringlen);
  ex_err(proc_name, error_string, *errcode);
  free(proc_name);
  free(error_string);
}


x86 assembly (clang, -O0):
<EXERR>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1199 <EXERR+0x59>
lea    0xe7d(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x3e8,%edx
call   1060 <ex_err@plt>
jmp    1225 <EXERR+0xe5>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11e0 <EXERR+0xa0>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe36(%rip),%rdi
lea    0xe6d(%rip),%rsi
mov    $0x3e8,%edx
call   1060 <ex_err@plt>
jmp    1225 <EXERR+0xe5>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <ex_fstrncpy@plt>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
call   1040 <ex_fstrncpy@plt>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   1060 <ex_err@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<EXERR>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r15d
mov    %ecx,%r13d
mov    %rdx,%rbp
mov    %rsi,%r12
mov    %rdi,%r14
lea    0x1(%r13),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11cb <EXERR+0x8b>
mov    %rax,%rbx
mov    %rbp,(%rsp)
lea    0x1(%r15),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11db <EXERR+0x9b>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r13d,%edx
call   1040 <ex_fstrncpy@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
mov    %r15d,%edx
call   1040 <ex_fstrncpy@plt>
mov    (%rsp),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <ex_err@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
lea    0xe2e(%rip),%rdi
lea    0xe2d(%rip),%rsi
jmp    11f1 <EXERR+0xb1>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe16(%rip),%rdi
lea    0xe4d(%rip),%rsi
mov    $0x3e8,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <ex_err@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"exerr\00"
@.str.1 = [56 x i8] c"Error: failed to allocate space for process name buffer\00"
@.str.2 = [53 x i8] c"Error: failed to allocate space for error msg buffer\00"
define void @EXERR(i8* %0, i8* %1, i32* %2, i32 %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32* %2, i32** %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = load i32, i32* %9
%14 = add nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 1
%17 = trunc i64 %16 to i32
%18 = call i8* @malloc(i32 %17)
store i8* %18, i8** %11
%19 = icmp ne i8* %18, null
br i1 %19, label %22, label %20
20: ; preds = %5
%21 = call i32 @ex_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 1000)
br label %52
22: ; preds = %5
%23 = load i32, i32* %10
%24 = add nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = mul i64 %25, 1
%27 = trunc i64 %26 to i32
%28 = call i8* @malloc(i32 %27)
store i8* %28, i8** %12
%29 = icmp ne i8* %28, null
br i1 %29, label %34, label %30
30: ; preds = %22
%31 = load i8*, i8** %11
%32 = call i32 @free(i8* %31)
%33 = call i32 @ex_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 1000)
br label %52
34: ; preds = %22
%35 = load i8*, i8** %11
%36 = load i8*, i8** %6
%37 = load i32, i32* %9
%38 = call i32 @ex_fstrncpy(i8* %35, i8* %36, i32 %37)
%39 = load i8*, i8** %12
%40 = load i8*, i8** %7
%41 = load i32, i32* %10
%42 = call i32 @ex_fstrncpy(i8* %39, i8* %40, i32 %41)
%43 = load i8*, i8** %11
%44 = load i8*, i8** %12
%45 = load i32*, i32** %8
%46 = load i32, i32* %45
%47 = call i32 @ex_err(i8* %43, i8* %44, i32 %46)
%48 = load i8*, i8** %11
%49 = call i32 @free(i8* %48)
%50 = load i8*, i8** %12
%51 = call i32 @free(i8* %50)
br label %52
52: ; preds = %34, %30, %20
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"exerr\00"
@.str.1 = [56 x i8] c"Error: failed to allocate space for process name buffer\00"
@.str.2 = [53 x i8] c"Error: failed to allocate space for error msg buffer\00"
define void @EXERR(i8* %0, i8* %1, i32* nocapture %2, i32 %3, i32 %4) {
%6 = add nsw i32 %3, 1
%7 = tail call i8* @malloc(i32 %6)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = tail call i32 @ex_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i32 1000)
br label %25
11: ; preds = %5
%12 = add nsw i32 %4, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = tail call i32 @free(i8* %7)
%17 = tail call i32 @ex_err(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.2, i64 0, i64 0), i32 1000)
br label %25
18: ; preds = %11
%19 = tail call i32 @ex_fstrncpy(i8* %7, i8* %0, i32 %3)
%20 = tail call i32 @ex_fstrncpy(i8* %13, i8* %1, i32 %4)
%21 = load i32, i32* %2
%22 = tail call i32 @ex_err(i8* %7, i8* %13, i32 %21)
%23 = tail call i32 @free(i8* %7)
%24 = tail call i32 @free(i8* %13)
br label %25
25: ; preds = %18, %15, %9
ret void
}