#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 *);
char *strstr(char *, char *);
int remove_bad_updown(char *s) {
  char *c1, *c2;
  char *p, *u;
  int s1, s2;
  int i, pisup, x;
  char up[8] = "'", down[8] = ",";
  for (x = 0; x < 5; x++) {
    pisup = 0;
    s1 = strlen(s);
    s2 = strlen(up) + strlen(down);
    if ((c1 = strstr(s, up)) != NULL && (c2 = strstr(s, down)) != NULL) {
      if (c1 < c2)
        p = c1, u = c2, pisup = 1;
      else
        p = c2, u = c1, pisup = 0;
      for (i = 0; i < s2; i++)
        *(p + i) = *(p + i + 1);
      s[s1 - s2] = '\0';
    }
  }
  return 1;
}


x86 assembly (clang, -O0):
<remove_bad_updown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0xecd(%rip),%rax
mov    %rax,-0x44(%rbp)
mov    0xeca(%rip),%rax
mov    %rax,-0x4c(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x5,-0x3c(%rbp)
jge    1258 <remove_bad_updown+0x138>
movl   $0x0,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x44(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x50(%rbp)
lea    -0x4c(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1245 <remove_bad_updown+0x125>
mov    -0x8(%rbp),%rdi
lea    -0x4c(%rbp),%rsi
call   1040 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1245 <remove_bad_updown+0x125>
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11e5 <remove_bad_updown+0xc5>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x1,-0x38(%rbp)
jmp    11fc <remove_bad_updown+0xdc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1234 <remove_bad_updown+0x114>
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    0x1(%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1203 <remove_bad_updown+0xe3>
mov    -0x8(%rbp),%rax
mov    -0x2c(%rbp),%ecx
sub    -0x30(%rbp),%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    124a <remove_bad_updown+0x12a>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1149 <remove_bad_updown+0x29>
mov    $0x1,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_bad_updown>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
movq   $0x27,0x10(%rsp)
movq   $0x2c,0x8(%rsp)
mov    $0x5,%r14d
jmp    1172 <remove_bad_updown+0x42>
nopl   0x0(%rax,%rax,1)
mov    0x4(%rsp),%eax
sub    %ebp,%eax
cltq
movb   $0x0,(%rbx,%rax,1)
add    $0xffffffff,%r14d
je     11ec <remove_bad_updown+0xbc>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,0x4(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %eax,%r13d
lea    0x8(%rsp),%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     116c <remove_bad_updown+0x3c>
mov    %rax,%r15
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     116c <remove_bad_updown+0x3c>
lea    (%r12,%r13,1),%ebp
cmp    %rax,%r15
jb     11cc <remove_bad_updown+0x9c>
mov    %rax,%r15
test   %ebp,%ebp
jle    1160 <remove_bad_updown+0x30>
lea    0x1(%r15),%rsi
lea    (%r12,%r13,1),%edx
add    $0xffffffff,%edx
add    $0x1,%rdx
mov    %r15,%rdi
call   1040 <memmove@plt>
jmp    1160 <remove_bad_updown+0x30>
mov    $0x1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.remove_bad_updown.up = [8 x i8] c"'\00\00\00\00\00\00\00"
@__const.remove_bad_updown.down = [8 x i8] c",\00\00\00\00\00\00\00"
define i32 @remove_bad_updown(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca [8 x i8]
%13 = alloca [8 x i8]
store i8* %0, i8** %2
%14 = bitcast [8 x i8]* %12 to i8*
%15 = bitcast [8 x i8]* %13 to i8*
store i32 0, i32* %11
br label %16
16: ; preds = %73, %1
%17 = load i32, i32* %11
%18 = icmp slt i32 %17, 5
br i1 %18, label %19, label %76
19: ; preds = %16
store i32 0, i32* %10
%20 = load i8*, i8** %2
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %7
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%25 = call i32 @strlen(i8* %24)
%26 = add nsw i32 %23, %25
store i32 %26, i32* %8
%27 = load i8*, i8** %2
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%29 = call i8* @strstr(i8* %27, i8* %28)
store i8* %29, i8** %3
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %72
31: ; preds = %19
%32 = load i8*, i8** %2
%33 = getelementptr inbounds [8 x i8], [8 x i8]* %13, i64 0, i64 0
%34 = call i8* @strstr(i8* %32, i8* %33)
store i8* %34, i8** %4
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %72
36: ; preds = %31
%37 = load i8*, i8** %3
%38 = load i8*, i8** %4
%39 = icmp ult i8* %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i8*, i8** %3
store i8* %41, i8** %5
%42 = load i8*, i8** %4
store i8* %42, i8** %6
store i32 1, i32* %10
br label %46
43: ; preds = %36
%44 = load i8*, i8** %4
store i8* %44, i8** %5
%45 = load i8*, i8** %3
store i8* %45, i8** %6
store i32 0, i32* %10
br label %46
46: ; preds = %43, %40
store i32 0, i32* %9
br label %47
47: ; preds = %62, %46
%48 = load i32, i32* %9
%49 = load i32, i32* %8
%50 = icmp slt i32 %48, %49
br i1 %50, label %51, label %65
51: ; preds = %47
%52 = load i8*, i8** %5
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i8, i8* %56
%58 = load i8*, i8** %5
%59 = load i32, i32* %9
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8, i8* %58, i64 %60
store i8 %57, i8* %61
br label %62
62: ; preds = %51
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %47
65: ; preds = %47
%66 = load i8*, i8** %2
%67 = load i32, i32* %7
%68 = load i32, i32* %8
%69 = sub nsw i32 %67, %68
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %66, i64 %70
store i8 0, i8* %71
br label %72
72: ; preds = %65, %31, %19
br label %73
73: ; preds = %72
%74 = load i32, i32* %11
%75 = add nsw i32 %74, 1
store i32 %75, i32* %11
br label %16
76: ; preds = %16
ret i32 1
}

LLVM IR (-O2):
define i32 @remove_bad_updown(i8* %0) {
%2 = alloca i64
%3 = alloca i64
%4 = bitcast i64* %2 to i8*
store i64 39, i64* %2
%5 = bitcast i64* %3 to i8*
store i64 44, i64* %3
br label %6
6: ; preds = %1, %31
%7 = phi i32 [ 0, %1 ], [ %32, %31 ]
%8 = call i32 @strlen(i8* %0)
%9 = call i32 @strlen(i8* %4)
%10 = call i32 @strlen(i8* %5)
%11 = add nsw i32 %10, %9
%12 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %4)
%13 = icmp eq i8* %12, null
br i1 %13, label %31, label %14
14: ; preds = %6
%15 = call i8* @strstr(i8* dereferenceable(1) %0, i8* %5)
%16 = icmp eq i8* %15, null
br i1 %16, label %31, label %17
17: ; preds = %14
%18 = icmp ult i8* %12, %15
%19 = select i1 %18, i8* %12, i8* %15
%20 = icmp sgt i32 %11, 0
br i1 %20, label %21, label %27
21: ; preds = %17
%22 = getelementptr i8, i8* %19, i64 1
%23 = add i32 %10, -1
%24 = add i32 %23, %9
%25 = zext i32 %24 to i64
%26 = add nuw nsw i64 %25, 1
br label %27
27: ; preds = %21, %17
%28 = sub nsw i32 %8, %11
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %0, i64 %29
store i8 0, i8* %30
br label %31
31: ; preds = %6, %14, %27
%32 = add nuw nsw i32 %7, 1
%33 = icmp eq i32 %32, 5
br i1 %33, label %34, label %6
34: ; preds = %31
ret i32 1
}