#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 int_max(int /*<<< orphan*/, int);
int int_min(int, int);
char *mk_copy_string(char *);
char *mk_substring(char *, int, int);
scalar_t__ strlen(char *);
char *mk_friendly_substring(char *s, int start, int end) {
  char *result;
  start = int_max(0, start);
  end = int_min((int)strlen(s), end);
  if (end <= start)
    result = mk_copy_string("");
  else
    result = mk_substring(s, start, end);
  return result;
}


x86 assembly (clang, -O0):
<mk_friendly_substring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%esi
xor    %edi,%edi
call   1030 <int_max@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%esi
call   1070 <int_min@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11a6 <mk_friendly_substring+0x56>
lea    0xe68(%rip),%rdi
call   1060 <mk_copy_string@plt>
mov    %rax,-0x18(%rbp)
jmp    11b9 <mk_friendly_substring+0x69>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <mk_substring@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mk_friendly_substring>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rdi,%rbx
xor    %edi,%edi
call   1030 <int_max@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1070 <int_min@plt>
cmp    %ebp,%eax
jle    1189 <mk_friendly_substring+0x39>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <mk_substring@plt>
lea    0xe70(%rip),%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1060 <mk_copy_string@plt>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @mk_friendly_substring(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = call i32 @int_max(i32 0, i32 %8)
store i32 %9, i32* %5
%10 = load i8*, i8** %4
%11 = call i64 @strlen(i8* %10)
%12 = trunc i64 %11 to i32
%13 = load i32, i32* %6
%14 = call i32 @int_min(i32 %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* %5
%17 = icmp sle i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %3
%19 = call i8* @mk_copy_string(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %7
br label %25
20: ; preds = %3
%21 = load i8*, i8** %4
%22 = load i32, i32* %5
%23 = load i32, i32* %6
%24 = call i8* @mk_substring(i8* %21, i32 %22, i32 %23)
store i8* %24, i8** %7
br label %25
25: ; preds = %20, %18
%26 = load i8*, i8** %7
ret i8* %26
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
define i8* @mk_friendly_substring(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @int_max(i32 0, i32 %1)
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = trunc i64 %5 to i32
%7 = tail call i32 @int_min(i32 %6, i32 %2)
%8 = icmp sgt i32 %7, %4
br i1 %8, label %11, label %9
9: ; preds = %3
%10 = tail call i8* @mk_copy_string(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %13
11: ; preds = %3
%12 = tail call i8* @mk_substring(i8* %0, i32 %4, i32 %7)
br label %13
13: ; preds = %11, %9
%14 = phi i8* [ %10, %9 ], [ %12, %11 ]
ret i8* %14
}