#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 adjust_pdb_field_string(char *field) {
  int i, len;
  len = strlen(field);
  while (len > 0 && field[len - 1] == ' ') {
    field[len - 1] = '\0';
    len--;
  }
  while (len > 0 && field[0] == ' ') {
    for (i = 0; i < len; i++)
      field[i] = field[i + 1];
    len--;
  }
}


x86 assembly (clang, -O0):
<adjust_pdb_field_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x11(%rbp)
jle    1151 <adjust_pdb_field_string+0x41>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1161 <adjust_pdb_field_string+0x51>
jmp    1180 <adjust_pdb_field_string+0x70>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1128 <adjust_pdb_field_string+0x18>
jmp    1185 <adjust_pdb_field_string+0x75>
xor    %eax,%eax
cmpl   $0x0,-0x10(%rbp)
mov    %al,-0x12(%rbp)
jle    11a4 <adjust_pdb_field_string+0x94>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
sete   %al
mov    %al,-0x12(%rbp)
mov    -0x12(%rbp),%al
test   $0x1,%al
jne    11b4 <adjust_pdb_field_string+0xa4>
jmp    11fe <adjust_pdb_field_string+0xee>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11f0 <adjust_pdb_field_string+0xe0>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11bb <adjust_pdb_field_string+0xab>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1185 <adjust_pdb_field_string+0x75>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<adjust_pdb_field_string>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
test   %eax,%eax
jle    118a <adjust_pdb_field_string+0x6a>
mov    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    -0x1(%rax),%rcx
mov    %ecx,%edx
cmpb   $0x20,(%r15,%rdx,1)
jne    1161 <adjust_pdb_field_string+0x41>
movb   $0x0,(%r15,%rdx,1)
lea    0x1(%rcx),%rdx
mov    %rcx,%rax
cmp    $0x1,%rdx
ja     1140 <adjust_pdb_field_string+0x20>
jmp    118a <adjust_pdb_field_string+0x6a>
test   %eax,%eax
jle    118a <adjust_pdb_field_string+0x6a>
lea    0x1(%r15),%r14
mov    %eax,%ebx
nopl   0x0(%rax,%rax,1)
cmpb   $0x20,(%r15)
jne    118a <adjust_pdb_field_string+0x6a>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <memmove@plt>
add    $0xffffffffffffffff,%rbx
jne    1170 <adjust_pdb_field_string+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @adjust_pdb_field_string(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @strlen(i8* %5)
store i32 %6, i32* %4
br label %7
7: ; preds = %21, %1
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i8*, i8** %2
%12 = load i32, i32* %4
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 32
br label %19
19: ; preds = %10, %7
%20 = phi i1 [ false, %7 ], [ %18, %10 ]
br i1 %20, label %21, label %29
21: ; preds = %19
%22 = load i8*, i8** %2
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %22, i64 %25
store i8 0, i8* %26
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
br label %7
29: ; preds = %19
br label %30
30: ; preds = %60, %29
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %39
33: ; preds = %30
%34 = load i8*, i8** %2
%35 = getelementptr inbounds i8, i8* %34, i64 0
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 32
br label %39
39: ; preds = %33, %30
%40 = phi i1 [ false, %30 ], [ %38, %33 ]
br i1 %40, label %41, label %63
41: ; preds = %39
store i32 0, i32* %3
br label %42
42: ; preds = %57, %41
%43 = load i32, i32* %3
%44 = load i32, i32* %4
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %60
46: ; preds = %42
%47 = load i8*, i8** %2
%48 = load i32, i32* %3
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8, i8* %47, i64 %50
%52 = load i8, i8* %51
%53 = load i8*, i8** %2
%54 = load i32, i32* %3
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %53, i64 %55
store i8 %52, i8* %56
br label %57
57: ; preds = %46
%58 = load i32, i32* %3
%59 = add nsw i32 %58, 1
store i32 %59, i32* %3
br label %42
60: ; preds = %42
%61 = load i32, i32* %4
%62 = add nsw i32 %61, -1
store i32 %62, i32* %4
br label %30
63: ; preds = %39
ret void
}

LLVM IR (-O2):
define void @adjust_pdb_field_string(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = icmp sgt i32 %2, 0
br i1 %3, label %4, label %29
4: ; preds = %1
%5 = zext i32 %2 to i64
br label %6
6: ; preds = %4, %13
%7 = phi i64 [ %5, %4 ], [ %8, %13 ]
%8 = add nsw i64 %7, -1
%9 = and i64 %8, 4294967295
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 32
br i1 %12, label %13, label %15
13: ; preds = %6
store i8 0, i8* %10
%14 = icmp ugt i64 %7, 1
br i1 %14, label %6, label %29
15: ; preds = %6
%16 = trunc i64 %7 to i32
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = getelementptr i8, i8* %0, i64 1
%20 = and i64 %7, 4294967295
br label %21
21: ; preds = %18, %25
%22 = phi i64 [ 0, %18 ], [ %27, %25 ]
%23 = load i8, i8* %0
%24 = icmp eq i8 %23, 32
br i1 %24, label %25, label %29
25: ; preds = %21
%26 = sub nsw i64 %20, %22
%27 = add nuw nsw i64 %22, 1
%28 = icmp eq i64 %27, %20
br i1 %28, label %29, label %21
29: ; preds = %13, %21, %25, %1, %15
ret void
}