#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*/ errorf(char *, int, char *);
char *format(char *, char *);
int strlen(char *);
char *replace_suffix(char *filename, char suffix) {
  char *r = format("%s", filename);
  char *p = r + strlen(r) - 1;
  if (*p != 'c')
    errorf("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/zhuzhaoyuan/8cc/refs/heads/master/main.c",
           59, "filename suffix is not .c");
  *p = suffix;
  return r;
}


x86 assembly (clang, -O0):
<replace_suffix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xeb3(%rip),%rdi
call   1050 <format@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x63,%eax
je     11a3 <replace_suffix+0x73>
lea    0xe71(%rip),%rdi
mov    $0x3b,%esi
lea    0xee8(%rip),%rdx
call   1040 <errorf@plt>
mov    -0x9(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_suffix>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rsi
lea    0xebf(%rip),%rdi
call   1050 <format@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1030 <strlen@plt>
movslq %eax,%rbp
cmpb   $0x63,-0x1(%rbx,%rbp,1)
je     1173 <replace_suffix+0x43>
lea    0xea1(%rip),%rdi
lea    0xf1d(%rip),%rdx
mov    $0x3b,%esi
call   1040 <errorf@plt>
mov    %r14b,-0x1(%rbx,%rbp,1)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhuzhaoyuan/8cc/refs/heads/master/main.c\00"
@.str.2 = [26 x i8] c"filename suffix is not .c\00"
define i8* @replace_suffix(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8 %1, i8* %4
%7 = load i8*, i8** %3
%8 = call i8* @format(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %7)
store i8* %8, i8** %5
%9 = load i8*, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %9, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -1
store i8* %14, i8** %6
%15 = load i8*, i8** %6
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 99
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @errorf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %21
21: ; preds = %19, %2
%22 = load i8, i8* %4
%23 = load i8*, i8** %6
store i8 %22, i8* %23
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [131 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/zhuzhaoyuan/8cc/refs/heads/master/main.c\00"
@.str.2 = [26 x i8] c"filename suffix is not .c\00"
define i8* @replace_suffix(i8* %0, i8 signext %1) {
%3 = tail call i8* @format(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = tail call i32 @strlen(i8* %3)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds i8, i8* %3, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 99
br i1 %9, label %12, label %10
10: ; preds = %2
%11 = tail call i32 @errorf(i8* getelementptr inbounds ([131 x i8], [131 x i8]* @.str.1, i64 0, i64 0), i32 59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
store i8 %1, i8* %7
ret i8* %3
}