#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 *, ...);
char *strn_cat(char *, char *, int);
int strn_cmp(char *, char *, int);
int /*<<< orphan*/ strn_cpy(char *, char *, int);
int main(int argc, char **argv) {
  char s[100] = "This is the first test string.";
  char *ps;
  int r;
  printf("Test string s:\n%s\n", s);
  printf("\n");
  strn_cpy(s, "This is the ", 12);
  printf("strn_cpy(s, \"This is the \", 12):\ns: %s\n", s);
  strn_cpy(s, "This is the ", 30);
  printf("strn_cpy(s, \"This is the \", 30):\ns: %s\n", s);
  printf("Should be padded with 0s. Test s[12] == 0? %d\n",
         s[12] == '\0' ? 1 : 0);
  printf("Should be padded with 0s. Test s[16] == 0? %d\n",
         s[16] == '\0' ? 1 : 0);
  printf("Should be padded with 0s. Test s[29] == 0? %d\n",
         s[29] == '\0' ? 1 : 0);
  ps = strn_cat(s, "concatenated string.", 20);
  printf("strn_cat(s, \"concatenated string. But this sentence must not be "
         "copied.\", 20):\ns: %s\n",
         ps);
  printf("\n");
  r = strn_cmp(s, "This is the", 5);
  printf("strn_cmp(s, \"This is the\", 5) returns %d\n", r);
  r = strn_cmp(s, "This is the", 11);
  printf("strn_cmp(s, \"This is the\", 11) returns %d\n", r);
  r = strn_cmp(s, "This is the", 15);
  printf("strn_cmp(s, \"This is the\", 15) returns %d\n", r);
  r = strn_cmp(s, "UVWXYZ", 6);
  printf("strn_cmp(s, \"UVWXYZ\", 6) returns %d\n", r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe8c(%rip),%rsi
mov    $0x64,%edx
call   1060 <memcpy@plt>
lea    -0x80(%rbp),%rsi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xf6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xece(%rip),%rsi
mov    $0xc,%edx
call   1050 <strn_cpy@plt>
lea    -0x80(%rbp),%rsi
lea    0xec6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xea7(%rip),%rsi
mov    $0x1e,%edx
call   1050 <strn_cpy@plt>
lea    -0x80(%rbp),%rsi
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x74(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmove  %eax,%esi
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x70(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmove  %eax,%esi
lea    0xee0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movsbl -0x63(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%eax
cmp    $0x0,%ecx
cmove  %eax,%esi
lea    0xef0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xf0d(%rip),%rsi
mov    $0x14,%edx
call   1070 <strn_cat@plt>
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rsi
lea    0xf03(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xf39(%rip),%rsi
mov    $0x5,%edx
call   1030 <strn_cmp@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xf28(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xf0a(%rip),%rsi
mov    $0xb,%edx
call   1030 <strn_cmp@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xf23(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xedb(%rip),%rsi
mov    $0xf,%edx
call   1030 <strn_cmp@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xf1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rdi
lea    0xf38(%rip),%rsi
mov    $0x6,%edx
call   1030 <strn_cmp@plt>
mov    %eax,-0x8c(%rbp)
mov    -0x8c(%rbp),%esi
lea    0xf22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x68,%rsp
movaps 0xef2(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xed6(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xeba(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe9e(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe82(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xe66(%rip),%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xeb7(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xeac(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1060 <strn_cpy@plt>
lea    0xea2(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x1e,%edx
call   1060 <strn_cpy@plt>
lea    0xea9(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %esi,%esi
cmpb   $0x0,0xc(%rsp)
sete   %sil
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %esi,%esi
cmpb   $0x0,0x10(%rsp)
sete   %sil
lea    0xecb(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %esi,%esi
cmpb   $0x0,0x1d(%rsp)
sete   %sil
lea    0xee1(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf02(%rip),%rsi
mov    %r14,%rdi
mov    $0x14,%edx
call   1070 <strn_cat@plt>
lea    0xf03(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xf3e(%rip),%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x5,%edx
call   1030 <strn_cmp@plt>
lea    0xf33(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xb,%edx
call   1030 <strn_cmp@plt>
lea    0xf3d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xf,%edx
call   1030 <strn_cmp@plt>
lea    0xf48(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf63(%rip),%rsi
mov    %r14,%rdi
mov    $0x6,%edx
call   1030 <strn_cmp@plt>
lea    0xf56(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.s = [100 x i8] c"This is the first test string.\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"
@.str = [19 x i8] c"Test string s:\0A%s\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [13 x i8] c"This is the \00"
@.str.3 = [40 x i8] c"strn_cpy(s, \22This is the \22, 12):\0As: %s\0A\00"
@.str.4 = [40 x i8] c"strn_cpy(s, \22This is the \22, 30):\0As: %s\0A\00"
@.str.5 = [47 x i8] c"Should be padded with 0s. Test s[12] == 0? %d\0A\00"
@.str.6 = [47 x i8] c"Should be padded with 0s. Test s[16] == 0? %d\0A\00"
@.str.7 = [47 x i8] c"Should be padded with 0s. Test s[29] == 0? %d\0A\00"
@.str.8 = [21 x i8] c"concatenated string.\00"
@.str.9 = [86 x i8] c"strn_cat(s, \22concatenated string. But this sentence must not be copied.\22, 20):\0As: %s\0A\00"
@.str.10 = [12 x i8] c"This is the\00"
@.str.11 = [42 x i8] c"strn_cmp(s, \22This is the\22, 5) returns %d\0A\00"
@.str.12 = [43 x i8] c"strn_cmp(s, \22This is the\22, 11) returns %d\0A\00"
@.str.13 = [43 x i8] c"strn_cmp(s, \22This is the\22, 15) returns %d\0A\00"
@.str.14 = [7 x i8] c"UVWXYZ\00"
@.str.15 = [37 x i8] c"strn_cmp(s, \22UVWXYZ\22, 6) returns %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [100 x i8]* %6 to i8*
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%14 = call i32 @strn_cpy(i8* %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%18 = call i32 @strn_cpy(i8* %17, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 30)
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 12
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 0
%25 = zext i1 %24 to i64
%26 = select i1 %24, i32 1, i32 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 16
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 0
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 1, i32 0
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i32 %33)
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 29
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 1, i32 0
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %40)
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%43 = call i8* @strn_cat(i8* %42, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 20)
store i8* %43, i8** %7
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.9, i64 0, i64 0), i8* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%47 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%48 = call i32 @strn_cmp(i8* %47, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 5)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 %49)
%51 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%52 = call i32 @strn_cmp(i8* %51, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 11)
store i32 %52, i32* %8
%53 = load i32, i32* %8
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i32 %53)
%55 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%56 = call i32 @strn_cmp(i8* %55, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 15)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0), i32 %57)
%59 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%60 = call i32 @strn_cmp(i8* %59, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 6)
store i32 %60, i32* %8
%61 = load i32, i32* %8
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i32 %61)
ret i32 0
}

LLVM IR (-O2):
@__const.main.s = [100 x i8] c"This is the first test string.\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"
@.str = [19 x i8] c"Test string s:\0A%s\0A\00"
@.str.2 = [13 x i8] c"This is the \00"
@.str.3 = [40 x i8] c"strn_cpy(s, \22This is the \22, 12):\0As: %s\0A\00"
@.str.4 = [40 x i8] c"strn_cpy(s, \22This is the \22, 30):\0As: %s\0A\00"
@.str.5 = [47 x i8] c"Should be padded with 0s. Test s[12] == 0? %d\0A\00"
@.str.6 = [47 x i8] c"Should be padded with 0s. Test s[16] == 0? %d\0A\00"
@.str.7 = [47 x i8] c"Should be padded with 0s. Test s[29] == 0? %d\0A\00"
@.str.8 = [21 x i8] c"concatenated string.\00"
@.str.9 = [86 x i8] c"strn_cat(s, \22concatenated string. But this sentence must not be copied.\22, 20):\0As: %s\0A\00"
@.str.10 = [12 x i8] c"This is the\00"
@.str.11 = [42 x i8] c"strn_cmp(s, \22This is the\22, 5) returns %d\0A\00"
@.str.12 = [43 x i8] c"strn_cmp(s, \22This is the\22, 11) returns %d\0A\00"
@.str.13 = [43 x i8] c"strn_cmp(s, \22This is the\22, 15) returns %d\0A\00"
@.str.14 = [7 x i8] c"UVWXYZ\00"
@.str.15 = [37 x i8] c"strn_cmp(s, \22UVWXYZ\22, 6) returns %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32 @putchar(i32 10)
%7 = call i32 @strn_cpy(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 12)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%9 = call i32 @strn_cpy(i8* %4, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32 30)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i8* %4)
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 12
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = zext i1 %13 to i32
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 16
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
%19 = zext i1 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.6, i64 0, i64 0), i32 %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 29
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
%24 = zext i1 %23 to i32
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0), i32 %24)
%26 = call i8* @strn_cat(i8* %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 20)
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([86 x i8], [86 x i8]* @.str.9, i64 0, i64 0), i8* %26)
%28 = call i32 @putchar(i32 10)
%29 = call i32 @strn_cmp(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 5)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.11, i64 0, i64 0), i32 %29)
%31 = call i32 @strn_cmp(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 11)
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.12, i64 0, i64 0), i32 %31)
%33 = call i32 @strn_cmp(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i64 0, i64 0), i32 15)
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.13, i64 0, i64 0), i32 %33)
%35 = call i32 @strn_cmp(i8* %4, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.14, i64 0, i64 0), i32 6)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.15, i64 0, i64 0), i32 %35)
ret i32 0
}