#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 */
scalar_t__ alloca(scalar_t__);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strlen(char const *);
void perror_with_name(char *string) {
  const char *err;
  char *combined;
  err = strerror(errno);
  if (err == NULL)
    err = "unknown error";
  combined = (char *)alloca(strlen(err) + strlen(string) + 3);
  strcpy(combined, string);
  strcat(combined, ": ");
  strcat(combined, err);
  fprintf(stderr, "\n%s.\n", combined);
  fflush(stderr);
  exit(1);
}


x86 assembly (clang, -O0):
<perror_with_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b4 <perror_with_name+0x34>
lea    0xe50(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
add    %rax,%rdi
add    $0x3,%rdi
call   1060 <alloca@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1080 <strcat@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<perror_with_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
test   %rax,%rax
lea    0xe5d(%rip),%r12
cmovne %rax,%r12
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    (%r15,%rax,1),%rdi
add    $0x3,%rdi
call   1060 <alloca@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    0x2dea(%rip),%r14
mov    (%r14),%edi
lea    0xe11(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    (%r14),%edi
call   1070 <fflush@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [14 x i8] c"unknown error\00"
@.str.1 = [3 x i8] c": \00"
@stderr = global i32 0
@.str.2 = [6 x i8] c"\0A%s.\0A\00"
define void @perror_with_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i32, i32* @errno
%6 = call i8* @strerror(i32 %5)
store i8* %6, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %9, %1
%11 = load i8*, i8** %3
%12 = call i64 @strlen(i8* %11)
%13 = load i8*, i8** %2
%14 = call i64 @strlen(i8* %13)
%15 = add nsw i64 %12, %14
%16 = add nsw i64 %15, 3
%17 = call i64 @alloca(i64 %16)
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %4
%19 = load i8*, i8** %4
%20 = load i8*, i8** %2
%21 = call i32 @strcpy(i8* %19, i8* %20)
%22 = load i8*, i8** %4
%23 = call i32 @strcat(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %4
%25 = load i8*, i8** %3
%26 = call i32 @strcat(i8* %24, i8* %25)
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %4
%29 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* @stderr
%31 = call i32 @fflush(i32 %30)
%32 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [14 x i8] c"unknown error\00"
@.str.1 = [3 x i8] c": \00"
@stderr = global i32 0
@.str.2 = [6 x i8] c"\0A%s.\0A\00"
define void @perror_with_name(i8* %0) {
%2 = load i32, i32* @errno
%3 = tail call i8* @strerror(i32 %2)
%4 = icmp eq i8* %3, null
%5 = select i1 %4, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %3
%6 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%7 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%8 = add i64 %6, 3
%9 = add i64 %8, %7
%10 = tail call i64 @alloca(i64 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @strcpy(i8* %11, i8* %0)
%13 = tail call i32 @strcat(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%14 = tail call i32 @strcat(i8* %11, i8* %5)
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%17 = load i32, i32* @stderr
%18 = tail call i32 @fflush(i32 %17)
%19 = tail call i32 @exit(i32 1)
unreachable
}