char *UtilSafeStrdupInternal(int bugNumber, const char *s, char *file,
                             int lineno) {
  char *result;
  if (s == ((void *)0)) {
    return ((void *)0);
  }
  if ((result = strdup(s)) == ((void *)0)) {
    if (bugNumber == -1) {
      Panic("Unrecoverable memory allocation failure at %s:%d\n", file, lineno);
    } else {
      Panic("Unrecoverable memory allocation failure at %s:%d.  Bug "
            "number: %d\n",
            file, lineno, bugNumber);
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<UtilSafeStrdupInternal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114e <UtilSafeStrdupInternal+0x2e>
movq   $0x0,-0x8(%rbp)
jmp    11ae <UtilSafeStrdupInternal+0x8e>
mov    -0x18(%rbp),%rdi
call   1040 <strdup@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11a6 <UtilSafeStrdupInternal+0x86>
cmpl   $0xffffffff,-0xc(%rbp)
jne    1189 <UtilSafeStrdupInternal+0x69>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <Panic@plt>
jmp    11a1 <UtilSafeStrdupInternal+0x81>
mov    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe98(%rip),%rdi
mov    $0x0,%al
call   1030 <Panic@plt>
jmp    11a6 <UtilSafeStrdupInternal+0x86>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<UtilSafeStrdupInternal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1163 <UtilSafeStrdupInternal+0x43>
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %edi,%ebp
mov    %rsi,%rdi
call   1040 <strdup@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    117d <UtilSafeStrdupInternal+0x5d>
cmp    $0xffffffff,%ebp
je     1167 <UtilSafeStrdupInternal+0x47>
lea    0xee2(%rip),%rdi
xor    %ebx,%ebx
mov    %r15,%rsi
mov    %r14d,%edx
mov    %ebp,%ecx
xor    %eax,%eax
call   1030 <Panic@plt>
jmp    117d <UtilSafeStrdupInternal+0x5d>
xor    %ebx,%ebx
jmp    117d <UtilSafeStrdupInternal+0x5d>
lea    0xe92(%rip),%rdi
xor    %ebx,%ebx
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1030 <Panic@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Unrecoverable memory allocation failure at %s:%d\0A\00"
@.str.1 = [67 x i8] c"Unrecoverable memory allocation failure at %s:%d. Bug number: %d\0A\00"
define i8* @UtilSafeStrdupInternal(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i8*
store i32 %0, i32* %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%11 = load i8*, i8** %7
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %14
13: ; preds = %4
store i8* null, i8** %5
br label %33
14: ; preds = %4
%15 = load i8*, i8** %7
%16 = call i8* @strdup(i8* %15)
store i8* %16, i8** %10
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %31
18: ; preds = %14
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = load i32, i32* %9
%24 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @Panic to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23)
br label %30
25: ; preds = %18
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = load i32, i32* %6
%29 = call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @Panic to i32 (i8*, i8*, i32, i32, ...)*)(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %26, i32 %27, i32 %28)
br label %30
30: ; preds = %25, %21
br label %31
31: ; preds = %30, %14
%32 = load i8*, i8** %10
store i8* %32, i8** %5
br label %33
33: ; preds = %31, %13
%34 = load i8*, i8** %5
ret i8* %34
}

LLVM IR (-O2):
@.str = [50 x i8] c"Unrecoverable memory allocation failure at %s:%d\0A\00"
@.str.1 = [67 x i8] c"Unrecoverable memory allocation failure at %s:%d. Bug number: %d\0A\00"
define i8* @UtilSafeStrdupInternal(i32 %0, i8* %1, i8* %2, i32 %3) {
%5 = icmp eq i8* %1, null
br i1 %5, label %15, label %6
6: ; preds = %4
%7 = tail call i8* @strdup(i8* %1)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %15
9: ; preds = %6
%10 = icmp eq i32 %0, -1
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @Panic to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %3)
br label %15
13: ; preds = %9
%14 = tail call i32 (i8*, i8*, i32, i32, ...) bitcast (i32 (...)* @Panic to i32 (i8*, i8*, i32, i32, ...)*)(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %3, i32 %0)
br label %15
15: ; preds = %6, %13, %11, %4
%16 = phi i8* [ null, %4 ], [ null, %11 ], [ null, %13 ], [ %7, %6 ]
ret i8* %16
}