#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*/ fatal(char *, unsigned long);
char *strdup(char const *);
scalar_t__ strlen(char const *);
char *xstrdup(const char *s) {
  char *o = s ? strdup(s) : strdup("");
  if (!o) {
    fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n",
          (unsigned long)strlen(s));
  }
  return o;
}


x86 assembly (clang, -O0):
<xstrdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1159 <xstrdup+0x29>
mov    -0x8(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
jmp    1169 <xstrdup+0x39>
lea    0xed2(%rip),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1194 <xstrdup+0x64>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rsi
lea    0xe71(%rip),%rdi
call   1050 <fatal@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrdup>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
test   %rdi,%rdi
je     1141 <xstrdup+0x11>
mov    %r14,%rdi
jmp    1148 <xstrdup+0x18>
lea    0xeea(%rip),%rdi
call   1040 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    116c <xstrdup+0x3c>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe9c(%rip),%rdi
mov    %rax,%rsi
call   1050 <fatal@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [51 x i8] c"gpsbabel: Unable to allocate %ld bytes of memory.\0A\00"
define i8* @xstrdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = call i8* @strdup(i8* %7)
br label %11
9: ; preds = %1
%10 = call i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %6
%12 = phi i8* [ %8, %6 ], [ %10, %9 ]
store i8* %12, i8** %3
%13 = load i8*, i8** %3
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = call i64 @strlen(i8* %16)
%18 = call i32 @fatal(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i64 %17)
br label %19
19: ; preds = %15, %11
%20 = load i8*, i8** %3
ret i8* %20
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [51 x i8] c"gpsbabel: Unable to allocate %ld bytes of memory.\0A\00"
define i8* @xstrdup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i8* @strdup(i8* %0)
br label %7
5: ; preds = %1
%6 = tail call dereferenceable_or_null(1) i8* @strdup(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = phi i8* [ %4, %3 ], [ %6, %5 ]
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7
%11 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%12 = tail call i32 @fatal(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.1, i64 0, i64 0), i64 %11)
br label %13
13: ; preds = %10, %7
ret i8* %8
}