#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*/ EXIT_FAILURE;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *strdup(char const *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
char *xstrdup(const char *str) {
  char *value;
  if (str == NULL)
    return NULL;
  if ((value = strdup(str)) != NULL)
    return value;
  syslog(LOG_ERR, "memory exhausted (xstrdup)");
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<xstrdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1154 <xstrdup+0x24>
movq   $0x0,-0x8(%rbp)
jmp    119b <xstrdup+0x6b>
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1178 <xstrdup+0x48>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119b <xstrdup+0x6b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe78(%rip),%rsi
call   1030 <syslog@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrdup>:
push   %rax
test   %rdi,%rdi
je     1142 <xstrdup+0x12>
call   1050 <strdup@plt>
test   %rax,%rax
je     1146 <xstrdup+0x16>
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xeaa(%rip),%rsi
call   1030 <syslog@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@LOG_ERR = global i32 0
@.str = [27 x i8] c"memory exhausted (xstrdup)\00"
@EXIT_FAILURE = global i32 0
define i8* @xstrdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %8
7: ; preds = %1
store i8* null, i8** %2
br label %19
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i8* @strdup(i8* %9)
store i8* %10, i8** %4
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i8*, i8** %4
store i8* %13, i8** %2
br label %19
14: ; preds = %8
%15 = load i32, i32* @LOG_ERR
%16 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12, %7
%20 = load i8*, i8** %2
ret i8* %20
}

LLVM IR (-O2):
@LOG_ERR = global i32 0
@.str = [27 x i8] c"memory exhausted (xstrdup)\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @xstrdup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %11, label %3
3: ; preds = %1
%4 = tail call i8* @strdup(i8* %0)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @LOG_ERR
%8 = tail call i32 @syslog(i32 %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %3, %1
%12 = phi i8* [ null, %1 ], [ %4, %3 ]
ret i8* %12
}