#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__ isspace(unsigned char);
char *clean_line(char *p) {
  int i;
  char c, *q;
  while (isspace((unsigned char)*p))
    p++;
  q = p;
  i = 0;
  for (;;) {
    if ((c = *p++) == '%') {
      if (i > 0 && p[-2] != '\\')
        c = '\0';
    }
    if (c == '\0') {
      p--;
      break;
    }
    i++;
  }
  while (--i > 0) {
    c = *--p;
    if (!isspace((unsigned char)c)) {
      p[1] = '\0';
      break;
    }
  }
  return q;
}


x86 assembly (clang, -O0):
<clean_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
je     1143 <clean_line+0x33>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    111c <clean_line+0xc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%al
mov    %al,-0xd(%rbp)
movsbl %al,%eax
cmp    $0x25,%eax
jne    1196 <clean_line+0x86>
cmpl   $0x0,-0xc(%rbp)
jle    1191 <clean_line+0x81>
mov    -0x8(%rbp),%rax
movsbl -0x2(%rax),%eax
cmp    $0x5c,%eax
je     1191 <clean_line+0x81>
movb   $0x0,-0xd(%rbp)
jmp    1196 <clean_line+0x86>
movsbl -0xd(%rbp),%eax
cmp    $0x0,%eax
jne    11b4 <clean_line+0xa4>
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
jmp    11c2 <clean_line+0xb2>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1152 <clean_line+0x42>
jmp    11c7 <clean_line+0xb7>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jle    1213 <clean_line+0x103>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x8(%rbp)
mov    -0x1(%rax),%al
mov    %al,-0xd(%rbp)
movzbl -0xd(%rbp),%edi
call   1030 <isspace@plt>
cmp    $0x0,%rax
jne    120e <clean_line+0xfe>
mov    -0x8(%rbp),%rax
movb   $0x0,0x1(%rax)
jmp    1213 <clean_line+0x103>
jmp    11c7 <clean_line+0xb7>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_line>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
nopl   0x0(%rax,%rax,1)
movzbl (%rbx),%edi
call   1030 <isspace@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    1120 <clean_line+0x10>
lea    -0x1(%rbx),%r14
xor    %r15d,%r15d
jmp    1148 <clean_line+0x38>
nopw   0x0(%rax,%rax,1)
test   %al,%al
je     115f <clean_line+0x4f>
add    $0x1,%r15
movzbl -0x1(%rbx,%r15,1),%eax
cmp    $0x25,%al
jne    1140 <clean_line+0x30>
test   %r15d,%r15d
je     1140 <clean_line+0x30>
cmpb   $0x5c,-0x2(%rbx,%r15,1)
je     1144 <clean_line+0x34>
add    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmp    $0x2,%r15d
jl     118f <clean_line+0x7f>
add    $0xffffffff,%r15d
movzbl -0x2(%rbx),%edi
call   1030 <isspace@plt>
add    $0xffffffffffffffff,%rbx
test   %rax,%rax
jne    1170 <clean_line+0x60>
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i8* @clean_line(i8* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i8* [ %0, %1 ], [ %7, %2 ]
%4 = load i8, i8* %3
%5 = tail call i64 @isspace(i8 zeroext %4)
%6 = icmp eq i64 %5, 0
%7 = getelementptr inbounds i8, i8* %3, i64 1
br i1 %6, label %8, label %2
8: ; preds = %2, %23
%9 = phi i32 [ %24, %23 ], [ 0, %2 ]
%10 = phi i8* [ %11, %23 ], [ %3, %2 ]
%11 = getelementptr inbounds i8, i8* %10, i64 1
%12 = load i8, i8* %10
%13 = icmp eq i8 %12, 37
%14 = icmp ne i32 %9, 0
%15 = select i1 %13, i1 %14, i1 false
br i1 %15, label %16, label %20
16: ; preds = %8
%17 = getelementptr inbounds i8, i8* %10, i64 -1
%18 = load i8, i8* %17
%19 = icmp eq i8 %18, 92
br i1 %19, label %23, label %22
20: ; preds = %8
%21 = icmp eq i8 %12, 0
br i1 %21, label %22, label %23
22: ; preds = %16, %20
br label %25
23: ; preds = %16, %20
%24 = add nuw nsw i32 %9, 1
br label %8
25: ; preds = %22, %29
%26 = phi i32 [ %30, %29 ], [ %9, %22 ]
%27 = phi i8* [ %31, %29 ], [ %10, %22 ]
%28 = icmp sgt i32 %26, 1
br i1 %28, label %29, label %36
29: ; preds = %25
%30 = add nsw i32 %26, -1
%31 = getelementptr inbounds i8, i8* %27, i64 -1
%32 = load i8, i8* %31
%33 = tail call i64 @isspace(i8 zeroext %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %25
35: ; preds = %29
store i8 0, i8* %27
br label %36
36: ; preds = %25, %35
ret i8* %3
}