#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*/ findPalindrome(char *, int, int, int *, int *, int);
char *malloc(int);
int strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *longestPalindrome(char *s) {
  int length = strlen(s);
  if (length < 2)
    return s;
  int maxLen = 0;
  int pos;
  for (int i = 0; i < length - 1; i++) {
    findPalindrome(s, i, i, &pos, &maxLen, length);
    findPalindrome(s, i, i + 1, &pos, &maxLen, length);
  }
  char *result = malloc(sizeof(char) * (maxLen + 1));
  strncpy(result, s + pos, maxLen);
  result[maxLen] = '\0';
  return result;
}


x86 assembly (clang, -O0):
<longestPalindrome>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jge    116f <longestPalindrome+0x2f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1217 <longestPalindrome+0xd7>
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11d5 <longestPalindrome+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    -0x14(%rbp),%r9d
lea    -0x1c(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1060 <findPalindrome@plt>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x14(%rbp),%r9d
lea    -0x1c(%rbp),%rcx
lea    -0x18(%rbp),%r8
call   1060 <findPalindrome@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    117d <longestPalindrome+0x3d>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movslq -0x1c(%rbp),%rax
add    %rax,%rsi
mov    -0x18(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<longestPalindrome>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <strlen@plt>
cmp    $0x2,%eax
jl     11d4 <longestPalindrome+0x94>
mov    %eax,%r13d
movl   $0x0,(%rsp)
mov    $0x1,%ebx
lea    0x4(%rsp),%r15
mov    %rsp,%r12
nop
lea    -0x1(%rbx),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebp,%edx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r13d,%r9d
call   1060 <findPalindrome@plt>
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %r15,%rcx
mov    %r12,%r8
mov    %r13d,%r9d
call   1060 <findPalindrome@plt>
add    $0x1,%ebx
cmp    %ebx,%r13d
jne    1170 <longestPalindrome+0x30>
mov    (%rsp),%ebx
movslq 0x4(%rsp),%r15
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
add    %r15,%r14
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <strncpy@plt>
movslq (%rsp),%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    %rbp,%r14
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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