#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*/ replace_link(char *, int, int, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int test_replace_link() {
  char line[(1024 * 256)];
  int start = 23, end = 25;
  char *link_str = "https://somedomain.net";
  sprintf(line, "%s", "This is a [Replacement][1] test.");
  if (line[start] != '[')
    return 1;
  if (line[end] != ']')
    return 2;
  replace_link(line, start, end, link_str);
  if (strcmp(line, "This is a [Replacement](https://somedomain.net) test.") !=
      0)
    return 3;
  return 0;
}


x86 assembly (clang, -O0):
<test_replace_link>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40020,%rsp
movl   $0x17,-0x40014(%rbp)
movl   $0x19,-0x40018(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x40020(%rbp)
lea    -0x40010(%rbp),%rdi
lea    0xeac(%rip),%rsi
lea    0xea8(%rip),%rdx
call   1050 <sprintf@plt>
movslq -0x40014(%rbp),%rax
movsbl -0x40010(%rbp,%rax,1),%eax
ff
cmp    $0x5b,%eax
je     119b <test_replace_link+0x6b>
movl   $0x1,-0x4(%rbp)
jmp    120e <test_replace_link+0xde>
movslq -0x40018(%rbp),%rax
movsbl -0x40010(%rbp,%rax,1),%eax
ff
cmp    $0x5d,%eax
je     11bf <test_replace_link+0x8f>
movl   $0x2,-0x4(%rbp)
jmp    120e <test_replace_link+0xde>
lea    -0x40010(%rbp),%rdi
mov    -0x40014(%rbp),%esi
mov    -0x40018(%rbp),%edx
mov    -0x40020(%rbp),%rcx
call   1030 <replace_link@plt>
lea    -0x40010(%rbp),%rdi
lea    0xe4f(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     1207 <test_replace_link+0xd7>
movl   $0x3,-0x4(%rbp)
jmp    120e <test_replace_link+0xde>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_replace_link>:
push   %rbx
sub    $0x40000,%rsp
movups 0xef8(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movups 0xedc(%rip),%xmm0
movaps %xmm0,(%rsp)
movb   $0x0,0x20(%rsp)
lea    0xeb5(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x17,%esi
mov    $0x19,%edx
call   1030 <replace_link@plt>
lea    0xed1(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,2),%eax
add    $0x40000,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [23 x i8] c"https://somedomain.net\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [33 x i8] c"This is a [Replacement][1] test.\00"
@.str.3 = [54 x i8] c"This is a [Replacement](https://somedomain.net) test.\00"
define i32 @test_replace_link() {
%1 = alloca i32
%2 = alloca [262144 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 23, i32* %3
store i32 25, i32* %4
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %5
%6 = getelementptr inbounds [262144 x i8], [262144 x i8]* %2, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
%8 = load i32, i32* %3
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [262144 x i8], [262144 x i8]* %2, i64 0, i64 %9
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 91
br i1 %13, label %14, label %15
14: ; preds = %0
store i32 1, i32* %1
br label %34
15: ; preds = %0
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [262144 x i8], [262144 x i8]* %2, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 93
br i1 %21, label %22, label %23
22: ; preds = %15
store i32 2, i32* %1
br label %34
23: ; preds = %15
%24 = getelementptr inbounds [262144 x i8], [262144 x i8]* %2, i64 0, i64 0
%25 = load i32, i32* %3
%26 = load i32, i32* %4
%27 = load i8*, i8** %5
%28 = call i32 @replace_link(i8* %24, i32 %25, i32 %26, i8* %27)
%29 = getelementptr inbounds [262144 x i8], [262144 x i8]* %2, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %23
store i32 3, i32* %1
br label %34
33: ; preds = %23
store i32 0, i32* %1
br label %34
34: ; preds = %33, %32, %22, %14
%35 = load i32, i32* %1
ret i32 %35
}

LLVM IR (-O2):
@.str = [23 x i8] c"https://somedomain.net\00"
@.str.2 = [33 x i8] c"This is a [Replacement][1] test.\00"
@.str.3 = [54 x i8] c"This is a [Replacement](https://somedomain.net) test.\00"
define i32 @test_replace_link() {
%1 = alloca [262144 x i8]
%2 = getelementptr inbounds [262144 x i8], [262144 x i8]* %1, i64 0, i64 0
%3 = call i32 @replace_link(i8* %2, i32 23, i32 25, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @strcmp(i8* %2, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.3, i64 0, i64 0))
%5 = icmp eq i64 %4, 0
%6 = select i1 %5, i32 0, i32 3
ret i32 %6
}