#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*/ mystrncat(char *, char *, int);
int mystrncmp(char *, char *, int);
int /*<<< orphan*/ mystrncpy(char *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  char s1[] = "hello";
  char t1[] = "world";
  char s2[100] = "hello, ";
  char t2[] = "world!";
  char s3[] = "java";
  char t3[] = "javascript";
  int n = 3;
  int result;
  mystrncpy(s1, t1, n);
  printf("results: %s\n", s1);
  mystrncat(s2, t2, n);
  printf("result: %s\n", s2);
  result = mystrncmp(s3, t3, n);
  printf("result: %d\n", result);
  result = mystrncmp(s3, t3, 5);
  printf("result: %d\n", result);
  result = mystrncmp(t3, s3, 5);
  printf("result: %d\n", result);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe98(%rip),%eax
mov    %eax,-0x16(%rbp)
mov    0xe92(%rip),%ax
mov    %ax,-0x12(%rbp)
mov    0xe8a(%rip),%eax
mov    %eax,-0x1c(%rbp)
mov    0xe84(%rip),%ax
mov    %ax,-0x18(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xebb(%rip),%rsi
mov    $0x64,%edx
call   1050 <memcpy@plt>
mov    0xe67(%rip),%eax
mov    %eax,-0x87(%rbp)
mov    0xe5e(%rip),%ax
mov    %ax,-0x83(%rbp)
mov    0xe53(%rip),%al
mov    %al,-0x81(%rbp)
mov    0xe48(%rip),%eax
mov    %eax,-0x8c(%rbp)
mov    0xe40(%rip),%al
mov    %al,-0x88(%rbp)
mov    0xe34(%rip),%rax
mov    %rax,-0x97(%rbp)
mov    0xe2e(%rip),%ax
mov    %ax,-0x8f(%rbp)
mov    0xe23(%rip),%al
mov    %al,-0x8d(%rbp)
movl   $0x3,-0x9c(%rbp)
lea    -0x16(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
mov    -0x9c(%rbp),%edx
call   1070 <mystrncpy@plt>
lea    -0x16(%rbp),%rsi
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    -0x87(%rbp),%rsi
mov    -0x9c(%rbp),%edx
call   1030 <mystrncat@plt>
lea    -0x80(%rbp),%rsi
lea    0xddb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8c(%rbp),%rdi
lea    -0x97(%rbp),%rsi
mov    -0x9c(%rbp),%edx
call   1060 <mystrncmp@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%esi
lea    0xdb4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x8c(%rbp),%rdi
lea    -0x97(%rbp),%rsi
mov    $0x5,%edx
call   1060 <mystrncmp@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%esi
lea    0xd82(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x97(%rbp),%rdi
lea    -0x8c(%rbp),%rsi
mov    $0x5,%edx
call   1060 <mystrncmp@plt>
mov    %eax,-0xa0(%rbp)
mov    -0xa0(%rbp),%esi
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
movw   $0x6f,0x14(%rsp)
movl   $0x6c6c6568,0x10(%rsp)
6c
movw   $0x64,0xc(%rsp)
movl   $0x6c726f77,0x8(%rsp)
6c
movaps 0xf2f(%rip),%xmm0
movaps %xmm0,0x80(%rsp)
movaps 0xf10(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xef4(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xed8(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xebc(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xea0(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movl   $0x0,0x90(%rsp)
movl   $0x21646c,0x1b(%rsp)
movl   $0x6c726f77,0x18(%rsp)
6c
movb   $0x0,0x4(%rsp)
movl   $0x6176616a,(%rsp)
movabs $0x697263736176616a,%rax
63 72 69
mov    %rax,0x20(%rsp)
movl   $0x747069,0x27(%rsp)
lea    0x10(%rsp),%rbx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1060 <mystrncpy@plt>
lea    0xe12(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x30(%rsp),%rbx
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <mystrncat@plt>
lea    0xdf7(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rsp,%r14
lea    0x20(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x3,%edx
call   1050 <mystrncmp@plt>
lea    0xdda(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1050 <mystrncmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1050 <mystrncmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.s1 = [6 x i8] c"hello\00"
@__const.main.t1 = [6 x i8] c"world\00"
@__const.main.s2 = [100 x i8] c"hello, \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.t2 = [7 x i8] c"world!\00"
@__const.main.s3 = [5 x i8] c"java\00"
@__const.main.t3 = [11 x i8] c"javascript\00"
@.str = [13 x i8] c"results: %s\0A\00"
@.str.1 = [12 x i8] c"result: %s\0A\00"
@.str.2 = [12 x i8] c"result: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [6 x i8]
%6 = alloca [6 x i8]
%7 = alloca [100 x i8]
%8 = alloca [7 x i8]
%9 = alloca [5 x i8]
%10 = alloca [11 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = bitcast [6 x i8]* %5 to i8*
%14 = bitcast [6 x i8]* %6 to i8*
%15 = bitcast [100 x i8]* %7 to i8*
%16 = bitcast [7 x i8]* %8 to i8*
%17 = bitcast [5 x i8]* %9 to i8*
%18 = bitcast [11 x i8]* %10 to i8*
store i32 3, i32* %11
%19 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%20 = getelementptr inbounds [6 x i8], [6 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* %11
%22 = call i32 @mystrncpy(i8* %19, i8* %20, i32 %21)
%23 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%26 = getelementptr inbounds [7 x i8], [7 x i8]* %8, i64 0, i64 0
%27 = load i32, i32* %11
%28 = call i32 @mystrncat(i8* %25, i8* %26, i32 %27)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%32 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 0
%33 = load i32, i32* %11
%34 = call i32 @mystrncmp(i8* %31, i8* %32, i32 %33)
store i32 %34, i32* %12
%35 = load i32, i32* %12
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 0
%39 = call i32 @mystrncmp(i8* %37, i8* %38, i32 5)
store i32 %39, i32* %12
%40 = load i32, i32* %12
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [11 x i8], [11 x i8]* %10, i64 0, i64 0
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %9, i64 0, i64 0
%44 = call i32 @mystrncmp(i8* %42, i8* %43, i32 5)
store i32 %44, i32* %12
%45 = load i32, i32* %12
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %45)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s1 = [6 x i8] c"hello\00"
@__const.main.t1 = [6 x i8] c"world\00"
@__const.main.s2 = [100 x i8] c"hello, \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.t2 = [7 x i8] c"world!\00"
@__const.main.s3 = [5 x i8] c"java\00"
@__const.main.t3 = [11 x i8] c"javascript\00"
@.str = [13 x i8] c"results: %s\0A\00"
@.str.1 = [12 x i8] c"result: %s\0A\00"
@.str.2 = [12 x i8] c"result: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [6 x i8]
%4 = alloca [6 x i8]
%5 = alloca [100 x i8]
%6 = alloca [7 x i8]
%7 = alloca [5 x i8]
%8 = alloca [11 x i8]
%9 = getelementptr inbounds [6 x i8], [6 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [7 x i8], [7 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%14 = getelementptr inbounds [11 x i8], [11 x i8]* %8, i64 0, i64 0
%15 = call i32 @mystrncpy(i8* %9, i8* %10, i32 3)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* %9)
%17 = call i32 @mystrncat(i8* %11, i8* %12, i32 3)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%19 = call i32 @mystrncmp(i8* %13, i8* %14, i32 3)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = call i32 @mystrncmp(i8* %13, i8* %14, i32 5)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 @mystrncmp(i8* %14, i8* %13, i32 5)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i32 0
}