#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*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
size_t strlen(char *);
void replace_last_parenthesis_with_0(char *buf, int start) {
  size_t i;
  const size_t len = strlen(buf);
  for (i = start; i < len; i++) {
    if (')' == buf[i]) {
      buf[i] = 0;
      return;
    }
  }
  fprintf(stderr, "ERROR: Malformed test-case '%s'", buf);
}


x86 assembly (clang, -O0):
<replace_last_parenthesis_with_0>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x20(%rbp)
movslq -0xc(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1192 <replace_last_parenthesis_with_0+0x72>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%ecx
mov    $0x29,%eax
cmp    %ecx,%eax
jne    117c <replace_last_parenthesis_with_0+0x5c>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    11ab <replace_last_parenthesis_with_0+0x8b>
jmp    1181 <replace_last_parenthesis_with_0+0x61>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1144 <replace_last_parenthesis_with_0+0x24>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe5a(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_last_parenthesis_with_0>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <strlen@plt>
movslq %ebp,%rcx
cmp    %rcx,%rax
jbe    114f <replace_last_parenthesis_with_0+0x2f>
cs nopw 0x0(%rax,%rax,1)
nop
cmpb   $0x29,(%rbx,%rcx,1)
je     116d <replace_last_parenthesis_with_0+0x4d>
add    $0x1,%rcx
cmp    %rcx,%rax
jne    1140 <replace_last_parenthesis_with_0+0x20>
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
lea    0xea1(%rip),%rsi
mov    %rbx,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <fprintf@plt>
movb   $0x0,(%rbx,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [32 x i8] c"ERROR: Malformed test-case '%s'\00"
define void @replace_last_parenthesis_with_0(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
store i64 %8, i64* %6
%9 = load i32, i32* %4
%10 = sext i32 %9 to i64
store i64 %10, i64* %5
br label %11
11: ; preds = %27, %2
%12 = load i64, i64* %5
%13 = load i64, i64* %6
%14 = icmp ult i64 %12, %13
br i1 %14, label %15, label %30
15: ; preds = %11
%16 = load i8*, i8** %3
%17 = load i64, i64* %5
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 41, %20
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = load i8*, i8** %3
%24 = load i64, i64* %5
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
br label %34
26: ; preds = %15
br label %27
27: ; preds = %26
%28 = load i64, i64* %5
%29 = add i64 %28, 1
store i64 %29, i64* %5
br label %11
30: ; preds = %11
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %3
%33 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %30, %22
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [32 x i8] c"ERROR: Malformed test-case '%s'\00"
define void @replace_last_parenthesis_with_0(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = sext i32 %1 to i64
%5 = icmp ugt i64 %3, %4
br i1 %5, label %6, label %16
6: ; preds = %2, %13
%7 = phi i64 [ %14, %13 ], [ %4, %2 ]
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 41
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = getelementptr inbounds i8, i8* %0, i64 %7
store i8 0, i8* %12
br label %19
13: ; preds = %6
%14 = add i64 %7, 1
%15 = icmp eq i64 %14, %3
br i1 %15, label %16, label %6
16: ; preds = %13, %2
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %19
19: ; preds = %16, %11
ret void
}