#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*/ printf(char *);
int strlen_my(char *);
void strncpy_my(char *dst, char *src, int num) {
  int i = 0;
  int len_s = 0;
  int len_d = 0;
  char exit = 0;
  if (num > 100 - 1) {
    printf("Warning: number of returning symbols is more, than destination "
           "string.\n");
  };
  len_s = strlen_my(src);
  if (num > len_s) {
    printf("Warning: number of returning symbols is more than same string.\n");
  };
  i = 0;
  exit = 0;
  for (i = 0; i < num && exit == 0; i++) {
    if (i == (100 - 2)) {
      exit = 1;
      *dst++ = *src++;
      i++;
      *dst = '\0';
    } else {
      if (i == len_s - 1) {
        exit = 1;
        *dst++ = *src++;
        i++;
        *dst = '\0';
      } else {
        *dst++ = *src++;
      };
    };
  };
}


x86 assembly (clang, -O0):
<strncpy_my>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movb   $0x0,-0x21(%rbp)
cmpl   $0x63,-0x14(%rbp)
jle    1162 <strncpy_my+0x42>
lea    0xea3(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen_my@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    1186 <strncpy_my+0x66>
lea    0xec7(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
movb   $0x0,-0x21(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
xor    %eax,%eax
cmp    -0x14(%rbp),%ecx
mov    %al,-0x22(%rbp)
jge    11b6 <strncpy_my+0x96>
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0x22(%rbp)
mov    -0x22(%rbp),%al
test   $0x1,%al
jne    11c6 <strncpy_my+0xa6>
jmp    1291 <strncpy_my+0x171>
cmpl   $0x62,-0x18(%rbp)
jne    120b <strncpy_my+0xeb>
movb   $0x1,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    127e <strncpy_my+0x15e>
mov    -0x18(%rbp),%eax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1257 <strncpy_my+0x137>
movb   $0x1,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    1279 <strncpy_my+0x159>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    127e <strncpy_my+0x15e>
jmp    1283 <strncpy_my+0x163>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <strncpy_my+0x78>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strncpy_my>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %edx,%r14d
mov    %rsi,%r13
mov    %rdi,%r15
cmp    $0x64,%edx
jl     1143 <strncpy_my+0x23>
lea    0xf01(%rip),%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
call   1040 <strlen_my@plt>
mov    %eax,%r12d
cmp    %r14d,%eax
jge    115f <strncpy_my+0x3f>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
test   %r14d,%r14d
jle    123a <strncpy_my+0x11a>
lea    -0x1(%r12),%edi
lea    -0x1(%r14),%esi
cmp    %esi,%edi
mov    %esi,%ecx
cmovb  %edi,%ecx
cmp    $0x62,%ecx
mov    $0x62,%edx
cmovae %edx,%ecx
xor    %eax,%eax
cmp    $0x10,%ecx
jb     11fa <strncpy_my+0xda>
cmp    %esi,%edi
cmovb  %edi,%esi
cmp    $0x62,%esi
cmovb  %esi,%edx
lea    (%rdx,%r13,1),%rsi
add    $0x1,%rsi
cmp    %r15,%rsi
jbe    11ae <strncpy_my+0x8e>
add    %r15,%rdx
add    $0x1,%rdx
cmp    %r13,%rdx
ja     11fa <strncpy_my+0xda>
add    $0x1,%ecx
mov    %ecx,%eax
and    $0xf,%eax
test   %rax,%rax
mov    $0x10,%edx
cmovne %rax,%rdx
mov    %rcx,%rax
sub    %rdx,%rax
lea    (%r15,%rax,1),%rcx
lea    (%rax,%r13,1),%rdx
xor    %esi,%esi
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movups 0x0(%r13,%rsi,1),%xmm0
movups %xmm0,(%r15,%rsi,1)
add    $0x10,%rsi
cmp    %rsi,%rax
jne    11e0 <strncpy_my+0xc0>
mov    %rcx,%r15
mov    %rdx,%r13
mov    %eax,%ecx
not    %eax
add    %r12d,%eax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    (%rcx,%rdx,1),%esi
movzbl 0x0(%r13,%rdx,1),%ebx
mov    %bl,(%r15,%rdx,1)
cmp    $0x62,%esi
je     1234 <strncpy_my+0x114>
cmp    %edx,%eax
je     1234 <strncpy_my+0x114>
add    $0x1,%rdx
lea    (%rdx,%rcx,1),%esi
cmp    %r14d,%esi
jl     1210 <strncpy_my+0xf0>
jmp    123a <strncpy_my+0x11a>
movb   $0x0,0x1(%r15,%rdx,1)
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [72 x i8] c"Warning: number of returning symbols is more, than destination string.\0A\00"
@.str.1 = [64 x i8] c"Warning: number of returning symbols is more than same string.\0A\00"
define void @strncpy_my(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i8 0, i8* %10
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 99
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %3
%16 = load i8*, i8** %5
%17 = call i32 @strlen_my(i8* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %6
%19 = load i32, i32* %8
%20 = icmp sgt i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %15
store i32 0, i32* %7
store i8 0, i8* %10
store i32 0, i32* %7
br label %24
24: ; preds = %68, %23
%25 = load i32, i32* %7
%26 = load i32, i32* %6
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = load i8, i8* %10
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
br label %32
32: ; preds = %28, %24
%33 = phi i1 [ false, %24 ], [ %31, %28 ]
br i1 %33, label %34, label %71
34: ; preds = %32
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 98
br i1 %36, label %37, label %46
37: ; preds = %34
store i8 1, i8* %10
%38 = load i8*, i8** %5
%39 = getelementptr inbounds i8, i8* %38, i32 1
store i8* %39, i8** %5
%40 = load i8, i8* %38
%41 = load i8*, i8** %4
%42 = getelementptr inbounds i8, i8* %41, i32 1
store i8* %42, i8** %4
store i8 %40, i8* %41
%43 = load i32, i32* %7
%44 = add nsw i32 %43, 1
store i32 %44, i32* %7
%45 = load i8*, i8** %4
store i8 0, i8* %45
br label %67
46: ; preds = %34
%47 = load i32, i32* %7
%48 = load i32, i32* %8
%49 = sub nsw i32 %48, 1
%50 = icmp eq i32 %47, %49
br i1 %50, label %51, label %60
51: ; preds = %46
store i8 1, i8* %10
%52 = load i8*, i8** %5
%53 = getelementptr inbounds i8, i8* %52, i32 1
store i8* %53, i8** %5
%54 = load i8, i8* %52
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %4
store i8 %54, i8* %55
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
%59 = load i8*, i8** %4
store i8 0, i8* %59
br label %66
60: ; preds = %46
%61 = load i8*, i8** %5
%62 = getelementptr inbounds i8, i8* %61, i32 1
store i8* %62, i8** %5
%63 = load i8, i8* %61
%64 = load i8*, i8** %4
%65 = getelementptr inbounds i8, i8* %64, i32 1
store i8* %65, i8** %4
store i8 %63, i8* %64
br label %66
66: ; preds = %60, %51
br label %67
67: ; preds = %66, %37
br label %68
68: ; preds = %67
%69 = load i32, i32* %7
%70 = add nsw i32 %69, 1
store i32 %70, i32* %7
br label %24
71: ; preds = %32
ret void
}

LLVM IR (-O2):
@str = [63 x i8] c"Warning: number of returning symbols is more than same string.\00"
@str.2 = [71 x i8] c"Warning: number of returning symbols is more, than destination string.\00"
define void @strncpy_my(i8* nocapture writeonly %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 99
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.2, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = tail call i32 @strlen_my(i8* %1)
%9 = icmp slt i32 %8, %2
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
br label %12
12: ; preds = %10, %7
%13 = icmp sgt i32 %2, 0
br i1 %13, label %14, label %68
14: ; preds = %12
%15 = add i32 %8, -1
%16 = add i32 %2, -1
%17 = call i32 @llvm.umin.i32(i32 %15, i32 %16)
%18 = call i32 @llvm.umin.i32(i32 %17, i32 98)
%19 = add nuw nsw i32 %18, 1
%20 = zext i32 %19 to i64
%21 = icmp ult i32 %18, 16
br i1 %21, label %50, label %22
22: ; preds = %14
%23 = add i32 %2, -1
%24 = call i32 @llvm.umin.i32(i32 %15, i32 %23)
%25 = call i32 @llvm.umin.i32(i32 %24, i32 98)
%26 = add nuw nsw i32 %25, 1
%27 = zext i32 %26 to i64
%28 = getelementptr i8, i8* %0, i64 %27
%29 = getelementptr i8, i8* %1, i64 %27
%30 = icmp ugt i8* %29, %0
%31 = icmp ugt i8* %28, %1
%32 = and i1 %30, %31
br i1 %32, label %50, label %33
33: ; preds = %22
%34 = and i64 %20, 15
%35 = icmp eq i64 %34, 0
%36 = select i1 %35, i64 16, i64 %34
%37 = sub nsw i64 %20, %36
%38 = getelementptr i8, i8* %0, i64 %37
%39 = trunc i64 %37 to i32
%40 = getelementptr i8, i8* %1, i64 %37
br label %41
41: ; preds = %41, %33
%42 = phi i64 [ 0, %33 ], [ %48, %41 ]
%43 = getelementptr i8, i8* %0, i64 %42
%44 = getelementptr i8, i8* %1, i64 %42
%45 = bitcast i8* %44 to <16 x i8>*
%46 = load <16 x i8>, <16 x i8>* %45
%47 = bitcast i8* %43 to <16 x i8>*
store <16 x i8> %46, <16 x i8>* %47
%48 = add nuw i64 %42, 16
%49 = icmp eq i64 %48, %37
br i1 %49, label %50, label %41
50: ; preds = %41, %22, %14
%51 = phi i8* [ %0, %22 ], [ %0, %14 ], [ %38, %41 ]
%52 = phi i32 [ 0, %22 ], [ 0, %14 ], [ %39, %41 ]
%53 = phi i8* [ %1, %22 ], [ %1, %14 ], [ %40, %41 ]
br label %54
54: ; preds = %50, %63
%55 = phi i8* [ %62, %63 ], [ %51, %50 ]
%56 = phi i32 [ %65, %63 ], [ %52, %50 ]
%57 = phi i8* [ %64, %63 ], [ %53, %50 ]
%58 = icmp eq i32 %56, 98
%59 = icmp eq i32 %56, %15
%60 = select i1 %58, i1 true, i1 %59
%61 = load i8, i8* %57
%62 = getelementptr inbounds i8, i8* %55, i64 1
store i8 %61, i8* %55
br i1 %60, label %67, label %63
63: ; preds = %54
%64 = getelementptr inbounds i8, i8* %57, i64 1
%65 = add nuw nsw i32 %56, 1
%66 = icmp slt i32 %65, %2
br i1 %66, label %54, label %68
67: ; preds = %54
store i8 0, i8* %62
br label %68
68: ; preds = %63, %67, %12
ret void
}