#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);
    *errcode = 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);
    *errcode = 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    11a3 <exerr+0x63>
lea    0xe7d(%rip),%rdi
lea    0xe7c(%rip),%rsi
mov    $0x3e8,%edx
call   1060 <ex_err@plt>
mov    -0x18(%rbp),%rax
movl   $0x3e8,(%rax)
jmp    1239 <exerr+0xf9>
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    11f4 <exerr+0xb4>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xe2c(%rip),%rdi
lea    0xe63(%rip),%rsi
mov    $0x3e8,%edx
call   1060 <ex_err@plt>
mov    -0x18(%rbp),%rax
movl   $0x3e8,(%rax)
jmp    1239 <exerr+0xf9>
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     11ec <exerr+0xac>
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
mov    $0x3e8,%edx
call   1060 <ex_err@plt>
movl   $0x3e8,0x0(%rbp)
jmp    1216 <exerr+0xd6>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe05(%rip),%rdi
lea    0xe3c(%rip),%rsi
mov    $0x3e8,%edx
call   1060 <ex_err@plt>
mov    (%rsp),%rax
movl   $0x3e8,(%rax)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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 %23, 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)
%22 = load i32*, i32** %8
store i32 1000, i32* %22
br label %54
23: ; preds = %5
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %12
%30 = icmp ne i8* %29, null
br i1 %30, label %36, label %31
31: ; preds = %23
%32 = load i8*, i8** %11
%33 = call i32 @free(i8* %32)
%34 = 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)
%35 = load i32*, i32** %8
store i32 1000, i32* %35
br label %54
36: ; preds = %23
%37 = load i8*, i8** %11
%38 = load i8*, i8** %6
%39 = load i32, i32* %9
%40 = call i32 @ex_fstrncpy(i8* %37, i8* %38, i32 %39)
%41 = load i8*, i8** %12
%42 = load i8*, i8** %7
%43 = load i32, i32* %10
%44 = call i32 @ex_fstrncpy(i8* %41, i8* %42, i32 %43)
%45 = load i8*, i8** %11
%46 = load i8*, i8** %12
%47 = load i32*, i32** %8
%48 = load i32, i32* %47
%49 = call i32 @ex_err(i8* %45, i8* %46, i32 %48)
%50 = load i8*, i8** %11
%51 = call i32 @free(i8* %50)
%52 = load i8*, i8** %12
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %36, %31, %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)
store i32 1000, i32* %2
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)
store i32 1000, i32* %2
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
}