#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__ isCorrectFormat(char);
char *malloc(int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *getPOS(char *s) {
  int len = strlen(s);
  char *result = malloc(sizeof(char) * 256);
  char cToStr[2];
  cToStr[1] = '\0';
  for (int i = 0; i < len; i++) {
    if (isCorrectFormat(s[i])) {
      cToStr[0] = s[i];
      strcat(result, cToStr);
      if (s[i] == ',') {
        i += 2;
      }
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<getPOS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0xc(%rbp)
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x19(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e9 <getPOS+0xa9>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <isCorrectFormat@plt>
cmp    $0x0,%rax
je     11d6 <getPOS+0x96>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1a(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x1a(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2c,%eax
jne    11d1 <getPOS+0x91>
mov    -0x20(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x20(%rbp)
jmp    11d6 <getPOS+0x96>
jmp    11db <getPOS+0x9b>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1171 <getPOS+0x31>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getPOS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    $0x100,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
movb   $0x0,0x7(%rsp)
test   %r12d,%r12d
jle    11bd <getPOS+0x7d>
xor    %ebp,%ebp
lea    0x6(%rsp),%r15
jmp    1188 <getPOS+0x48>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    %r12d,%ebp
jge    11bd <getPOS+0x7d>
movslq %ebp,%rbx
movsbl 0x0(%r13,%rbx,1),%edi
call   1040 <isCorrectFormat@plt>
test   %rax,%rax
je     1180 <getPOS+0x40>
movzbl 0x0(%r13,%rbx,1),%eax
mov    %al,0x6(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
cmpb   $0x2c,0x0(%r13,%rbx,1)
jne    1180 <getPOS+0x40>
add    $0x2,%ebp
jmp    1180 <getPOS+0x40>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @getPOS(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca [2 x i8]
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @strlen(i8* %7)
store i32 %8, i32* %3
%9 = call i8* @malloc(i32 256)
store i8* %9, i8** %4
%10 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 1
store i8 0, i8* %10
store i32 0, i32* %6
br label %11
11: ; preds = %45, %1
%12 = load i32, i32* %6
%13 = load i32, i32* %3
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %48
15: ; preds = %11
%16 = load i8*, i8** %2
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
%20 = load i8, i8* %19
%21 = call i64 @isCorrectFormat(i8 signext %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %44
23: ; preds = %15
%24 = load i8*, i8** %2
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i8, i8* %27
%29 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
store i8 %28, i8* %29
%30 = load i8*, i8** %4
%31 = getelementptr inbounds [2 x i8], [2 x i8]* %5, i64 0, i64 0
%32 = call i32 @strcat(i8* %30, i8* %31)
%33 = load i8*, i8** %2
%34 = load i32, i32* %6
%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, 44
br i1 %39, label %40, label %43
40: ; preds = %23
%41 = load i32, i32* %6
%42 = add nsw i32 %41, 2
store i32 %42, i32* %6
br label %43
43: ; preds = %40, %23
br label %44
44: ; preds = %43, %15
br label %45
45: ; preds = %44
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
store i32 %47, i32* %6
br label %11
48: ; preds = %11
%49 = load i8*, i8** %4
ret i8* %49
}

LLVM IR (-O2):
define i8* @getPOS(i8* %0) {
%2 = alloca [2 x i8]
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [2 x i8], [2 x i8]* %2, i64 0, i64 1
store i8 0, i8* %6
%7 = icmp sgt i32 %3, 0
br i1 %7, label %9, label %8
8: ; preds = %23, %1
ret i8* %4
9: ; preds = %1, %23
%10 = phi i32 [ %25, %23 ], [ 0, %1 ]
%11 = sext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = call i64 @isCorrectFormat(i8 signext %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %23, label %16
16: ; preds = %9
%17 = load i8, i8* %12
store i8 %17, i8* %5
%18 = call i32 @strcat(i8* %4, i8* %5)
%19 = load i8, i8* %12
%20 = icmp eq i8 %19, 44
%21 = add nsw i32 %10, 2
%22 = select i1 %20, i32 %21, i32 %10
br label %23
23: ; preds = %16, %9
%24 = phi i32 [ %10, %9 ], [ %22, %16 ]
%25 = add nsw i32 %24, 1
%26 = icmp slt i32 %25, %3
br i1 %26, label %9, label %8
}