#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*/ assert_failed(char *, int);
void string_replace_leading(char *str, const char match, const char replace) {
  do {
    if (!(match != '\0'))
      assert_failed("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/Bytewerk/uClinux-ipcam/"
                    "refs/heads/master/buffer.c",
                    823);
  } while (0);
  while (*str) {
    if (*str == match)
      *str = replace;
    else
      break;
    ++str;
  }
}


x86 assembly (clang, -O0):
<string_replace_leading>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %dl,%al
mov    %sil,%cl
mov    %rdi,-0x8(%rbp)
mov    %cl,-0x9(%rbp)
mov    %al,-0xa(%rbp)
movsbl -0x9(%rbp),%eax
cmp    $0x0,%eax
jne    1145 <string_replace_leading+0x35>
lea    0xec5(%rip),%rdi
mov    $0x337,%esi
call   1030 <assert_failed@plt>
jmp    114a <string_replace_leading+0x3a>
jmp    114f <string_replace_leading+0x3f>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     1193 <string_replace_leading+0x83>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    117d <string_replace_leading+0x6d>
mov    -0xa(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
jmp    1182 <string_replace_leading+0x72>
jmp    1193 <string_replace_leading+0x83>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    114f <string_replace_leading+0x3f>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<string_replace_leading>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
mov    %rdi,%rbx
test   %bpl,%bpl
jne    1132 <string_replace_leading+0x22>
lea    0xed8(%rip),%rdi
mov    $0x337,%esi
call   1030 <assert_failed@plt>
mov    (%rbx),%al
test   %al,%al
je     1164 <string_replace_leading+0x54>
cmp    %bpl,%al
jne    1164 <string_replace_leading+0x54>
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14b,-0x1(%rbx)
movzbl (%rbx),%eax
test   %al,%al
je     1164 <string_replace_leading+0x54>
add    $0x1,%rbx
cmp    %bpl,%al
je     1150 <string_replace_leading+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Bytewerk/uClinux-ipcam/refs/heads/master/buffer.c\00"
define void @string_replace_leading(i8* %0, i8 signext %1, i8 signext %2) {
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8
store i8* %0, i8** %4
store i8 %1, i8* %5
store i8 %2, i8* %6
br label %7
7: ; preds = %3
%8 = load i8, i8* %5
%9 = sext i8 %8 to i32
%10 = icmp ne i32 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = call i32 @assert_failed(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 823)
br label %13
13: ; preds = %11, %7
br label %14
14: ; preds = %13
br label %15
15: ; preds = %30, %14
%16 = load i8*, i8** %4
%17 = load i8, i8* %16
%18 = icmp ne i8 %17, 0
br i1 %18, label %19, label %33
19: ; preds = %15
%20 = load i8*, i8** %4
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %29
26: ; preds = %19
%27 = load i8, i8* %6
%28 = load i8*, i8** %4
store i8 %27, i8* %28
br label %30
29: ; preds = %19
br label %33
30: ; preds = %26
%31 = load i8*, i8** %4
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %4
br label %15
33: ; preds = %29, %15
ret void
}

LLVM IR (-O2):
@.str = [140 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Bytewerk/uClinux-ipcam/refs/heads/master/buffer.c\00"
define void @string_replace_leading(i8* nocapture %0, i8 signext %1, i8 signext %2) {
%4 = icmp eq i8 %1, 0
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @assert_failed(i8* getelementptr inbounds ([140 x i8], [140 x i8]* @.str, i64 0, i64 0), i32 823)
br label %7
7: ; preds = %3, %5
%8 = load i8, i8* %0
%9 = icmp ne i8 %8, 0
%10 = icmp eq i8 %8, %1
%11 = and i1 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %7, %12
%13 = phi i8* [ %14, %12 ], [ %0, %7 ]
store i8 %2, i8* %13
%14 = getelementptr inbounds i8, i8* %13, i64 1
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 0
%17 = icmp eq i8 %15, %1
%18 = and i1 %16, %17
br i1 %18, label %12, label %19
19: ; preds = %12, %7
ret void
}