#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 strlen(char *);
void plustospace(char *string) {
  char *p;
  int slen;
  slen = strlen(string);
  for (p = string; p < (string + slen) && *p != 0; p++) {
    if (*p == '+')
      *p = ' ';
  }
}


x86 assembly (clang, -O0):
<plustospace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rcx
mov    -0x8(%rbp),%rdx
movslq -0x14(%rbp),%rax
add    %rax,%rdx
xor    %eax,%eax
cmp    %rdx,%rcx
mov    %al,-0x15(%rbp)
jae    115d <plustospace+0x4d>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    116d <plustospace+0x5d>
jmp    119a <plustospace+0x8a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2b,%eax
jne    1184 <plustospace+0x74>
mov    -0x10(%rbp),%rax
movb   $0x20,(%rax)
jmp    1189 <plustospace+0x79>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <plustospace+0x20>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plustospace>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
test   %eax,%eax
jle    1148 <plustospace+0x38>
cltq
add    %rbx,%rax
jmp    113c <plustospace+0x2c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movb   $0x20,(%rbx)
add    $0x1,%rbx
cmp    %rax,%rbx
jae    1148 <plustospace+0x38>
movzbl (%rbx),%ecx
cmp    $0x2b,%cl
je     1130 <plustospace+0x20>
test   %cl,%cl
jne    1133 <plustospace+0x23>
pop    %rbx
ret

LLVM IR (-O0):
define void @plustospace(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
%7 = load i8*, i8** %2
store i8* %7, i8** %3
br label %8
8: ; preds = %30, %1
%9 = load i8*, i8** %3
%10 = load i8*, i8** %2
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = icmp ult i8* %9, %13
br i1 %14, label %15, label %20
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 0
br label %20
20: ; preds = %15, %8
%21 = phi i1 [ false, %8 ], [ %19, %15 ]
br i1 %21, label %22, label %33
22: ; preds = %20
%23 = load i8*, i8** %3
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 43
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = load i8*, i8** %3
store i8 32, i8* %28
br label %29
29: ; preds = %27, %22
br label %30
30: ; preds = %29
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i32 1
store i8* %32, i8** %3
br label %8
33: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @plustospace(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = icmp sgt i32 %2, 0
br i1 %5, label %6, label %13
6: ; preds = %1, %10
%7 = phi i8* [ %11, %10 ], [ %0, %1 ]
%8 = load i8, i8* %7
switch i8 %8, label %10 [
i8 0, label %13
i8 43, label %9
]
9: ; preds = %6
store i8 32, i8* %7
br label %10
10: ; preds = %6, %9
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = icmp ult i8* %11, %4
br i1 %12, label %6, label %13
13: ; preds = %10, %6, %1
ret void
}