#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 */
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  char buf[256];
  char buf2[sizeof(buf)];
  if (strlen("") != 0) {
    printf("strlen 1 failed\n");
    return 1;
  }
  if (strlen("0123456789") != 10) {
    printf("strlen 2 failed\n");
    return 1;
  }
  strncpy(buf, "0123456789012345678901234567890", 6);
  strncpy(buf + 5, "ABC", 8);
  if (strcmp(buf, "01234ABC") != 0) {
    printf("strncpy failed\n");
    printf("result: %s\n", buf);
    return 1;
  }
  memset(buf, 0, sizeof(buf));
  memset(buf, 'A', 64);
  memset(buf + 10, 'B', 23);
  memset(buf + 15, 'C', 5);
  if (strcmp("AAAAAAAAAABBBBBCCCCCBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
             buf) != 0)
    return 1;
  memcpy(buf2, buf, sizeof(buf2));
  return strcmp(buf, buf2) != 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     11a8 <main+0x48>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x1b7>
lea    0xe62(%rip),%rdi
call   1040 <strlen@plt>
cmp    $0xa,%eax
je     11d7 <main+0x77>
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x1b7>
lea    -0x110(%rbp),%rdi
lea    0xe48(%rip),%rsi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rdi
add    $0x5,%rdi
lea    0xe51(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    -0x110(%rbp),%rdi
lea    0xe34(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1257 <main+0xf7>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x1b7>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    $0x41,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
add    $0xa,%rdi
mov    $0x42,%esi
mov    $0x17,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
add    $0xf,%rdi
mov    $0x43,%esi
mov    $0x5,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rsi
lea    0xdb0(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12dd <main+0x17d>
movl   $0x1,-0x4(%rbp)
jmp    1317 <main+0x1b7>
lea    -0x210(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1080 <memcpy@plt>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xebe(%rip),%rdi
call   1050 <strlen@plt>
test   %eax,%eax
je     1193 <main+0x23>
lea    0xf0f(%rip),%rdi
jmp    120b <main+0x9b>
lea    0xe66(%rip),%rdi
call   1050 <strlen@plt>
cmp    $0xa,%eax
jne    1204 <main+0x94>
lea    0xe60(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x6,%edx
call   1030 <strncpy@plt>
lea    0x5(%rsp),%rdi
lea    0xe69(%rip),%rsi
mov    $0x8,%edx
call   1030 <strncpy@plt>
lea    0xe53(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1220 <main+0xb0>
lea    0xe95(%rip),%rdi
call   1040 <puts@plt>
lea    0xe3c(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1210 <main+0xa0>
lea    0xe85(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
mov    $0x41,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
lea    0xa(%rsp),%rdi
mov    $0x42,%esi
mov    $0x17,%edx
call   1070 <memset@plt>
lea    0xf(%rsp),%rdi
mov    $0x43,%esi
mov    $0x5,%edx
call   1070 <memset@plt>
lea    0xdcd(%rip),%rdi
mov    %rbx,%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    1215 <main+0xa5>
lea    0x100(%rsp),%r14
mov    %rsp,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0x100,%edx
call   1090 <memcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    1215 <main+0xa5>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [17 x i8] c"strlen 1 failed\0A\00"
@.str.2 = [11 x i8] c"0123456789\00"
@.str.3 = [17 x i8] c"strlen 2 failed\0A\00"
@.str.4 = [32 x i8] c"0123456789012345678901234567890\00"
@.str.5 = [4 x i8] c"ABC\00"
@.str.6 = [9 x i8] c"01234ABC\00"
@.str.7 = [16 x i8] c"strncpy failed\0A\00"
@.str.8 = [12 x i8] c"result: %s\0A\00"
@.str.9 = [65 x i8] c"AAAAAAAAAABBBBBCCCCCBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [256 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 @strlen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%9 = icmp ne i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %54
12: ; preds = %2
%13 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp ne i32 %13, 10
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %54
17: ; preds = %12
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%19 = call i32 @strncpy(i8* %18, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 6)
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds i8, i8* %20, i64 5
%22 = call i32 @strncpy(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 8)
%23 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %17
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
br label %54
30: ; preds = %17
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%32 = call i32 @memset(i8* %31, i8 signext 0, i32 256)
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%34 = call i32 @memset(i8* %33, i8 signext 65, i32 64)
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%36 = getelementptr inbounds i8, i8* %35, i64 10
%37 = call i32 @memset(i8* %36, i8 signext 66, i32 23)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%39 = getelementptr inbounds i8, i8* %38, i64 15
%40 = call i32 @memset(i8* %39, i8 signext 67, i32 5)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%42 = call i64 @strcmp(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.9, i64 0, i64 0), i8* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %30
store i32 1, i32* %3
br label %54
45: ; preds = %30
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%48 = call i32 @memcpy(i8* %46, i8* %47, i32 256)
%49 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%51 = call i64 @strcmp(i8* %49, i8* %50)
%52 = icmp ne i64 %51, 0
%53 = zext i1 %52 to i32
store i32 %53, i32* %3
br label %54
54: ; preds = %45, %44, %26, %15, %10
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.2 = [11 x i8] c"0123456789\00"
@.str.4 = [32 x i8] c"0123456789012345678901234567890\00"
@.str.5 = [4 x i8] c"ABC\00"
@.str.6 = [9 x i8] c"01234ABC\00"
@.str.8 = [12 x i8] c"result: %s\0A\00"
@.str.9 = [65 x i8] c"AAAAAAAAAABBBBBCCCCCBBBBBBBBBBBBBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\00"
@str = [15 x i8] c"strncpy failed\00"
@str.10 = [16 x i8] c"strlen 2 failed\00"
@str.11 = [16 x i8] c"strlen 1 failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.11, i64 0, i64 0))
br label %39
11: ; preds = %2
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32 %12, 10
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.10, i64 0, i64 0))
br label %39
16: ; preds = %11
%17 = call i32 @strncpy(i8* %5, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0), i32 6)
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 5
%19 = call i32 @strncpy(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i32 8)
%20 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i8* %5)
br label %39
25: ; preds = %16
%26 = call i32 @memset(i8* %5, i8 signext 0, i32 256)
%27 = call i32 @memset(i8* %5, i8 signext 65, i32 64)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 10
%29 = call i32 @memset(i8* %28, i8 signext 66, i32 23)
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 15
%31 = call i32 @memset(i8* %30, i8 signext 67, i32 5)
%32 = call i64 @strcmp(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.9, i64 0, i64 0), i8* %5)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %25
%35 = call i32 @memcpy(i8* %6, i8* %5, i32 256)
%36 = call i64 @strcmp(i8* %5, i8* %6)
%37 = icmp ne i64 %36, 0
%38 = zext i1 %37 to i32
br label %39
39: ; preds = %25, %34, %22, %14, %9
%40 = phi i32 [ 1, %9 ], [ 1, %14 ], [ 1, %22 ], [ %38, %34 ], [ 1, %25 ]
ret i32 %40
}