#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*/ LOG_CRIT;
int /*<<< orphan*/ _debug(char *, int, int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
char *strdup(char const *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
char *safe_strdup(const char s[]) {
  char *retval = NULL;
  if (!s) {
    _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/lynxis/nodogsplash/refs/heads/master/src/"
           "safe.c",
           54, LOG_CRIT,
           "safe_strdup called with NULL which would have crashed strdup. "
           "Bailing out.");
    exit(1);
  }
  retval = strdup(s);
  if (!retval) {
    _debug("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/lynxis/nodogsplash/refs/heads/master/src/"
           "safe.c",
           59, LOG_CRIT, "Failed to duplicate a string: %s. Bailing out.",
           strerror(errno));
    exit(1);
  }
  return (retval);
}


x86 assembly (clang, -O0):
<safe_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    118c <safe_strdup+0x4c>
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
lea    0xe91(%rip),%rdi
mov    $0x36,%esi
lea    0xf0f(%rip),%rcx
mov    $0x0,%al
call   1030 <_debug@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e8 <safe_strdup+0xa8>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edx
mov    %eax,%r8d
lea    0xe35(%rip),%rdi
mov    $0x3b,%esi
lea    0xefe(%rip),%rcx
mov    $0x0,%al
call   1030 <_debug@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_strdup>:
push   %rbx
test   %rdi,%rdi
je     1152 <safe_strdup+0x12>
call   1050 <strdup@plt>
test   %rax,%rax
je     117f <safe_strdup+0x3f>
pop    %rbx
ret
mov    0x2e8f(%rip),%rax
mov    (%rax),%edx
lea    0xe9e(%rip),%rdi
lea    0xf21(%rip),%rcx
mov    $0x36,%esi
xor    %eax,%eax
call   1030 <_debug@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%ebx
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe63(%rip),%rdi
lea    0xf31(%rip),%rcx
mov    $0x3b,%esi
mov    %ebx,%edx
mov    %eax,%r8d
xor    %eax,%eax
call   1030 <_debug@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lynxis/nodogsplash/refs/heads/master/src/safe.c\00"
@LOG_CRIT = global i32 0
@.str.1 = [75 x i8] c"safe_strdup called with NULL which would have crashed strdup. Bailing out.\00"
@.str.2 = [47 x i8] c"Failed to duplicate a string: %s. Bailing out.\00"
@errno = global i32 0
define i8* @safe_strdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %3
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = load i32, i32* @LOG_CRIT
%8 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 54, i32 %7, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i8* @strdup(i8* %11)
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %10
%16 = load i32, i32* @LOG_CRIT
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 59, i32 %16, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %10
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@.str = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/lynxis/nodogsplash/refs/heads/master/src/safe.c\00"
@LOG_CRIT = global i32 0
@.str.1 = [75 x i8] c"safe_strdup called with NULL which would have crashed strdup. Bailing out.\00"
@.str.2 = [47 x i8] c"Failed to duplicate a string: %s. Bailing out.\00"
@errno = global i32 0
define noalias i8* @safe_strdup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %7
3: ; preds = %1
%4 = load i32, i32* @LOG_CRIT
%5 = tail call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 54, i32 %4, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i8* @strdup(i8* %0)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i32, i32* @LOG_CRIT
%12 = load i32, i32* @errno
%13 = tail call i32 @strerror(i32 %12)
%14 = tail call i32 (i8*, i32, i32, i8*, ...) @_debug(i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str, i64 0, i64 0), i32 59, i32 %11, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %7
ret i8* %8
}