#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ filter(char *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int rand();
char *makestring() {
  char *tmp;
  int len = (rand() % 5) + 4, i;
  FILE *file;
  tmp = (char *)malloc(len + 1);
  memset(tmp, 0, len + 1);
  if ((file = fopen("/usr/dict/words", "r")) == NULL)
    for (i = 0; i < len; i++)
      tmp[i] = (rand() % (91 - 65)) + 65;
  else {
    int a = ((rand() * rand()) % 45402) + 1;
    char buf[1024];
    for (i = 0; i < a; i++)
      fgets(buf, 1024, file);
    memset(buf, 0, 1024);
    fgets(buf, 1024, file);
    filter(buf);
    memcpy(tmp, buf, len);
    fclose(file);
  }
  return tmp;
}


x86 assembly (clang, -O0):
<makestring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x5,%ecx
cltd
idiv   %ecx
add    $0x4,%edx
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
add    $0x1,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0xe39(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1224 <makestring+0xa4>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121f <makestring+0x9f>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    $0x1a,%ecx
cltd
idiv   %ecx
add    $0x41,%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11e8 <makestring+0x68>
jmp    12d7 <makestring+0x157>
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,-0x424(%rbp)
mov    $0x0,%al
call   10a0 <rand@plt>
mov    %eax,%ecx
mov    -0x424(%rbp),%eax
imul   %ecx,%eax
mov    $0xb15a,%ecx
cltd
idiv   %ecx
add    $0x1,%edx
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1287 <makestring+0x107>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1258 <makestring+0xd8>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
lea    -0x420(%rbp),%rdi
call   1040 <filter@plt>
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<makestring>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%ecx
mov    %eax,%ebp
sub    %ecx,%ebp
lea    0x4(%rbp),%r14d
neg    %ecx
lea    (%rax,%rcx,1),%ebx
add    $0x5,%ebx
mov    %ebx,%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1050 <memset@plt>
lea    0xe24(%rip),%rdi
lea    0xe2d(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1297 <makestring+0x117>
mov    %rax,%r12
xor    %eax,%eax
call   10a0 <rand@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10a0 <rand@plt>
imul   %ebx,%eax
movslq %eax,%rbp
imul   $0xffffffffb8c3517b,%rbp,%rax
shr    $0x20,%rax
add    %ebp,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
sar    $0xf,%eax
add    %ecx,%eax
imul   $0xb15a,%eax,%eax
sub    %eax,%ebp
js     1255 <makestring+0xd5>
add    $0x1,%ebp
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
add    $0xffffffff,%ebp
jne    1240 <makestring+0xc0>
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r12,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <filter@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
call   1030 <fclose@plt>
jmp    12e6 <makestring+0x166>
cmp    $0xfffffffd,%ebp
jl     12e6 <makestring+0x166>
mov    %r14d,%ebx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   10a0 <rand@plt>
cltq
imul   $0x4ec4ec4f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x23,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,4),%edx
lea    (%rdx,%rdx,4),%edx
add    %ecx,%edx
sub    %edx,%eax
add    $0x41,%al
mov    %al,(%r15,%rbp,1)
add    $0x1,%rbp
cmp    %rbp,%rbx
jne    12b0 <makestring+0x130>
mov    %r15,%rax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/usr/dict/words\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @makestring() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 5
%9 = add nsw i32 %8, 4
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = add nsw i32 %10, 1
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %1
%14 = load i8*, i8** %1
%15 = load i32, i32* %2
%16 = add nsw i32 %15, 1
%17 = call i32 @memset(i8* %14, i32 0, i32 %16)
%18 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %4
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %38
20: ; preds = %0
store i32 0, i32* %3
br label %21
21: ; preds = %34, %20
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 26
%28 = add nsw i32 %27, 65
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %1
%31 = load i32, i32* %3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 %29, i8* %33
br label %34
34: ; preds = %25
%35 = load i32, i32* %3
%36 = add nsw i32 %35, 1
store i32 %36, i32* %3
br label %21
37: ; preds = %21
br label %69
38: ; preds = %0
%39 = call i32 (...) @rand()
%40 = call i32 (...) @rand()
%41 = mul nsw i32 %39, %40
%42 = srem i32 %41, 45402
%43 = add nsw i32 %42, 1
store i32 %43, i32* %5
store i32 0, i32* %3
br label %44
44: ; preds = %52, %38
%45 = load i32, i32* %3
%46 = load i32, i32* %5
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %55
48: ; preds = %44
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = load i32*, i32** %4
%51 = call i32 @fgets(i8* %49, i32 1024, i32* %50)
br label %52
52: ; preds = %48
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %44
55: ; preds = %44
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%57 = call i32 @memset(i8* %56, i32 0, i32 1024)
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%59 = load i32*, i32** %4
%60 = call i32 @fgets(i8* %58, i32 1024, i32* %59)
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%62 = call i32 @filter(i8* %61)
%63 = load i8*, i8** %1
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%65 = load i32, i32* %2
%66 = call i32 @memcpy(i8* %63, i8* %64, i32 %65)
%67 = load i32*, i32** %4
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %55, %37
%70 = load i8*, i8** %1
ret i8* %70
}

LLVM IR (-O2):
@.str = [16 x i8] c"/usr/dict/words\00"
@.str.1 = [2 x i8] c"r\00"
define i8* @makestring() {
%1 = alloca [1024 x i8]
%2 = tail call i32 (...) @rand()
%3 = srem i32 %2, 5
%4 = add nsw i32 %3, 4
%5 = add nsw i32 %3, 5
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = tail call i32 @memset(i8* %7, i32 0, i32 %5)
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %0
%12 = icmp sgt i32 %3, -4
br i1 %12, label %13, label %42
13: ; preds = %11
%14 = zext i32 %4 to i64
br label %15
15: ; preds = %13, %15
%16 = phi i64 [ 0, %13 ], [ %22, %15 ]
%17 = tail call i32 (...) @rand()
%18 = srem i32 %17, 26
%19 = trunc i32 %18 to i8
%20 = add nsw i8 %19, 65
%21 = getelementptr inbounds i8, i8* %7, i64 %16
store i8 %20, i8* %21
%22 = add nuw nsw i64 %16, 1
%23 = icmp eq i64 %22, %14
br i1 %23, label %42, label %15
24: ; preds = %0
%25 = tail call i32 (...) @rand()
%26 = tail call i32 (...) @rand()
%27 = mul nsw i32 %26, %25
%28 = srem i32 %27, 45402
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%30 = icmp slt i32 %28, 0
br i1 %30, label %36, label %31
31: ; preds = %24, %31
%32 = phi i32 [ %34, %31 ], [ 0, %24 ]
%33 = call i32 @fgets(i8* %29, i32 1024, i32* %9)
%34 = add nuw nsw i32 %32, 1
%35 = icmp eq i32 %32, %28
br i1 %35, label %36, label %31
36: ; preds = %31, %24
%37 = call i32 @memset(i8* %29, i32 0, i32 1024)
%38 = call i32 @fgets(i8* %29, i32 1024, i32* %9)
%39 = call i32 @filter(i8* %29)
%40 = call i32 @memcpy(i8* %7, i8* %29, i32 %4)
%41 = call i32 @fclose(i32* %9)
br label %42
42: ; preds = %15, %11, %36
ret i8* %7
}