#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*/ printf(char *, int, ...);
int strlen(char const *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void strip_loop_marker_string(char *stripped_string, const char *orig_string) {
  int colonpos, marker_start_pos = 0;
  int i = 0;
  for (i = 0; i < strlen(orig_string); i++) {
    if (*(orig_string + i) == ':') {
      colonpos = i;
      break;
    }
  }
  for (i = colonpos; i > 0; i--) {
    if (*(orig_string + i) == ' ' || *(orig_string + i) == '\n' ||
        *(orig_string + i) == '\t' || *(orig_string + i) == '\r') {
      marker_start_pos = i + 1;
      break;
    }
  }
  printf("Marker start pos: %d\n Colon pos: %d\n", marker_start_pos, colonpos);
  strncpy(stripped_string, orig_string + marker_start_pos,
          (colonpos + 1) - marker_start_pos);
  printf("Stripped length: %d\n", (int)strlen(stripped_string));
}


x86 assembly (clang, -O0):
<strip_loop_marker_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jge    11a4 <strip_loop_marker_string+0x74>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x3a,%eax
jne    1191 <strip_loop_marker_string+0x61>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    11a4 <strip_loop_marker_string+0x74>
jmp    1196 <strip_loop_marker_string+0x66>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1155 <strip_loop_marker_string+0x25>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1229 <strip_loop_marker_string+0xf9>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
je     1208 <strip_loop_marker_string+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
je     1208 <strip_loop_marker_string+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x9,%eax
je     1208 <strip_loop_marker_string+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    1216 <strip_loop_marker_string+0xe6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1229 <strip_loop_marker_string+0xf9>
jmp    121b <strip_loop_marker_string+0xeb>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11aa <strip_loop_marker_string+0x7a>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
sub    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strip_loop_marker_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1040 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jle    11b0 <strip_loop_marker_string+0x80>
nopl   0x0(%rax,%rax,1)
cmpb   $0x3a,(%r15,%rbx,1)
je     116a <strip_loop_marker_string+0x3a>
add    $0x1,%rbx
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1150 <strip_loop_marker_string+0x20>
xor    %ebp,%ebp
test   %ebx,%ebx
jle    11b2 <strip_loop_marker_string+0x82>
mov    %rbx,%rax
add    $0x1,%rax
movabs $0x100002600,%rcx
jmp    119a <strip_loop_marker_string+0x6a>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
jle    11b2 <strip_loop_marker_string+0x82>
movzbl -0x1(%r15,%rax,1),%edx
cmp    $0x20,%rdx
ja     1190 <strip_loop_marker_string+0x60>
bt     %rdx,%rcx
jae    1190 <strip_loop_marker_string+0x60>
mov    %eax,%ebp
jmp    11b2 <strip_loop_marker_string+0x82>
xor    %ebp,%ebp
lea    0xe47(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebp,%eax
add    %rax,%r15
sub    %ebp,%ebx
add    $0x1,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
lea    0xe3b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"Marker start pos: %d\0A Colon pos: %d\0A\00"
@.str.1 = [21 x i8] c"Stripped length: %d\0A\00"
define void @strip_loop_marker_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %7
br label %8
8: ; preds = %24, %2
%9 = load i32, i32* %7
%10 = load i8*, i8** %4
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = load i32, i32* %7
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %14, i64 %16
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 58
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = load i32, i32* %7
store i32 %22, i32* %5
br label %27
23: ; preds = %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %7
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
br label %8
27: ; preds = %21, %8
%28 = load i32, i32* %5
store i32 %28, i32* %7
br label %29
29: ; preds = %68, %27
%30 = load i32, i32* %7
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %71
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i32, i32* %7
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 32
br i1 %39, label %64, label %40
40: ; preds = %32
%41 = load i8*, i8** %4
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 10
br i1 %47, label %64, label %48
48: ; preds = %40
%49 = load i8*, i8** %4
%50 = load i32, i32* %7
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8, i8* %49, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 9
br i1 %55, label %64, label %56
56: ; preds = %48
%57 = load i8*, i8** %4
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %57, i64 %59
%61 = load i8, i8* %60
%62 = sext i8 %61 to i32
%63 = icmp eq i32 %62, 13
br i1 %63, label %64, label %67
64: ; preds = %56, %48, %40, %32
%65 = load i32, i32* %7
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %71
67: ; preds = %56
br label %68
68: ; preds = %67
%69 = load i32, i32* %7
%70 = add nsw i32 %69, -1
store i32 %70, i32* %7
br label %29
71: ; preds = %64, %29
%72 = load i32, i32* %6
%73 = load i32, i32* %5
%74 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %72, i32 %73)
%75 = load i8*, i8** %3
%76 = load i8*, i8** %4
%77 = load i32, i32* %6
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8, i8* %76, i64 %78
%80 = load i32, i32* %5
%81 = add nsw i32 %80, 1
%82 = load i32, i32* %6
%83 = sub nsw i32 %81, %82
%84 = call i32 @strncpy(i8* %75, i8* %79, i32 %83)
%85 = load i8*, i8** %3
%86 = call i32 @strlen(i8* %85)
%87 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %86)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"Marker start pos: %d\0A Colon pos: %d\0A\00"
@.str.1 = [21 x i8] c"Stripped length: %d\0A\00"
define void @strip_loop_marker_string(i8* %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %31
5: ; preds = %2, %10
%6 = phi i64 [ %11, %10 ], [ 0, %2 ]
%7 = getelementptr inbounds i8, i8* %1, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 58
br i1 %9, label %15, label %10
10: ; preds = %5
%11 = add nuw nsw i64 %6, 1
%12 = tail call i32 @strlen(i8* %1)
%13 = sext i32 %12 to i64
%14 = icmp slt i64 %11, %13
br i1 %14, label %5, label %15
15: ; preds = %10, %5
%16 = phi i64 [ %11, %10 ], [ %6, %5 ]
%17 = trunc i64 %16 to i32
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %31
19: ; preds = %15
%20 = and i64 %16, 4294967295
br label %21
21: ; preds = %19, %28
%22 = phi i64 [ %20, %19 ], [ %29, %28 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %22
%24 = load i8, i8* %23
switch i8 %24, label %28 [
i8 32, label %25
i8 10, label %25
i8 9, label %25
i8 13, label %25
]
25: ; preds = %21, %21, %21, %21
%26 = trunc i64 %22 to i32
%27 = add nuw nsw i32 %26, 1
br label %31
28: ; preds = %21
%29 = add nsw i64 %22, -1
%30 = icmp sgt i64 %22, 1
br i1 %30, label %21, label %31
31: ; preds = %28, %2, %15, %25
%32 = phi i32 [ %17, %25 ], [ %17, %15 ], [ 0, %2 ], [ %17, %28 ]
%33 = phi i32 [ %27, %25 ], [ 0, %15 ], [ 0, %2 ], [ 0, %28 ]
%34 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %32)
%35 = zext i32 %33 to i64
%36 = getelementptr inbounds i8, i8* %1, i64 %35
%37 = add nuw nsw i32 %32, 1
%38 = sub i32 %37, %33
%39 = tail call i32 @strncpy(i8* %0, i8* %36, i32 %38)
%40 = tail call i32 @strlen(i8* %0)
%41 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 %40)
ret void
}