#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 *);
void replace_str(char *, char *, char *, int);
int strlen(char *);
void strrepstr(char *str, int str_buff_len, char *from, char *to) {
  int from_len;
  int to_len;
  if (str == NULL || from == NULL || to == NULL)
    return;
  from_len = strlen(from);
  to_len = strlen(to);
  if (from_len == to_len)
    return replace_str(str, from, to, from_len);
  printf("TODO\n");
}


x86 assembly (clang, -O0):
<strrepstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1168 <strrepstr+0x38>
cmpq   $0x0,-0x18(%rbp)
je     1168 <strrepstr+0x38>
cmpq   $0x0,-0x20(%rbp)
jne    116d <strrepstr+0x3d>
jmp    11b6 <strrepstr+0x86>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jne    11aa <strrepstr+0x7a>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1050 <replace_str@plt>
jmp    11b6 <strrepstr+0x86>
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strrepstr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     117f <strrepstr+0x4f>
mov    %rdx,%rbx
test   %rdx,%rdx
je     117f <strrepstr+0x4f>
mov    %rcx,%r14
test   %rcx,%rcx
je     117f <strrepstr+0x4f>
mov    %rdi,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <strlen@plt>
cmp    %eax,%ebp
jne    118a <strrepstr+0x5a>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <replace_str@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe6f(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"TODO\0A\00"
define void @strrepstr(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %19, label %13
13: ; preds = %4
%14 = load i8*, i8** %7
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i8*, i8** %8
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %20
19: ; preds = %16, %13, %4
br label %35
20: ; preds = %16
%21 = load i8*, i8** %7
%22 = call i32 @strlen(i8* %21)
store i32 %22, i32* %9
%23 = load i8*, i8** %8
%24 = call i32 @strlen(i8* %23)
store i32 %24, i32* %10
%25 = load i32, i32* %9
%26 = load i32, i32* %10
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load i8*, i8** %5
%30 = load i8*, i8** %7
%31 = load i8*, i8** %8
%32 = load i32, i32* %9
br label %35
33: ; preds = %20
%34 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %28, %19
ret void
}

LLVM IR (-O2):
@str = [5 x i8] c"TODO\00"
define void @strrepstr(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %0, null
%6 = icmp eq i8* %2, null
%7 = or i1 %5, %6
%8 = icmp eq i8* %3, null
%9 = or i1 %7, %8
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = tail call i32 @strlen(i8* %2)
%12 = tail call i32 @strlen(i8* %3)
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %15
14: ; preds = %10
tail call void @replace_str(i8* %0, i8* %2, i8* %3, i32 %11)
br label %17
15: ; preds = %10
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
br label %17
17: ; preds = %4, %15, %14
ret void
}