#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
char *str_sub(const char *s, int start, int end) {
  char *new_s = NULL;
  if (s != NULL && start <= end) {
    new_s = malloc(sizeof(*new_s) * (end - start + 2));
    if (new_s != NULL) {
      int i;
      for (i = start; i <= end; i++) {
        new_s[i - start] = s[i];
      }
      new_s[i - start] = '\0';
    } else {
      fprintf(stderr, "Memoire insuffisante\n");
      exit(EXIT_FAILURE);
    }
  }
  return new_s;
}


x86 assembly (clang, -O0):
<str_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11ff <str_sub+0xcf>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11ff <str_sub+0xcf>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d7 <str_sub+0xa7>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jg     11c1 <str_sub+0x91>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    118c <str_sub+0x5c>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    -0xc(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11fa <str_sub+0xca>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    11ff <str_sub+0xcf>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_sub>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %r14d,%r14d
test   %rdi,%rdi
je     118a <str_sub+0x4a>
mov    %edx,%ebx
mov    %esi,%ebp
sub    %esi,%ebx
jl     118a <str_sub+0x4a>
mov    %rdi,%r15
lea    0x2(%rbx),%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1198 <str_sub+0x58>
mov    %rax,%r14
movslq %ebp,%rax
add    %rax,%r15
lea    0x1(%rbx),%rdx
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <memcpy@plt>
add    $0x1,%ebx
movslq %ebx,%rax
movb   $0x0,(%r14,%rax,1)
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Memoire insuffisante\0A\00"
@EXIT_FAILURE = global i32 0
define i8* @str_sub(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8* null, i8** %7
%9 = load i8*, i8** %4
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %60
11: ; preds = %3
%12 = load i32, i32* %5
%13 = load i32, i32* %6
%14 = icmp sle i32 %12, %13
br i1 %14, label %15, label %60
15: ; preds = %11
%16 = load i32, i32* %6
%17 = load i32, i32* %5
%18 = sub nsw i32 %16, %17
%19 = add nsw i32 %18, 2
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %7
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %54
26: ; preds = %15
%27 = load i32, i32* %5
store i32 %27, i32* %8
br label %28
28: ; preds = %44, %26
%29 = load i32, i32* %8
%30 = load i32, i32* %6
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
%33 = load i8*, i8** %4
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i8*, i8** %7
%39 = load i32, i32* %8
%40 = load i32, i32* %5
%41 = sub nsw i32 %39, %40
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %38, i64 %42
store i8 %37, i8* %43
br label %44
44: ; preds = %32
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %28
47: ; preds = %28
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = load i32, i32* %5
%51 = sub nsw i32 %49, %50
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %48, i64 %52
store i8 0, i8* %53
br label %59
54: ; preds = %15
%55 = load i32, i32* @stderr
%56 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %47
br label %60
60: ; preds = %59, %11, %3
%61 = load i8*, i8** %7
ret i8* %61
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Memoire insuffisante\0A\00"
@EXIT_FAILURE = global i32 0
define noalias i8* @str_sub(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i8* %0, null
%5 = icmp slt i32 %2, %1
%6 = or i1 %4, %5
br i1 %6, label %27, label %7
7: ; preds = %3
%8 = sub i32 2, %1
%9 = add i32 %8, %2
%10 = tail call i8* @malloc(i32 %9)
%11 = icmp eq i8* %10, null
br i1 %11, label %22, label %12
12: ; preds = %7
%13 = sext i32 %1 to i64
%14 = getelementptr i8, i8* %0, i64 %13
%15 = sub i32 %2, %1
%16 = zext i32 %15 to i64
%17 = add nuw nsw i64 %16, 1
%18 = add i32 %2, 1
%19 = sub nsw i32 %18, %1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %10, i64 %20
store i8 0, i8* %21
br label %27
22: ; preds = %7
%23 = load i32, i32* @stderr
%24 = tail call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = tail call i32 @exit(i32 %25)
unreachable
27: ; preds = %12, %3
%28 = phi i8* [ %10, %12 ], [ null, %3 ]
ret i8* %28
}