#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 */
scalar_t__ malloc(int);
int my_strcmp(char *, char *);
int /*<<< orphan*/ my_strcpy(char *, char *);
int my_strlen(char *);
int /*<<< orphan*/ printf(char *, ...);
int main() {
  char *s1 = "slack";
  int len = my_strlen(s1);
  printf("my_strlen(): %s is %d characters long.\n", s1, len);
  char *s2 = "short";
  char *s3 = "super long";
  char *s4 = "slack";
  int cmp1 = my_strcmp(s1, s2);
  int cmp2 = my_strcmp(s2, s3);
  int cmp3 = my_strcmp(s1, s4);
  printf("my_strcmp(): after: %d, before: %d, and equal: %d\n", cmp1, cmp2,
         cmp3);
  char *s5 = (char *)malloc(my_strlen(s3) + my_strlen(s1) + 2);
  my_strcpy(s5, s3);
  s5[my_strlen(s3)] = ' ';
  my_strcpy(s5 + my_strlen(s3) + 1, s1);
  printf("%s\n", s5);
  char s6[my_strlen(s5)];
  my_strcpy(s6, s5);
  printf("%s\n", s6);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe9e(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe82(%rip),%rdi
xor    %eax,%eax
mov    %al,-0x59(%rbp)
call   1060 <printf@plt>
mov    -0x80(%rbp),%rax
lea    0xe95(%rip),%rcx
mov    %rcx,-0x18(%rbp)
lea    0xe90(%rip),%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <my_strcmp@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <my_strcmp@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <my_strcmp@plt>
mov    %eax,%ecx
mov    -0x59(%rbp),%al
mov    %ecx,-0x34(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
lea    0xe4e(%rip),%rdi
call   1060 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    -0x74(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x2(%rax,%rcx,1),%edi
call   1070 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <my_strcpy@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
lea    0x1(%rax,%rcx,1),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <my_strcpy@plt>
mov    -0x59(%rbp),%al
mov    -0x40(%rbp),%rsi
lea    0xdf0(%rip),%rdi
call   1060 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <my_strlen@plt>
mov    %eax,%eax
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x40(%rbp),%rsi
call   1050 <my_strcpy@plt>
mov    -0x58(%rbp),%rsi
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
xor    %eax,%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe8b(%rip),%r14
mov    %r14,%rdi
call   1030 <my_strlen@plt>
lea    0xe82(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe97(%rip),%r12
mov    %r14,%rdi
mov    %r12,%rsi
call   1040 <my_strcmp@plt>
mov    %eax,%r13d
lea    0xe88(%rip),%r15
mov    %r12,%rdi
mov    %r15,%rsi
call   1040 <my_strcmp@plt>
mov    %eax,%ebx
mov    %r14,%rdi
mov    %r14,%rsi
call   1040 <my_strcmp@plt>
lea    0xe74(%rip),%rdi
mov    %r13d,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r15,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1030 <my_strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1050 <my_strcpy@plt>
mov    %r15,%rdi
call   1030 <my_strlen@plt>
cltq
movb   $0x20,(%r12,%rax,1)
mov    %r15,%rdi
call   1030 <my_strlen@plt>
cltq
lea    (%r12,%rax,1),%rdi
add    $0x1,%rdi
mov    %r14,%rsi
call   1050 <my_strcpy@plt>
mov    %r12,%rdi
call   1060 <puts@plt>
mov    %r12,%rdi
call   1030 <my_strlen@plt>
mov    %eax,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <my_strcpy@plt>
mov    %rbx,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"slack\00"
@.str.1 = [40 x i8] c"my_strlen(): %s is %d characters long.\0A\00"
@.str.2 = [6 x i8] c"short\00"
@.str.3 = [11 x i8] c"super long\00"
@.str.4 = [51 x i8] c"my_strcmp(): after: %d, before: %d, and equal: %d\0A\00"
@.str.5 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %1
%12 = load i8*, i8** %1
%13 = call i32 @my_strlen(i8* %12)
store i32 %13, i32* %2
%14 = load i8*, i8** %1
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15)
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i8** %4
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %5
%17 = load i8*, i8** %1
%18 = load i8*, i8** %3
%19 = call i32 @my_strcmp(i8* %17, i8* %18)
store i32 %19, i32* %6
%20 = load i8*, i8** %3
%21 = load i8*, i8** %4
%22 = call i32 @my_strcmp(i8* %20, i8* %21)
store i32 %22, i32* %7
%23 = load i8*, i8** %1
%24 = load i8*, i8** %5
%25 = call i32 @my_strcmp(i8* %23, i8* %24)
store i32 %25, i32* %8
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %26, i32 %27, i32 %28)
%30 = load i8*, i8** %4
%31 = call i32 @my_strlen(i8* %30)
%32 = load i8*, i8** %1
%33 = call i32 @my_strlen(i8* %32)
%34 = add nsw i32 %31, %33
%35 = add nsw i32 %34, 2
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %9
%38 = load i8*, i8** %9
%39 = load i8*, i8** %4
%40 = call i32 @my_strcpy(i8* %38, i8* %39)
%41 = load i8*, i8** %9
%42 = load i8*, i8** %4
%43 = call i32 @my_strlen(i8* %42)
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8, i8* %41, i64 %44
store i8 32, i8* %45
%46 = load i8*, i8** %9
%47 = load i8*, i8** %4
%48 = call i32 @my_strlen(i8* %47)
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %46, i64 %49
%51 = getelementptr inbounds i8, i8* %50, i64 1
%52 = load i8*, i8** %1
%53 = call i32 @my_strcpy(i8* %51, i8* %52)
%54 = load i8*, i8** %9
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %54)
%56 = load i8*, i8** %9
%57 = call i32 @my_strlen(i8* %56)
%58 = zext i32 %57 to i64
%59 = call i8* @llvm.stacksave()
store i8* %59, i8** %10
%60 = alloca i8, i64 %58
store i64 %58, i64* %11
%61 = load i8*, i8** %9
%62 = call i32 @my_strcpy(i8* %60, i8* %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %60)
%64 = load i8*, i8** %10
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"slack\00"
@.str.1 = [40 x i8] c"my_strlen(): %s is %d characters long.\0A\00"
@.str.2 = [6 x i8] c"short\00"
@.str.3 = [11 x i8] c"super long\00"
@.str.4 = [51 x i8] c"my_strcmp(): after: %d, before: %d, and equal: %d\0A\00"
define i32 @main() {
%1 = tail call i32 @my_strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @my_strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i32 @my_strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%5 = tail call i32 @my_strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.4, i64 0, i64 0), i32 %3, i32 %4, i32 %5)
%7 = tail call i32 @my_strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%8 = tail call i32 @my_strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%9 = add i32 %7, 2
%10 = add i32 %9, %8
%11 = tail call i64 @malloc(i32 %10)
%12 = inttoptr i64 %11 to i8*
%13 = tail call i32 @my_strcpy(i8* %12, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%14 = tail call i32 @my_strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
store i8 32, i8* %16
%17 = tail call i32 @my_strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %12, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = tail call i32 @my_strcpy(i8* %20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) %12)
%23 = tail call i32 @my_strlen(i8* %12)
%24 = zext i32 %23 to i64
%25 = alloca i8, i64 %24
%26 = call i32 @my_strcpy(i8* %25, i8* %12)
%27 = call i32 @puts(i8* %25)
ret i32 0
}