#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*/ exit(int /*<<< orphan*/);
char *malloc(scalar_t__);
int /*<<< orphan*/ perror(char *);
char *strcpy(char *, char const *);
scalar_t__ strlen(char const *);
char *xstrdup(const char *str) {
  char *new_str;
  if (!str)
    return NULL;
  if (!(new_str = malloc(strlen(str) + 1 + 1))) {
    perror(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/kaffeemonster/g2cd/refs/heads/master/bin2o.c"
        ", "
        "689"
        ", strdup malloc()");
    exit(EXIT_FAILURE);
  }
  return strcpy(new_str, str);
}


x86 assembly (clang, -O0):
<xstrdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1174 <xstrdup+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11c6 <xstrdup+0x76>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11b5 <xstrdup+0x65>
lea    0xe5e(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e32(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrdup>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117f <xstrdup+0x2f>
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x2(%rax),%rdi
call   1050 <malloc@plt>
test   %rax,%rax
je     118c <xstrdup+0x3c>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
jmp    1181 <xstrdup+0x31>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6d(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaffeemonster/g2cd/refs/heads/master/bin2o.c, 689, strdup malloc()\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 ne i8* %5, null
br i1 %6, label %8, label %7
7: ; preds = %1
store i8* null, i8** %2
br label %23
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = add nsw i64 %11, 1
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %4
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %8
%16 = call i32 @perror(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %8
%20 = load i8*, i8** %4
%21 = load i8*, i8** %3
%22 = call i8* @strcpy(i8* %20, i8* %21)
store i8* %22, i8** %2
br label %23
23: ; preds = %19, %7
%24 = load i8*, i8** %2
ret i8* %24
}

LLVM IR (-O2):
@.str = [157 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaffeemonster/g2cd/refs/heads/master/bin2o.c, 689, strdup malloc()\00"
@EXIT_FAILURE = global i32 0
define i8* @xstrdup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %14, label %3
3: ; preds = %1
%4 = tail call i64 @strlen(i8* %0)
%5 = add nsw i64 %4, 2
%6 = tail call i8* @malloc(i64 %5)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %12
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %3
%13 = tail call i8* @strcpy(i8* %6, i8* %0)
br label %14
14: ; preds = %1, %12
%15 = phi i8* [ %6, %12 ], [ null, %1 ]
ret i8* %15
}