#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 test_pointer_string(char *c) {
  char temp, *end_ptr;
  if (c == NULL || !(*c))
    return;
  end_ptr = c + strlen(c) - 1;
  while (end_ptr > c) {
    temp = *c;
    *c = *end_ptr;
    *end_ptr = temp;
    c++;
    end_ptr--;
  }
}


x86 assembly (clang, -O0):
<test_pointer_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1134 <test_pointer_string+0x24>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1139 <test_pointer_string+0x29>
jmp    11a7 <test_pointer_string+0x97>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jbe    11a7 <test_pointer_string+0x97>
mov    -0x8(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x9(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
mov    -0x9(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    115e <test_pointer_string+0x4e>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pointer_string>:
push   %rbx
test   %rdi,%rdi
je     115c <test_pointer_string+0x4c>
mov    %rdi,%rbx
cmpb   $0x0,(%rdi)
je     115c <test_pointer_string+0x4c>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
add    %rbx,%rax
add    $0xffffffffffffffff,%rax
cmp    %rbx,%rax
jbe    115c <test_pointer_string+0x4c>
add    $0x1,%rbx
nopl   0x0(%rax,%rax,1)
movzbl -0x1(%rbx),%ecx
movzbl (%rax),%edx
mov    %dl,-0x1(%rbx)
mov    %cl,(%rax)
add    $0xffffffffffffffff,%rax
lea    0x1(%rbx),%rcx
cmp    %rbx,%rax
mov    %rcx,%rbx
ja     1140 <test_pointer_string+0x30>
pop    %rbx
ret

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

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