#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*/ mstrncat(char *, char *, int);
int mstrncmp(char *, char *, int);
int /*<<< orphan*/ mstrncpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  char s[] = "first  string";
  char t[] = "second string";
  char bs[20];
  bs[0] = 'H';
  bs[1] = 'e';
  bs[2] = 'l';
  bs[3] = 'l';
  bs[4] = 'o';
  bs[5] = '!';
  bs[6] = '\0';
  printf("s : %s\n", s);
  printf("t : %s\n", t);
  printf("bs: %s\n", bs);
  printf("\n");
  mstrncpy(s, t, 5);
  printf("strncpy(s,t,5):\n%s\n\n", s);
  mstrncat(bs, t, 5);
  printf("strncat(bs,t,5):\n%s\n\n", bs);
  printf("strncmp('vladi', 'vlado', 4): %i\n", mstrncmp("vladi", "vlado", 4));
  printf("strncmp('vladi', 'vlado', 5): %i\n", mstrncmp("vladi", "vlado", 5));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x12(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0xa(%rbp)
mov    0xea2(%rip),%ax
mov    %ax,-0x6(%rbp)
mov    0xe99(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe97(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xe91(%rip),%ax
mov    %ax,-0x14(%rbp)
movb   $0x48,-0x40(%rbp)
movb   $0x65,-0x3f(%rbp)
movb   $0x6c,-0x3e(%rbp)
movb   $0x6c,-0x3d(%rbp)
movb   $0x6f,-0x3c(%rbp)
movb   $0x21,-0x3b(%rbp)
movb   $0x0,-0x3a(%rbp)
lea    -0x12(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x12(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x5,%edx
call   1030 <mstrncpy@plt>
lea    -0x12(%rbp),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x5,%edx
call   1060 <mstrncat@plt>
lea    -0x40(%rbp),%rsi
lea    0xe1b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe45(%rip),%rdi
lea    0xe44(%rip),%rsi
mov    $0x4,%edx
call   1050 <mstrncmp@plt>
mov    %eax,%esi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe1d(%rip),%rdi
lea    0xe1c(%rip),%rsi
mov    $0x5,%edx
call   1050 <mstrncmp@plt>
mov    %eax,%esi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x40,%rsp
movabs $0x676e6972747320,%rax
mov    %rax,0x16(%rsp)
movabs $0x7320207473726966,%rcx
20 20 73
mov    %rcx,0x10(%rsp)
mov    %rax,0x6(%rsp)
movabs $0x7320646e6f636573,%rax
64 20 73
mov    %rax,(%rsp)
movl   $0x6c6c6548,0x20(%rsp)
6c
movw   $0x216f,0x24(%rsp)
movb   $0x0,0x26(%rsp)
lea    0xe77(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe69(%rip),%rdi
mov    %rsp,%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe5d(%rip),%rdi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <mstrncpy@plt>
lea    0xe35(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1070 <mstrncat@plt>
lea    0xe29(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe50(%rip),%rbx
lea    0xe4f(%rip),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x4,%edx
call   1060 <mstrncmp@plt>
lea    0xe10(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1060 <mstrncmp@plt>
lea    0xe1e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.s = [14 x i8] c"first string\00"
@__const.main.t = [14 x i8] c"second string\00"
@.str = [8 x i8] c"s : %s\0A\00"
@.str.1 = [8 x i8] c"t : %s\0A\00"
@.str.2 = [8 x i8] c"bs: %s\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [21 x i8] c"strncpy(s,t,5):\0A%s\0A\0A\00"
@.str.5 = [22 x i8] c"strncat(bs,t,5):\0A%s\0A\0A\00"
@.str.6 = [34 x i8] c"strncmp('vladi', 'vlado', 4): %i\0A\00"
@.str.7 = [6 x i8] c"vladi\00"
@.str.8 = [6 x i8] c"vlado\00"
@.str.9 = [34 x i8] c"strncmp('vladi', 'vlado', 5): %i\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [14 x i8]
%3 = alloca [14 x i8]
%4 = alloca [20 x i8]
store i32 0, i32* %1
%5 = bitcast [14 x i8]* %2 to i8*
%6 = bitcast [14 x i8]* %3 to i8*
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
store i8 72, i8* %7
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 1
store i8 101, i8* %8
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 2
store i8 108, i8* %9
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 3
store i8 108, i8* %10
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 4
store i8 111, i8* %11
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 5
store i8 33, i8* %12
%13 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 6
store i8 0, i8* %13
%14 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %18)
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%21 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%23 = call i32 @mstrncpy(i8* %21, i8* %22, i32 5)
%24 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [14 x i8], [14 x i8]* %3, i64 0, i64 0
%28 = call i32 @mstrncat(i8* %26, i8* %27, i32 5)
%29 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %29)
%31 = call i32 @mstrncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 4)
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %31)
%33 = call i32 @mstrncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i32 %33)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [14 x i8] c"first string\00"
@__const.main.t = [14 x i8] c"second string\00"
@.str = [8 x i8] c"s : %s\0A\00"
@.str.1 = [8 x i8] c"t : %s\0A\00"
@.str.2 = [8 x i8] c"bs: %s\0A\00"
@.str.4 = [21 x i8] c"strncpy(s,t,5):\0A%s\0A\0A\00"
@.str.5 = [22 x i8] c"strncat(bs,t,5):\0A%s\0A\0A\00"
@.str.6 = [34 x i8] c"strncmp('vladi', 'vlado', 4): %i\0A\00"
@.str.7 = [6 x i8] c"vladi\00"
@.str.8 = [6 x i8] c"vlado\00"
@.str.9 = [34 x i8] c"strncmp('vladi', 'vlado', 5): %i\0A\00"
define i32 @main() {
%1 = alloca [14 x i8]
%2 = alloca [14 x i8]
%3 = alloca [20 x i8]
%4 = getelementptr inbounds [14 x i8], [14 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [14 x i8], [14 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
store i8 72, i8* %6
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 1
store i8 101, i8* %7
%8 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 2
store i8 108, i8* %8
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 3
store i8 108, i8* %9
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 4
store i8 111, i8* %10
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 5
store i8 33, i8* %11
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 6
store i8 0, i8* %12
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %4)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%16 = call i32 @putchar(i32 10)
%17 = call i32 @mstrncpy(i8* %4, i8* %5, i32 5)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%19 = call i32 @mstrncat(i8* %6, i8* %5, i32 5)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%21 = call i32 @mstrncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = call i32 @mstrncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i32 5)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i32 %23)
ret i32 0
}