#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 */
char *astrcpy(char const *);
scalar_t__ mu__malloc(char *, int, size_t);
size_t strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *astrncpy(const char *src, size_t n) {
  char *result = NULL;
  if (strlen(src) <= n) {
    return astrcpy(src);
  } else {
    result = (char *)mu__malloc(
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c",
        444, (n + 1) * sizeof(char));
    strncpy(result, src, n);
    return result;
  }
}


x86 assembly (clang, -O0):
<astrncpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    -0x18(%rbp),%rax
ja     117d <astrncpy+0x3d>
mov    -0x10(%rbp),%rdi
call   1050 <astrcpy@plt>
mov    %rax,-0x8(%rbp)
jmp    11b7 <astrncpy+0x77>
mov    -0x18(%rbp),%rdx
add    $0x1,%rdx
shl    $0x0,%rdx
lea    0xe70(%rip),%rdi
mov    $0x1bc,%esi
call   1060 <mu__malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<astrncpy>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %r14,%rax
jbe    1184 <astrncpy+0x44>
lea    0x1(%r14),%rdx
lea    0xea0(%rip),%rdi
mov    $0x1bc,%esi
call   1060 <mu__malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1030 <strncpy@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <astrcpy@plt>

LLVM IR (-O0):
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c\00"
define i8* @astrncpy(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* null, i8** %6
%7 = load i8*, i8** %4
%8 = call i64 @strlen(i8* %7)
%9 = load i64, i64* %5
%10 = icmp ule i64 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = call i8* @astrcpy(i8* %12)
store i8* %13, i8** %3
br label %25
14: ; preds = %2
%15 = load i64, i64* %5
%16 = add i64 %15, 1
%17 = mul i64 %16, 1
%18 = call i64 @mu__malloc(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 444, i64 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = load i8*, i8** %4
%22 = load i64, i64* %5
%23 = call i32 @strncpy(i8* %20, i8* %21, i64 %22)
%24 = load i8*, i8** %6
store i8* %24, i8** %3
br label %25
25: ; preds = %14, %11
%26 = load i8*, i8** %3
ret i8* %26
}

LLVM IR (-O2):
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/kaiaie/bile/refs/heads/master/src/astring.c\00"
define i8* @astrncpy(i8* %0, i64 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp ugt i64 %3, %1
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i8* @astrcpy(i8* %0)
br label %12
7: ; preds = %2
%8 = add nuw i64 %1, 1
%9 = tail call i64 @mu__malloc(i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 444, i64 %8)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strncpy(i8* %10, i8* %0, i64 %1)
br label %12
12: ; preds = %7, %5
%13 = phi i8* [ %6, %5 ], [ %10, %7 ]
ret i8* %13
}