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

/* Variables and functions */
scalar_t__ asprintf(char **, char *, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strerror_r(int, char *, int);
char *add_strerror(char *message, int last_errno) {
  if (last_errno == 0)
    return message;
  else {
    char StrError[64];
    char *result;
    do
      if (asprintf(&result, "%s: (%d) %s", message, last_errno,
                   strerror_r(last_errno, StrError, sizeof(StrError)))) {
      }
    while (0);
    free(message);
    return result;
  }
}


x86 assembly (clang, -O0):
<add_strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1159 <add_strerror+0x29>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11bc <add_strerror+0x8c>
jmp    115e <add_strerror+0x2e>
mov    -0x10(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x40,%edx
call   1040 <strerror_r@plt>
mov    -0x78(%rbp),%rdx
mov    -0x6c(%rbp),%ecx
mov    %eax,%r8d
lea    -0x68(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1050 <asprintf@plt>
cmp    $0x0,%rax
je     11a6 <add_strerror+0x76>
jmp    11a6 <add_strerror+0x76>
jmp    11ab <add_strerror+0x7b>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x68(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_strerror>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
test   %esi,%esi
je     1176 <add_strerror+0x46>
mov    %esi,%ebp
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x40,%edx
call   1040 <strerror_r@plt>
lea    0xea9(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    %ebp,%ecx
mov    %eax,%r8d
call   1050 <asprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x8(%rsp),%rbx
mov    %rbx,%rax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"%s: (%d) %s\00"
define i8* @add_strerror(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [64 x i8]
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i8*, i8** %4
store i8* %11, i8** %3
br label %27
12: ; preds = %2
br label %13
13: ; preds = %12
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = load i32, i32* %5
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %6, i64 0, i64 0
%18 = call i32 @strerror_r(i32 %16, i8* %17, i32 64)
%19 = call i64 @asprintf(i8** %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %14, i32 %15, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %13
br label %22
22: ; preds = %21, %13
br label %23
23: ; preds = %22
%24 = load i8*, i8** %4
%25 = call i32 @free(i8* %24)
%26 = load i8*, i8** %7
store i8* %26, i8** %3
br label %27
27: ; preds = %23, %10
%28 = load i8*, i8** %3
ret i8* %28
}

LLVM IR (-O2):
@.str = [12 x i8] c"%s: (%d) %s\00"
define i8* @add_strerror(i8* %0, i32 %1) {
%3 = alloca [64 x i8]
%4 = alloca i8*
%5 = icmp eq i32 %1, 0
br i1 %5, label %13, label %6
6: ; preds = %2
%7 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%8 = bitcast i8** %4 to i8*
%9 = call i32 @strerror_r(i32 %1, i8* %7, i32 64)
%10 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %9)
%11 = call i32 @free(i8* %0)
%12 = load i8*, i8** %4
br label %13
13: ; preds = %2, %6
%14 = phi i8* [ %12, %6 ], [ %0, %2 ]
ret i8* %14
}