#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__ malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char const *, int);
int strlen(char const *);
unsigned char *_fix_input(const unsigned char *in) {
  unsigned char *out;
  int len;
  len = strlen((const char *)in);
  if (len > 254)
    len = 254;
  if (in[len - 1] != '.' && len < 254) {
    out = (unsigned char *)malloc(len + 2);
    memcpy(out, in, len);
    out[len] = '.';
    out[len + 1] = 0;
    ++len;
  } else {
    out = (unsigned char *)malloc(len + 1);
    memcpy(out, in, len);
    out[len] = 0;
  }
  return out;
}


x86 assembly (clang, -O0):
<_fix_input>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xfe,-0x14(%rbp)
jle    115c <_fix_input+0x2c>
movl   $0xfe,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movzbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     11cd <_fix_input+0x9d>
cmpl   $0xfe,-0x14(%rbp)
jge    11cd <_fix_input+0x9d>
mov    -0x14(%rbp),%edi
add    $0x2,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11f8 <_fix_input+0xc8>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_fix_input>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <strlen@plt>
cmp    $0xfe,%eax
mov    $0xfe,%ebx
cmovl  %eax,%ebx
movslq %ebx,%r12
cmpb   $0x2e,-0x1(%r12,%r14,1)
je     1181 <_fix_input+0x51>
cmp    $0xfd,%eax
jg     1181 <_fix_input+0x51>
lea    0x2(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movb   $0x2e,(%r15,%r12,1)
add    $0x1,%ebx
jmp    1199 <_fix_input+0x69>
lea    0x1(%rbx),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
movslq %ebx,%rax
movb   $0x0,(%r15,%rax,1)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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