#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 */
scalar_t__ isprint(char);
char toupper(char);
char *replace_char_in_str(char *text_string, char letter) {
  int times = 0;
  int i = 0;
  while (isprint(text_string[i])) {
    if (text_string[i] == letter)
      text_string[i] = toupper(letter);
    i++;
  }
  return text_string;
}


x86 assembly (clang, -O0):
<replace_char_in_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isprint@plt>
cmp    $0x0,%rax
je     1197 <replace_char_in_str+0x77>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
jne    1189 <replace_char_in_str+0x69>
movsbl -0x9(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <replace_char_in_str+0x20>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<replace_char_in_str>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
movsbl (%rdi),%edi
call   1040 <isprint@plt>
test   %rax,%rax
je     1173 <replace_char_in_str+0x53>
movsbl %bpl,%r15d
mov    %r14,%rbx
jmp    1162 <replace_char_in_str+0x42>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1040 <isprint@plt>
test   %rax,%rax
je     1173 <replace_char_in_str+0x53>
cmp    %bpl,(%rbx)
jne    1150 <replace_char_in_str+0x30>
mov    %r15d,%edi
call   1030 <toupper@plt>
mov    %al,(%rbx)
jmp    1150 <replace_char_in_str+0x30>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @replace_char_in_str(i8* %0, i8 signext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %32, %2
%8 = load i8*, i8** %3
%9 = load i32, i32* %6
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = call i64 @isprint(i8 signext %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %35
15: ; preds = %7
%16 = load i8*, i8** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = load i8, i8* %4
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %32
25: ; preds = %15
%26 = load i8, i8* %4
%27 = call signext i8 @toupper(i8 signext %26)
%28 = load i8*, i8** %3
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
store i8 %27, i8* %31
br label %32
32: ; preds = %25, %15
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %7
35: ; preds = %7
%36 = load i8*, i8** %3
ret i8* %36
}

LLVM IR (-O2):
define i8* @replace_char_in_str(i8* returned %0, i8 signext %1) {
%3 = load i8, i8* %0
%4 = tail call i64 @isprint(i8 signext %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %19, label %6
6: ; preds = %2, %13
%7 = phi i64 [ %14, %13 ], [ 0, %2 ]
%8 = phi i8* [ %15, %13 ], [ %0, %2 ]
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, %1
br i1 %10, label %11, label %13
11: ; preds = %6
%12 = tail call signext i8 @toupper(i8 signext %1)
store i8 %12, i8* %8
br label %13
13: ; preds = %11, %6
%14 = add nuw i64 %7, 1
%15 = getelementptr inbounds i8, i8* %0, i64 %14
%16 = load i8, i8* %15
%17 = tail call i64 @isprint(i8 signext %16)
%18 = icmp eq i64 %17, 0
br i1 %18, label %19, label %6
19: ; preds = %13, %2
ret i8* %0
}