#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 */
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
size_t get_rec_dir(char *, size_t, int /*<<< orphan*/, int *);
char *malloc(size_t);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, size_t);
char *get_dir(char *str, uint64_t num, int *fin) {
  size_t len = strlen(str);
  char *dir = malloc(len);
  size_t rc = get_rec_dir(str, len, num, fin);
  strncpy(dir, str, rc);
  dir[rc] = '\0';
  return dir;
}


x86 assembly (clang, -O0):
<get_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
call   1060 <get_rec_dir@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %r15d,%edx
mov    %r14,%rcx
call   1060 <get_rec_dir@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
call   1030 <strncpy@plt>
movb   $0x0,(%rbx,%rbp,1)
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @get_dir(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
store i64 %11, i64* %7
%12 = load i64, i64* %7
%13 = call i8* @malloc(i64 %12)
store i8* %13, i8** %8
%14 = load i8*, i8** %4
%15 = load i64, i64* %7
%16 = load i32, i32* %5
%17 = load i32*, i32** %6
%18 = call i64 @get_rec_dir(i8* %14, i64 %15, i32 %16, i32* %17)
store i64 %18, i64* %9
%19 = load i8*, i8** %8
%20 = load i8*, i8** %4
%21 = load i64, i64* %9
%22 = call i32 @strncpy(i8* %19, i8* %20, i64 %21)
%23 = load i8*, i8** %8
%24 = load i64, i64* %9
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %8
ret i8* %26
}

LLVM IR (-O2):
define i8* @get_dir(i8* %0, i32 %1, i32* %2) {
%4 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i64 @get_rec_dir(i8* %0, i64 %4, i32 %1, i32* %2)
%7 = tail call i32 @strncpy(i8* %5, i8* %0, i64 %6)
%8 = getelementptr inbounds i8, i8* %5, i64 %6
store i8 0, i8* %8
ret i8* %5
}