#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 *);
int /*<<< orphan*/ puts(char *);
char *substring(char *, int, int);
int main() {
  printf("substring of 'hello'(1,3) is %s\n", substring("hello", 1, 3));
  printf("substring of 'world'(0,4) is %s\n", substring("world", 0, 4));
  if (substring("blah", 5, 4) == NULL)
    puts("pass 3");
  if (substring("blah", 4, 4) == NULL)
    puts("pass 4");
  if (substring(NULL, 1, 2) == NULL)
    puts("pass 5");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xedb(%rip),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <substring@plt>
mov    %rax,%rsi
lea    0xea1(%rip),%rdi
call   1040 <printf@plt>
lea    0xedd(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <substring@plt>
mov    %rax,%rsi
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
lea    0xec1(%rip),%rdi
mov    $0x5,%esi
mov    $0x4,%edx
call   1050 <substring@plt>
cmp    $0x0,%rax
jne    11b2 <main+0x82>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
lea    0xe95(%rip),%rdi
mov    $0x4,%edx
mov    %edx,%esi
call   1050 <substring@plt>
cmp    $0x0,%rax
jne    11db <main+0xab>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <substring@plt>
cmp    $0x0,%rax
jne    1204 <main+0xd4>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
lea    0xee9(%rip),%rdi
mov    $0x1,%esi
mov    $0x3,%edx
call   1050 <substring@plt>
lea    0xeb2(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xeeb(%rip),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <substring@plt>
lea    0xeb7(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
lea    0xecf(%rip),%rdi
mov    $0x5,%esi
mov    $0x4,%edx
call   1050 <substring@plt>
test   %rax,%rax
jne    119f <main+0x6f>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
lea    0xea8(%rip),%rdi
mov    $0x4,%esi
mov    $0x4,%edx
call   1050 <substring@plt>
test   %rax,%rax
jne    11c6 <main+0x96>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
mov    $0x1,%esi
mov    $0x2,%edx
call   1050 <substring@plt>
test   %rax,%rax
jne    11e8 <main+0xb8>
lea    0xe7e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [33 x i8] c"substring of 'hello'(1,3) is %s\0A\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [33 x i8] c"substring of 'world'(0,4) is %s\0A\00"
@.str.3 = [6 x i8] c"world\00"
@.str.4 = [5 x i8] c"blah\00"
@.str.5 = [7 x i8] c"pass 3\00"
@.str.6 = [7 x i8] c"pass 4\00"
@.str.7 = [7 x i8] c"pass 5\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i8* @substring(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 3)
%3 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i8* @substring(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 4)
%5 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%6 = call i8* @substring(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 5, i32 4)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = call i8* @substring(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4, i32 4)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %15
15: ; preds = %13, %10
%16 = call i8* @substring(i8* null, i32 1, i32 2)
%17 = icmp eq i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"substring of 'hello'(1,3) is %s\0A\00"
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [33 x i8] c"substring of 'world'(0,4) is %s\0A\00"
@.str.3 = [6 x i8] c"world\00"
@.str.4 = [5 x i8] c"blah\00"
@.str.5 = [7 x i8] c"pass 3\00"
@.str.6 = [7 x i8] c"pass 4\00"
@.str.7 = [7 x i8] c"pass 5\00"
define i32 @main() {
%1 = tail call i8* @substring(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 1, i32 3)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %1)
%3 = tail call i8* @substring(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i32 0, i32 4)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %3)
%5 = tail call i8* @substring(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 5, i32 4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = tail call i8* @substring(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 4, i32 4)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %14
14: ; preds = %12, %9
%15 = tail call i8* @substring(i8* null, i32 1, i32 2)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
br label %19
19: ; preds = %17, %14
ret i32 0
}