#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 */
size_t floor(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
scalar_t__ pow(int, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int man2string(char *line, long man) {
  int rc = 0, i = 0, l = 0, counter = 0;
  size_t length = 0;
  char *output = NULL, *pad = NULL;
  output = malloc(sizeof(char) * 20);
  if (!output) {
    printf("Memory error\n");
    rc = 1;
    goto cleanup;
  }
  for (i = 19 - 1, l = 0; i >= l; i--) {
    output[counter++] = (man & (long)pow(2, i)) ? '.' : '0';
  }
  output[counter] = '\0';
  length = floor((49 - strlen(output)) / 2);
  counter = 0;
  pad = malloc(sizeof(char) * length + 1);
  if (!pad) {
    printf("Memory error\n");
    rc = 1;
    goto cleanup;
  }
  for (i = 0, l = length; i < l; i++) {
    pad[counter++] = '.';
  }
  pad[counter] = '\0';
  strcpy(line, pad);
  strcat(line, output);
  strcat(line, pad);
cleanup:
  if (output) {
    free(output);
  }
  if (pad) {
    free(pad);
  }
  return rc;
}


x86 assembly (clang, -O0):
<man2string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    $0x14,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f5 <man2string+0x75>
lea    0xe1c(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1344 <man2string+0x1c4>
movl   $0x12,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     1261 <man2string+0xe1>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%esi
mov    $0x2,%edi
call   1080 <pow@plt>
mov    -0x40(%rbp),%rdx
and    %rax,%rdx
mov    $0x30,%eax
mov    $0x2e,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %al,%dl
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x20(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    1203 <man2string+0x83>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    $0x31,%eax
sub    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
call   10a0 <floor@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    12d3 <man2string+0x153>
lea    0xd3e(%rip),%rdi
call   1060 <printf@plt>
movl   $0x1,-0x14(%rbp)
jmp    1344 <man2string+0x1c4>
movl   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1311 <man2string+0x191>
mov    -0x38(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x20(%rbp)
movslq %ecx,%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12e1 <man2string+0x161>
mov    -0x38(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1090 <strcat@plt>
cmpq   $0x0,-0x30(%rbp)
je     1358 <man2string+0x1d8>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
je     136c <man2string+0x1ec>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<man2string>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r12
mov    %rdi,%r14
mov    $0x14,%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1264 <man2string+0xd4>
mov    %rax,%r15
mov    %rax,%r13
add    $0x1,%r13
mov    $0x12,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    %ebx,%esi
call   1090 <pow@plt>
test   %r12,%rax
sete   %al
add    %al,%al
add    $0x2e,%al
mov    %al,-0x1(%r13)
test   %rbx,%rbx
je     1214 <man2string+0x84>
lea    -0x1(%rbx),%esi
mov    $0x2,%edi
call   1090 <pow@plt>
test   %r12,%rax
sete   %al
add    %al,%al
add    $0x2e,%al
mov    %al,0x0(%r13)
add    $0x2,%r13
add    $0xfffffffffffffffe,%rbx
jmp    11d0 <man2string+0x40>
movb   $0x0,0x13(%r15)
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    $0x31,%ecx
sub    %eax,%ecx
mov    %ecx,%edi
shr    $0x1f,%edi
add    %ecx,%edi
sar    %edi
call   10b0 <floor@plt>
mov    %rax,%rbx
lea    0x1(%rax),%edi
call   1080 <malloc@plt>
test   %rax,%rax
je     1278 <man2string+0xe8>
mov    %rax,%r13
xor    %r12d,%r12d
test   %ebx,%ebx
jle    1294 <man2string+0x104>
mov    %ebx,%ebx
mov    %r13,%rdi
mov    $0x2e,%esi
mov    %rbx,%rdx
call   1070 <memset@plt>
jmp    1296 <man2string+0x106>
lea    0xd95(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%r12d
jmp    12cd <man2string+0x13d>
lea    0xd81(%rip),%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1,%r12d
jmp    12cd <man2string+0x13d>
xor    %ebx,%ebx
movb   $0x0,0x0(%r13,%rbx,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10a0 <strcat@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Memory error\0A\00"
define i32 @man2string(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i64 0, i64* %9
store i8* null, i8** %10
store i8* null, i8** %11
%12 = call i8* @malloc(i32 20)
store i8* %12, i8** %10
%13 = load i8*, i8** %10
%14 = icmp ne i8* %13, null
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %88
17: ; preds = %2
store i32 18, i32* %6
store i32 0, i32* %7
br label %18
18: ; preds = %36, %17
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = icmp sge i32 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = load i64, i64* %4
%24 = load i32, i32* %6
%25 = call i64 @pow(i32 2, i32 %24)
%26 = and i64 %23, %25
%27 = icmp ne i64 %26, 0
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 46, i32 48
%30 = trunc i32 %29 to i8
%31 = load i8*, i8** %10
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
%34 = sext i32 %32 to i64
%35 = getelementptr inbounds i8, i8* %31, i64 %34
store i8 %30, i8* %35
br label %36
36: ; preds = %22
%37 = load i32, i32* %6
%38 = add nsw i32 %37, -1
store i32 %38, i32* %6
br label %18
39: ; preds = %18
%40 = load i8*, i8** %10
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 0, i8* %43
%44 = load i8*, i8** %10
%45 = call i32 @strlen(i8* %44)
%46 = sub nsw i32 49, %45
%47 = sdiv i32 %46, 2
%48 = call i64 @floor(i32 %47)
store i64 %48, i64* %9
store i32 0, i32* %8
%49 = load i64, i64* %9
%50 = mul i64 1, %49
%51 = add i64 %50, 1
%52 = trunc i64 %51 to i32
%53 = call i8* @malloc(i32 %52)
store i8* %53, i8** %11
%54 = load i8*, i8** %11
%55 = icmp ne i8* %54, null
br i1 %55, label %58, label %56
56: ; preds = %39
%57 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %5
br label %88
58: ; preds = %39
store i32 0, i32* %6
%59 = load i64, i64* %9
%60 = trunc i64 %59 to i32
store i32 %60, i32* %7
br label %61
61: ; preds = %71, %58
%62 = load i32, i32* %6
%63 = load i32, i32* %7
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %74
65: ; preds = %61
%66 = load i8*, i8** %11
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
%69 = sext i32 %67 to i64
%70 = getelementptr inbounds i8, i8* %66, i64 %69
store i8 46, i8* %70
br label %71
71: ; preds = %65
%72 = load i32, i32* %6
%73 = add nsw i32 %72, 1
store i32 %73, i32* %6
br label %61
74: ; preds = %61
%75 = load i8*, i8** %11
%76 = load i32, i32* %8
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8 0, i8* %78
%79 = load i8*, i8** %3
%80 = load i8*, i8** %11
%81 = call i32 @strcpy(i8* %79, i8* %80)
%82 = load i8*, i8** %3
%83 = load i8*, i8** %10
%84 = call i32 @strcat(i8* %82, i8* %83)
%85 = load i8*, i8** %3
%86 = load i8*, i8** %11
%87 = call i32 @strcat(i8* %85, i8* %86)
br label %88
88: ; preds = %74, %56, %15
%89 = load i8*, i8** %10
%90 = icmp ne i8* %89, null
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i8*, i8** %10
%93 = call i32 @free(i8* %92)
br label %94
94: ; preds = %91, %88
%95 = load i8*, i8** %11
%96 = icmp ne i8* %95, null
br i1 %96, label %97, label %100
97: ; preds = %94
%98 = load i8*, i8** %11
%99 = call i32 @free(i8* %98)
br label %100
100: ; preds = %97, %94
%101 = load i32, i32* %5
ret i32 %101
}

LLVM IR (-O2):
@str.1 = [13 x i8] c"Memory error\00"
define i32 @man2string(i8* %0, i64 %1) {
%3 = tail call dereferenceable_or_null(20) i8* @malloc(i32 20)
%4 = icmp eq i8* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.1, i64 0, i64 0))
br label %52
7: ; preds = %2, %17
%8 = phi i64 [ %23, %17 ], [ 0, %2 ]
%9 = phi i32 [ %25, %17 ], [ 18, %2 ]
%10 = tail call i64 @pow(i32 2, i32 %9)
%11 = and i64 %10, %1
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i8 48, i8 46
%14 = or i64 %8, 1
%15 = getelementptr inbounds i8, i8* %3, i64 %8
store i8 %13, i8* %15
%16 = icmp eq i64 %14, 19
br i1 %16, label %26, label %17
17: ; preds = %7
%18 = add nsw i32 %9, -1
%19 = tail call i64 @pow(i32 2, i32 %18)
%20 = and i64 %19, %1
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i8 48, i8 46
%23 = add nuw nsw i64 %8, 2
%24 = getelementptr inbounds i8, i8* %3, i64 %14
store i8 %22, i8* %24
%25 = add nsw i32 %9, -2
br label %7
26: ; preds = %7
%27 = getelementptr inbounds i8, i8* %3, i64 19
store i8 0, i8* %27
%28 = tail call i32 @strlen(i8* %3)
%29 = sub nsw i32 49, %28
%30 = sdiv i32 %29, 2
%31 = tail call i64 @floor(i32 %30)
%32 = trunc i64 %31 to i32
%33 = add i32 %32, 1
%34 = tail call i8* @malloc(i32 %33)
%35 = icmp eq i8* %34, null
br i1 %35, label %41, label %36
36: ; preds = %26
%37 = icmp sgt i32 %32, 0
br i1 %37, label %38, label %44
38: ; preds = %36
%39 = and i64 %31, 4294967295
%40 = and i64 %31, 4294967295
br label %44
41: ; preds = %26
%42 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.1, i64 0, i64 0))
%43 = tail call i32 @free(i8* %3)
br label %52
44: ; preds = %38, %36
%45 = phi i64 [ 0, %36 ], [ %40, %38 ]
%46 = getelementptr inbounds i8, i8* %34, i64 %45
store i8 0, i8* %46
%47 = tail call i32 @strcpy(i8* %0, i8* %34)
%48 = tail call i32 @strcat(i8* %0, i8* %3)
%49 = tail call i32 @strcat(i8* %0, i8* %34)
%50 = tail call i32 @free(i8* %3)
%51 = tail call i32 @free(i8* %34)
br label %52
52: ; preds = %41, %5, %44
%53 = phi i32 [ 1, %5 ], [ 0, %44 ], [ 1, %41 ]
ret i32 %53
}