char *fz_strdup(char *s) {
  char *ns = malloc(strlen(s) + 1);
  if (!ns)
    fz_throwimp("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/OpenInkpot-archive/"
                "iplinux-mupdf-fontdump/refs/heads/master/fitz/base_memory.c",
                28, __func__, "cannot strdup %lu bytes",
                (unsigned long)strlen(s) + 1);
  memcpy(ns, s, strlen(s) + 1);
  return ns;
}


x86 assembly (clang, -O0):
<fz_strdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a1 <fz_strdup+0x61>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%r8
add    $0x1,%r8
lea    0xe79(%rip),%rdi
mov    $0x1c,%esi
lea    0xf16(%rip),%rdx
lea    0xf19(%rip),%rcx
mov    $0x0,%al
call   1060 <fz_throwimp@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fz_strdup>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
mov    %rax,%rbx
add    $0x1,%rbx
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1188 <fz_strdup+0x48>
lea    0xe95(%rip),%rdi
lea    0xf37(%rip),%rdx
lea    0xf3a(%rip),%rcx
mov    $0x1c,%esi
mov    %rbx,%r8
xor    %eax,%eax
call   1060 <fz_throwimp@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <memcpy@plt>

LLVM IR (-O0):
@.str = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OpenInkpot-archive/iplinux-mupdf-fontdump/refs/heads/master/fitz/base_memory.c\00"
@__func__.fz_strdup = [10 x i8] c"fz_strdup\00"
@.str.1 = [24 x i8] c"cannot strdup %lu bytes\00"
define i8* @fz_strdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i64 @strlen(i8* %4)
%6 = add i64 %5, 1
%7 = call i8* @malloc(i64 %6)
store i8* %7, i8** %3
%8 = load i8*, i8** %3
%9 = icmp ne i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = call i64 @strlen(i8* %11)
%13 = add i64 %12, 1
%14 = call i32 (i8*, i32, i8*, i8*, i64, ...) bitcast (i32 (...)* @fz_throwimp to i32 (i8*, i32, i8*, i8*, i64, ...)*)(i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str, i64 0, i64 0), i32 28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.fz_strdup, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %13)
br label %15
15: ; preds = %10, %1
%16 = load i8*, i8** %3
%17 = load i8*, i8** %2
%18 = load i8*, i8** %2
%19 = call i64 @strlen(i8* %18)
%20 = add i64 %19, 1
%21 = load i8*, i8** %3
ret i8* %21
}

LLVM IR (-O2):
@.str = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/OpenInkpot-archive/iplinux-mupdf-fontdump/refs/heads/master/fitz/base_memory.c\00"
@__func__.fz_strdup = [10 x i8] c"fz_strdup\00"
@.str.1 = [24 x i8] c"cannot strdup %lu bytes\00"
define i8* @fz_strdup(i8* nocapture %0) {
%2 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%3 = add i64 %2, 1
%4 = tail call i8* @malloc(i64 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (i8*, i32, i8*, i8*, i64, ...) bitcast (i32 (...)* @fz_throwimp to i32 (i8*, i32, i8*, i8*, i64, ...)*)(i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str, i64 0, i64 0), i32 28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.fz_strdup, i64 0, i64 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %3)
br label %8
8: ; preds = %6, %1
%9 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%10 = add i64 %9, 1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 %4, i8* align 1 %0, i64 %10, i1 false)
ret i8* %4
}