#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int *calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int find_number_of_prefixs(char **, int);
int find_number_of_suffixs(char **, int);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ histogram(char **, int *, int);
int write_data(char **strings, const char *filename, int size) {
  FILE *fp = fopen(filename, "w");
  int *hist = calloc(25, sizeof(int));
  histogram(strings, hist, size);
  int prefix_num = find_number_of_prefixs(strings, size);
  int suffix_num = find_number_of_suffixs(strings, size);
  int i = 0;
  int j = 0;
  for (; i < 25; ++i) {
    if (!hist[i]) {
      continue;
    }
    fprintf(fp, "Number of names with %d characters: ", i);
    for (j = 0; j < hist[i]; ++j) {
      fprintf(fp, "*");
    }
    fprintf(fp, "\n");
  }
  fprintf(fp, "Number of names with prefix of ma are %d", prefix_num);
  fprintf(fp, "\nNumber of names with suffix of an are %d\n", suffix_num);
  free(hist);
  fclose(fp);
}


x86 assembly (clang, -O0):
<write_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    $0x19,%edi
mov    $0x4,%esi
call   1070 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1050 <histogram@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1040 <find_number_of_prefixs@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1090 <find_number_of_suffixs@plt>
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x19,-0x3c(%rbp)
jge    1287 <write_data+0x107>
mov    -0x30(%rbp),%rax
movslq -0x3c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    1217 <write_data+0x97>
jmp    1279 <write_data+0xf9>
mov    -0x28(%rbp),%rdi
mov    -0x3c(%rbp),%edx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
mov    -0x30(%rbp),%rcx
movslq -0x3c(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1267 <write_data+0xe7>
mov    -0x28(%rbp),%rdi
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1233 <write_data+0xb3>
mov    -0x28(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f6 <write_data+0x76>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%edx
lea    0xd94(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%edx
lea    0xda8(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rax
mov    %rdi,%rbp
lea    0xe55(%rip),%rsi
mov    %rax,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r14
mov    $0x19,%edi
mov    $0x4,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1050 <histogram@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
call   1040 <find_number_of_prefixs@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
mov    %r15d,%esi
call   10a0 <find_number_of_suffixs@plt>
mov    %eax,0x4(%rsp)
lea    0xe08(%rip),%r13
xor    %ebp,%ebp
jmp    1217 <write_data+0x87>
xchg   %ax,%ax
mov    $0xa,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
add    $0x1,%rbp
cmp    $0x19,%rbp
je     1259 <write_data+0xc9>
cmpl   $0x0,(%rbx,%rbp,4)
je     120d <write_data+0x7d>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
cmpl   $0x0,(%rbx,%rbp,4)
jle    1200 <write_data+0x70>
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x2a,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
add    $0x1,%r15d
cmp    (%rbx,%rbp,4),%r15d
jl     1240 <write_data+0xb0>
jmp    1200 <write_data+0x70>
lea    0xdc7(%rip),%rsi
mov    %r14,%rdi
mov    %r12d,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
lea    0xddc(%rip),%rsi
mov    %r14,%rdi
mov    0x4(%rsp),%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [37 x i8] c"Number of names with %d characters: \00"
@.str.2 = [2 x i8] c"*\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [41 x i8] c"Number of names with prefix of ma are %d\00"
@.str.5 = [43 x i8] c"\0ANumber of names with suffix of an are %d\0A\00"
define i32 @write_data(i8** %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%14 = load i8*, i8** %6
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = call i32* @calloc(i32 25, i32 4)
store i32* %16, i32** %9
%17 = load i8**, i8*** %5
%18 = load i32*, i32** %9
%19 = load i32, i32* %7
%20 = call i32 @histogram(i8** %17, i32* %18, i32 %19)
%21 = load i8**, i8*** %5
%22 = load i32, i32* %7
%23 = call i32 @find_number_of_prefixs(i8** %21, i32 %22)
store i32 %23, i32* %10
%24 = load i8**, i8*** %5
%25 = load i32, i32* %7
%26 = call i32 @find_number_of_suffixs(i8** %24, i32 %25)
store i32 %26, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
br label %27
27: ; preds = %59, %3
%28 = load i32, i32* %12
%29 = icmp slt i32 %28, 25
br i1 %29, label %30, label %62
30: ; preds = %27
%31 = load i32*, i32** %9
%32 = load i32, i32* %12
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %30
br label %59
38: ; preds = %30
%39 = load i32*, i32** %8
%40 = load i32, i32* %12
%41 = call i32 (i32*, i8*, ...) @fprintf(i32* %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %40)
store i32 0, i32* %13
br label %42
42: ; preds = %53, %38
%43 = load i32, i32* %13
%44 = load i32*, i32** %9
%45 = load i32, i32* %12
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i32, i32* %44, i64 %46
%48 = load i32, i32* %47
%49 = icmp slt i32 %43, %48
br i1 %49, label %50, label %56
50: ; preds = %42
%51 = load i32*, i32** %8
%52 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %53
53: ; preds = %50
%54 = load i32, i32* %13
%55 = add nsw i32 %54, 1
store i32 %55, i32* %13
br label %42
56: ; preds = %42
%57 = load i32*, i32** %8
%58 = call i32 (i32*, i8*, ...) @fprintf(i32* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %56, %37
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
store i32 %61, i32* %12
br label %27
62: ; preds = %27
%63 = load i32*, i32** %8
%64 = load i32, i32* %10
%65 = call i32 (i32*, i8*, ...) @fprintf(i32* %63, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %64)
%66 = load i32*, i32** %8
%67 = load i32, i32* %11
%68 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %67)
%69 = load i32*, i32** %9
%70 = call i32 @free(i32* %69)
%71 = load i32*, i32** %8
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* %4
ret i32 %73
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [37 x i8] c"Number of names with %d characters: \00"
@.str.4 = [41 x i8] c"Number of names with prefix of ma are %d\00"
@.str.5 = [43 x i8] c"\0ANumber of names with suffix of an are %d\0A\00"
define i32 @write_data(i8** %0, i8* nocapture %1, i32 %2) {
%4 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @calloc(i32 25, i32 4)
%6 = tail call i32 @histogram(i8** %0, i32* %5, i32 %2)
%7 = tail call i32 @find_number_of_prefixs(i8** %0, i32 %2)
%8 = tail call i32 @find_number_of_suffixs(i8** %0, i32 %2)
br label %9
9: ; preds = %3, %27
%10 = phi i64 [ 0, %3 ], [ %28, %27 ]
%11 = getelementptr inbounds i32, i32* %5, i64 %10
%12 = load i32, i32* %11
%13 = icmp eq i32 %12, 0
br i1 %13, label %27, label %14
14: ; preds = %9
%15 = trunc i64 %10 to i32
%16 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %11
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %14, %19
%20 = phi i32 [ %22, %19 ], [ 0, %14 ]
%21 = tail call i32 @fputc(i32 42, i32* %4)
%22 = add nuw nsw i32 %20, 1
%23 = load i32, i32* %11
%24 = icmp slt i32 %22, %23
br i1 %24, label %19, label %25
25: ; preds = %19, %14
%26 = tail call i32 @fputc(i32 10, i32* %4)
br label %27
27: ; preds = %9, %25
%28 = add nuw nsw i64 %10, 1
%29 = icmp eq i64 %28, 25
br i1 %29, label %30, label %9
30: ; preds = %27
%31 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i32 %7)
%32 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %4, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0), i32 %8)
%33 = tail call i32 @free(i32* %5)
%34 = tail call i32 @fclose(i32* %4)
ret i32 undef
}