#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 */
void __xassert_failed(char *, char *, int, char *);
scalar_t__ slurm_xmalloc(size_t, char *, int, char *);
size_t strlcpy(char *, char const *, size_t);
int strlen(char const *);
char *xstrdup(const char *str) {
  size_t siz, rsiz;
  char *result;
  if (str == NULL) {
    return NULL;
  }
  siz = strlen(str) + 1;
  result = (char *)slurm_xmalloc(
      siz,
      "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
      "2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/heads/"
      "master/src/common/xstring.c",
      359, "");
  rsiz = strlcpy(result, str, siz);
  (void)({
    (rsiz == siz - 1)
        ? ((void)0)
        : __xassert_failed(
              "rsiz == siz-1",
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/"
              "heads/master/src/common/xstring.c",
              363, "");
  });
  return result;
}


x86 assembly (clang, -O0):
<xstrdup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1164 <xstrdup+0x24>
movq   $0x0,-0x8(%rbp)
jmp    11ec <xstrdup+0xac>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7f(%rip),%rsi
mov    $0x167,%edx
lea    0xf1e(%rip),%rcx
call   1040 <slurm_xmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1050 <strlcpy@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
cmp    %rcx,%rax
jne    11c5 <xstrdup+0x85>
jmp    11e4 <xstrdup+0xa4>
lea    0xed2(%rip),%rdi
lea    0xe2d(%rip),%rsi
mov    $0x16b,%edx
lea    0xecc(%rip),%rcx
call   1060 <__xassert_failed@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xstrdup>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11af <xstrdup+0x6f>
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %eax,%r12
lea    0x1(%r12),%r15
lea    0xe9c(%rip),%rsi
lea    0xf40(%rip),%rcx
mov    %r15,%rdi
mov    $0x167,%edx
call   1040 <slurm_xmalloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1050 <strlcpy@plt>
cmp    %r12,%rax
je     11b2 <xstrdup+0x72>
lea    0xf09(%rip),%rdi
lea    0xe64(%rip),%rsi
lea    0xf08(%rip),%rcx
mov    $0x16b,%edx
call   1060 <__xassert_failed@plt>
jmp    11b2 <xstrdup+0x72>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/heads/master/src/common/xstring.c\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [14 x i8] c"rsiz == siz-1\00"
define i8* @xstrdup(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %30
10: ; preds = %1
%11 = load i8*, i8** %3
%12 = call i32 @strlen(i8* %11)
%13 = add nsw i32 %12, 1
%14 = sext i32 %13 to i64
store i64 %14, i64* %4
%15 = load i64, i64* %4
%16 = call i64 @slurm_xmalloc(i64 %15, i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str, i64 0, i64 0), i32 359, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%17 = inttoptr i64 %16 to i8*
store i8* %17, i8** %6
%18 = load i8*, i8** %6
%19 = load i8*, i8** %3
%20 = load i64, i64* %4
%21 = call i64 @strlcpy(i8* %18, i8* %19, i64 %20)
store i64 %21, i64* %5
%22 = load i64, i64* %5
%23 = load i64, i64* %4
%24 = sub i64 %23, 1
%25 = icmp eq i64 %22, %24
br i1 %25, label %26, label %27
26: ; preds = %10
br label %28
27: ; preds = %10
br label %28
28: ; preds = %27, %26
%29 = load i8*, i8** %6
store i8* %29, i8** %2
br label %30
30: ; preds = %28, %9
%31 = load i8*, i8** %2
ret i8* %31
}

LLVM IR (-O2):
@.str = [158 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Q-Leap-Networks/debian-slurm/refs/heads/master/src/common/xstring.c\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [14 x i8] c"rsiz == siz-1\00"
define i8* @xstrdup(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %13, label %3
3: ; preds = %1
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 1
%6 = sext i32 %5 to i64
%7 = tail call i64 @slurm_xmalloc(i64 %6, i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str, i64 0, i64 0), i32 359, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%8 = inttoptr i64 %7 to i8*
%9 = tail call i64 @strlcpy(i8* %8, i8* %0, i64 %6)
%10 = add nsw i64 %6, -1
%11 = icmp eq i64 %9, %10
br i1 %11, label %13, label %12
12: ; preds = %3
tail call void @__xassert_failed(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([158 x i8], [158 x i8]* @.str, i64 0, i64 0), i32 363, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %12, %3, %1
%14 = phi i8* [ null, %1 ], [ %8, %3 ], [ %8, %12 ]
ret i8* %14
}