#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 *strcat(char *, char const *);
int strcmp(char const *, char const *);
char *strncat(char *, char const *, int);
int main() {
  char arr[20] = "apple";
  const char *p = "pear";
  char *p2 = strcat(arr, p);
  printf("arr=%s,p=%s,p2=%s\n", arr, p, p2);
  const char *pc = "abc";
  const char *pc2 = "abcdefg";
  const char *pc3 = "abc";
  printf("d:%d\n", 'd');
  printf("strcmp(pc, pc2):%d\n", strcmp(pc, pc2));
  printf("strcmp(pc2, pc):%d\n", strcmp(pc2, pc));
  printf("strcmp(pc, pc3):%d\n", strcmp(pc, pc3));
  char a[10] = "apple";
  const char *pt = "pear";
  char *pt2 = strncat(a, pt, 2);
  printf("a=%s,pt=%s,pt2=%s\n", a, pt, pt2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xea5(%rip),%eax
mov    %eax,-0x10(%rbp)
lea    0xea9(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <strcat@plt>
mov    %rax,-0x30(%rbp)
lea    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe8b(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    0xe84(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xe75(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xe76(%rip),%rdi
mov    $0x64,%esi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,%esi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,%esi
lea    0xe51(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1050 <strcmp@plt>
mov    %eax,%esi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0xdde(%rip),%rax
mov    %rax,-0x52(%rbp)
mov    0xddb(%rip),%ax
mov    %ax,-0x4a(%rbp)
lea    0xdd2(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    -0x52(%rbp),%rdi
mov    -0x60(%rbp),%rsi
mov    $0x2,%edx
call   1040 <strncat@plt>
mov    %rax,-0x68(%rbp)
lea    -0x52(%rbp),%rsi
mov    -0x60(%rbp),%rdx
mov    -0x68(%rbp),%rcx
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movaps 0xec2(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x20(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strlen@plt>
movl   $0x72616570,0x10(%rsp,%rax,1)
72
movb   $0x0,0x14(%rsp,%rax,1)
lea    0xeb2(%rip),%r14
lea    0xeb0(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xeac(%rip),%rdi
mov    $0x64,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe9f(%rip),%rdi
mov    $0xffffffff,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea1(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
movabs $0x656c707061,%rax
mov    %rax,(%rsp)
movw   $0x0,0x8(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x2,%edx
call   1050 <strncat@plt>
lea    0xe7d(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@__const.main.arr = [20 x i8] c"apple\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c"pear\00"
@.str.1 = [19 x i8] c"arr=%s,p=%s,p2=%s\0A\00"
@.str.2 = [4 x i8] c"abc\00"
@.str.3 = [8 x i8] c"abcdefg\00"
@.str.4 = [6 x i8] c"d:%d\0A\00"
@.str.5 = [20 x i8] c"strcmp(pc, pc2):%d\0A\00"
@.str.6 = [20 x i8] c"strcmp(pc2, pc):%d\0A\00"
@.str.7 = [20 x i8] c"strcmp(pc, pc3):%d\0A\00"
@__const.main.a = [10 x i8] c"apple\00\00\00\00\00"
@.str.8 = [19 x i8] c"a=%s,pt=%s,pt2=%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i8]
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [10 x i8]
%9 = alloca i8*
%10 = alloca i8*
store i32 0, i32* %1
%11 = bitcast [20 x i8]* %2 to i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%13 = load i8*, i8** %3
%14 = call i8* @strcat(i8* %12, i8* %13)
store i8* %14, i8** %4
%15 = getelementptr inbounds [20 x i8], [20 x i8]* %2, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = load i8*, i8** %4
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %15, i8* %16, i8* %17)
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %7
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 100)
%20 = load i8*, i8** %5
%21 = load i8*, i8** %6
%22 = call i32 @strcmp(i8* %20, i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %6
%25 = load i8*, i8** %5
%26 = call i32 @strcmp(i8* %24, i8* %25)
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 %26)
%28 = load i8*, i8** %5
%29 = load i8*, i8** %7
%30 = call i32 @strcmp(i8* %28, i8* %29)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 %30)
%32 = bitcast [10 x i8]* %8 to i8*
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %9
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%34 = load i8*, i8** %9
%35 = call i8* @strncat(i8* %33, i8* %34, i32 2)
store i8* %35, i8** %10
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%37 = load i8*, i8** %9
%38 = load i8*, i8** %10
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %36, i8* %37, i8* %38)
ret i32 0
}

LLVM IR (-O2):
@__const.main.arr = [20 x i8] c"apple\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [5 x i8] c"pear\00"
@.str.1 = [19 x i8] c"arr=%s,p=%s,p2=%s\0A\00"
@.str.4 = [6 x i8] c"d:%d\0A\00"
@.str.5 = [20 x i8] c"strcmp(pc, pc2):%d\0A\00"
@.str.6 = [20 x i8] c"strcmp(pc2, pc):%d\0A\00"
@.str.7 = [20 x i8] c"strcmp(pc, pc3):%d\0A\00"
@__const.main.a = [10 x i8] c"apple\00\00\00\00\00"
@.str.8 = [19 x i8] c"a=%s,pt=%s,pt2=%s\0A\00"
define i32 @main() {
%1 = alloca [20 x i8]
%2 = alloca [10 x i8]
%3 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%4 = call i64 @strlen(i8* %3)
%5 = getelementptr [20 x i8], [20 x i8]* %1, i64 0, i64 %4
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %3)
%7 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i32 100)
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0), i32 -1)
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.6, i64 0, i64 0), i32 1)
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i32 0)
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %2, i64 0, i64 0
%12 = call i8* @strncat(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 2)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %12)
ret i32 0
}