#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 /*<<< orphan*/ strncat(char *, char *, int);
int strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(void) {
  char s1[100] = "test";
  char *t1 = "longstring";
  strncpy(s1, t1, 3);
  printf("%s\n", s1);
  char s2[100] = "test2";
  char *t2 = "longstring2";
  strncat(s2, t2, 3);
  printf("%s\n", s2);
  char *s3 = "test3";
  char *t3 = "test3123";
  printf("%d\n", strncmp(s3, t3, 3));
  printf("%d\n", strncmp(s3, t3, 5));
  printf("%d\n", strncmp(s3, t3, 7));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
movb   $0x74,-0x70(%rbp)
movb   $0x65,-0x6f(%rbp)
movb   $0x73,-0x6e(%rbp)
movb   $0x74,-0x6d(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    $0x3,%edx
call   1030 <strncpy@plt>
lea    -0x70(%rbp),%rsi
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1060 <memset@plt>
movb   $0x74,-0xe0(%rbp)
movb   $0x65,-0xdf(%rbp)
movb   $0x73,-0xde(%rbp)
movb   $0x74,-0xdd(%rbp)
movb   $0x32,-0xdc(%rbp)
lea    0xe21(%rip),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%rdi
mov    -0xe8(%rbp),%rsi
mov    $0x3,%edx
call   1070 <strncat@plt>
lea    -0xe0(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdf2(%rip),%rax
mov    %rax,-0xf0(%rbp)
lea    0xdea(%rip),%rax
mov    %rax,-0xf8(%rbp)
mov    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xdcb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xda3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf0(%rbp),%rdi
mov    -0xf8(%rbp),%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
mov    %eax,%esi
lea    0xd7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movl   $0x0,0xd0(%rsp)
movl   $0x74736574,0x70(%rsp)
74
lea    0xe5a(%rip),%rsi
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x60(%rsp)
movl   $0x74736574,(%rsp)
movb   $0x32,0x4(%rsp)
lea    0xe10(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x3,%edx
call   1070 <strncat@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
lea    0xdfd(%rip),%r15
lea    0xdfc(%rip),%r14
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1040 <strncmp@plt>
lea    0xdee(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1040 <strncmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x7,%edx
call   1040 <strncmp@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"longstring\00"
@.str.1 = [4 x i8] c"%s\0A\00"
@.str.2 = [12 x i8] c"longstring2\00"
@.str.3 = [6 x i8] c"test3\00"
@.str.4 = [9 x i8] c"test3123\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 0, i32* %1
%8 = bitcast [100 x i8]* %2 to i8*
%9 = bitcast i8* %8 to [100 x i8]*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i32 0, i32 0
store i8 116, i8* %10
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i32 0, i32 1
store i8 101, i8* %11
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i32 0, i32 2
store i8 115, i8* %12
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %9, i32 0, i32 3
store i8 116, i8* %13
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%15 = load i8*, i8** %3
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 3)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = bitcast [100 x i8]* %4 to i8*
%20 = bitcast i8* %19 to [100 x i8]*
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i32 0, i32 0
store i8 116, i8* %21
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i32 0, i32 1
store i8 101, i8* %22
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i32 0, i32 2
store i8 115, i8* %23
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i32 0, i32 3
store i8 116, i8* %24
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %20, i32 0, i32 4
store i8 50, i8* %25
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8** %5
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = load i8*, i8** %5
%28 = call i32 @strncat(i8* %26, i8* %27, i32 3)
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %7
%31 = load i8*, i8** %6
%32 = load i8*, i8** %7
%33 = call i32 @strncmp(i8* %31, i8* %32, i32 3)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %33)
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = call i32 @strncmp(i8* %35, i8* %36, i32 5)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %6
%40 = load i8*, i8** %7
%41 = call i32 @strncmp(i8* %39, i8* %40, i32 7)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %41)
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"longstring\00"
@.str.2 = [12 x i8] c"longstring2\00"
@.str.3 = [6 x i8] c"test3\00"
@.str.4 = [9 x i8] c"test3123\00"
@.str.5 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 116, i8* %3
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 1
store i8 101, i8* %4
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 2
store i8 115, i8* %5
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 3
store i8 116, i8* %6
%7 = call i32 @strncpy(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 3)
%8 = call i32 @puts(i8* %3)
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
store i8 116, i8* %9
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 1
store i8 101, i8* %10
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 2
store i8 115, i8* %11
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 3
store i8 116, i8* %12
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 4
store i8 50, i8* %13
%14 = call i32 @strncat(i8* %9, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 3)
%15 = call i32 @puts(i8* %9)
%16 = call i32 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 3)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 5)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %18)
%20 = call i32 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32 7)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 %20)
ret i32 0
}