#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 errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *,
                           int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
char *strerror(int);
scalar_t__ strlen(char const *);
char *wrapper_malloc(scalar_t__, char const *, int const);
char *wrapper_strdup(const char *str, const char *file, const int line) {
  char *new_str = wrapper_malloc(strlen(str) + 1, file, line);
  if (!new_str) {
    fprintf(stderr,
            "Error: couldn't allocate memory for string: "
            "%s, line %d\n    %s (%d)\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/paulgriffiths/pgutils/refs/heads/master/"
            "wrappers/std_wrappers.c",
            51, strerror(errno), errno);
    exit(EXIT_FAILURE);
  }
  strcpy(new_str, str);
  return new_str;
}


x86 assembly (clang, -O0):
<wrapper_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1050 <wrapper_malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ee <wrapper_strdup+0x8e>
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%r8
mov    0x2e13(%rip),%rax
mov    (%rax),%r9d
lea    0xe31(%rip),%rsi
lea    0xe6f(%rip),%rdx
mov    $0x33,%ecx
call   1060 <fprintf@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wrapper_strdup>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1050 <wrapper_malloc@plt>
test   %rax,%rax
je     119a <wrapper_strdup+0x3a>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e3f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2e(%rip),%rbp
mov    0x0(%rbp),%edi
call   1080 <strerror@plt>
mov    0x0(%rbp),%r9d
lea    0xe43(%rip),%rsi
lea    0xe81(%rip),%rdx
mov    %ebx,%edi
mov    $0x33,%ecx
mov    %rax,%r8
call   1060 <fprintf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [69 x i8] c"Error: couldn't allocate memory for string: %s, line %d\0A %s (%d)\0A\00"
@.str.1 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/paulgriffiths/pgutils/refs/heads/master/wrappers/std_wrappers.c\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @wrapper_strdup(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call i8* @wrapper_malloc(i64 %10, i8* %11, i32 %12)
store i8* %13, i8** %7
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %24, label %16
16: ; preds = %3
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = load i32, i32* @errno
%21 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.1, i64 0, i64 0), i32 51, i8* %19, i32 %20)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %3
%25 = load i8*, i8** %7
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %25, i8* %26)
%28 = load i8*, i8** %7
ret i8* %28
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [69 x i8] c"Error: couldn't allocate memory for string: %s, line %d\0A %s (%d)\0A\00"
@.str.1 = [154 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/paulgriffiths/pgutils/refs/heads/master/wrappers/std_wrappers.c\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i8* @wrapper_strdup(i8* %0, i8* %1, i32 %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = add nsw i64 %4, 1
%6 = tail call i8* @wrapper_malloc(i64 %5, i8* %1, i32 %2)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = load i32, i32* @errno
%13 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([154 x i8], [154 x i8]* @.str.1, i64 0, i64 0), i32 51, i8* %11, i32 %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %3
%17 = tail call i32 @strcpy(i8* %6, i8* %0)
ret i8* %6
}