#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 */
char *strchr(char *, char);
int strlen(char *);
void replace_semicolons_with_hashes(char *s) {
  char *p;
  if (!s)
    return;
  while ((p = strchr(s, ';')))
    *p = '#';
  p = s + strlen(s) - 1;
  if (*p == '#')
    *p = '\0';
}


x86 assembly (clang, -O0):
<replace_semicolons_with_hashes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    113c <replace_semicolons_with_hashes+0x1c>
jmp    11a5 <replace_semicolons_with_hashes+0x85>
jmp    1141 <replace_semicolons_with_hashes+0x21>
mov    -0x8(%rbp),%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1169 <replace_semicolons_with_hashes+0x49>
mov    -0x10(%rbp),%rax
movb   $0x23,(%rax)
jmp    1141 <replace_semicolons_with_hashes+0x21>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x23,%eax
jne    11a5 <replace_semicolons_with_hashes+0x85>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_semicolons_with_hashes>:
push   %rbx
test   %rdi,%rdi
je     115d <replace_semicolons_with_hashes+0x3d>
mov    %rdi,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x3b,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1147 <replace_semicolons_with_hashes+0x27>
movb   $0x23,(%rax)
jmp    1130 <replace_semicolons_with_hashes+0x10>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0x23,-0x1(%rbx,%rax,1)
jne    115d <replace_semicolons_with_hashes+0x3d>
movb   $0x0,-0x1(%rbx,%rax,1)
pop    %rbx
ret

LLVM IR (-O0):
define void @replace_semicolons_with_hashes(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp ne i8* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
br label %27
7: ; preds = %1
br label %8
8: ; preds = %12, %7
%9 = load i8*, i8** %2
%10 = call i8* @strchr(i8* %9, i8 signext 59)
store i8* %10, i8** %3
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = load i8*, i8** %3
store i8 35, i8* %13
br label %8
14: ; preds = %8
%15 = load i8*, i8** %2
%16 = load i8*, i8** %2
%17 = call i32 @strlen(i8* %16)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %15, i64 %18
%20 = getelementptr inbounds i8, i8* %19, i64 -1
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 35
br i1 %24, label %25, label %27
25: ; preds = %14
%26 = load i8*, i8** %3
store i8 0, i8* %26
br label %27
27: ; preds = %6, %25, %14
ret void
}

LLVM IR (-O2):
define void @replace_semicolons_with_hashes(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %18, label %3
3: ; preds = %1
%4 = tail call i8* @strchr(i8* %0, i8 signext 59)
%5 = icmp eq i8* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3, %6
%7 = phi i8* [ %8, %6 ], [ %4, %3 ]
store i8 35, i8* %7
%8 = tail call i8* @strchr(i8* %0, i8 signext 59)
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %6
10: ; preds = %6, %3
%11 = tail call i32 @strlen(i8* %0)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -1
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 35
br i1 %16, label %17, label %18
17: ; preds = %10
store i8 0, i8* %14
br label %18
18: ; preds = %10, %17, %1
ret void
}