#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 */
char *buf1(char *, int);
char *buf2(char *, int);
int index(char *, char *);
int /*<<< orphan*/ print_text(char *);
int /*<<< orphan*/ printf(char *, ...);
char *ptr(char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main() {
  char *text = "Mary had a little lamb, its fleece was white as snow.";
  print_text(text);
  char *buffer1 = buf1(text, 14);
  char *buffer2 = buf2(text, 14);
  printf("Buffer1: %s \n", buffer1);
  printf("Buffer2: %s \n", buffer2);
  char *test = ptr("obsidian", 3);
  printf("Ptr: %s \n", test);
  char *foo = "obsidian";
  char *bar = foo + 3;
  char baz[4];
  strncpy(baz, foo, 3);
  baz[3] = 0;
  char middle[4];
  strncpy(middle, bar, 3);
  middle[3] = 0;
  int myindex = index(foo, bar);
  printf("Index: %d \n", myindex);
  printf("Foo: %s \n", foo);
  printf("Bar: %s \n", bar);
  printf("Baz: %s \n", baz);
  printf("Middle: %s \n", middle);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <print_text@plt>
mov    -0x10(%rbp),%rdi
mov    $0xe,%esi
call   1090 <buf1@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xe,%esi
call   1070 <buf2@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe70(%rip),%rdi
mov    $0x3,%esi
call   1080 <ptr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe49(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x38(%rbp)
lea    -0x3c(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x39(%rbp)
lea    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
movb   $0x0,-0x3d(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <index@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x3c(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe81(%rip),%rbx
mov    %rbx,%rdi
call   1030 <print_text@plt>
mov    %rbx,%rdi
mov    $0xe,%esi
call   1090 <buf1@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0xe,%esi
call   1070 <buf2@plt>
mov    %rax,%rbx
lea    0xe88(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe82(%rip),%r12
mov    %r12,%rdi
mov    $0x3,%esi
call   1080 <ptr@plt>
lea    0xe77(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x7(%rsp)
lea    0xe46(%rip),%rbx
mov    %rsp,%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1040 <strncpy@plt>
movb   $0x0,0x3(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
call   1060 <index@plt>
lea    0xe2c(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe21(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe1a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe13(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [54 x i8] c"Mary had a little lamb, its fleece was white as snow.\00"
@.str.1 = [14 x i8] c"Buffer1: %s \0A\00"
@.str.2 = [14 x i8] c"Buffer2: %s \0A\00"
@.str.3 = [9 x i8] c"obsidian\00"
@.str.4 = [10 x i8] c"Ptr: %s \0A\00"
@.str.5 = [12 x i8] c"Index: %d \0A\00"
@.str.6 = [10 x i8] c"Foo: %s \0A\00"
@.str.7 = [10 x i8] c"Bar: %s \0A\00"
@.str.8 = [10 x i8] c"Baz: %s \0A\00"
@.str.9 = [13 x i8] c"Middle: %s \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [4 x i8]
%9 = alloca [4 x i8]
%10 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8** %2
%11 = load i8*, i8** %2
%12 = call i32 @print_text(i8* %11)
%13 = load i8*, i8** %2
%14 = call i8* @buf1(i8* %13, i32 14)
store i8* %14, i8** %3
%15 = load i8*, i8** %2
%16 = call i8* @buf2(i8* %15, i32 14)
store i8* %16, i8** %4
%17 = load i8*, i8** %3
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = call i8* @ptr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 3)
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %22)
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8** %6
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 3
store i8* %25, i8** %7
%26 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%27 = load i8*, i8** %6
%28 = call i32 @strncpy(i8* %26, i8* %27, i32 3)
%29 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 3
store i8 0, i8* %29
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%31 = load i8*, i8** %7
%32 = call i32 @strncpy(i8* %30, i8* %31, i32 3)
%33 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 3
store i8 0, i8* %33
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i32 @index(i8* %34, i8* %35)
store i32 %36, i32* %10
%37 = load i32, i32* %10
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %6
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %39)
%41 = load i8*, i8** %7
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* %41)
%43 = getelementptr inbounds [4 x i8], [4 x i8]* %8, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %43)
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %9, i64 0, i64 0
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [54 x i8] c"Mary had a little lamb, its fleece was white as snow.\00"
@.str.1 = [14 x i8] c"Buffer1: %s \0A\00"
@.str.2 = [14 x i8] c"Buffer2: %s \0A\00"
@.str.3 = [9 x i8] c"obsidian\00"
@.str.4 = [10 x i8] c"Ptr: %s \0A\00"
@.str.5 = [12 x i8] c"Index: %d \0A\00"
@.str.6 = [10 x i8] c"Foo: %s \0A\00"
@.str.7 = [10 x i8] c"Bar: %s \0A\00"
@.str.8 = [10 x i8] c"Baz: %s \0A\00"
@.str.9 = [13 x i8] c"Middle: %s \0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = alloca [4 x i8]
%3 = tail call i32 @print_text(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0))
%4 = tail call i8* @buf1(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 14)
%5 = tail call i8* @buf2(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 14)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%8 = tail call i8* @ptr(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 3)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%10 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%11 = call i32 @strncpy(i8* %10, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i32 3)
%12 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 3
store i8 0, i8* %12
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%14 = call i32 @strncpy(i8* %13, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 3), i32 3)
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 3
store i8 0, i8* %15
%16 = call i32 @index(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 3))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 3))
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0), i8* %13)
ret i32 0
}