#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int random();
void main(const int argc, char *argv[]) {
  FILE *file;
  int i;
  int my_random;
  int size;
  char *cp;
  if (argc != 3) {
    printf("usage: %s file_size_in_bytes[K|M] name\n", argv[0]);
    exit(2);
  }
  if ((file = fopen(argv[2], "w")) == 0) {
    perror("fopen");
    exit(1);
  }
  size = atoi(argv[1]);
  for (cp = argv[1]; *cp; cp++) {
    switch (*cp) {
    case 'k':
    case 'K':
      size *= 1024;
      break;
    case 'm':
    case 'M':
      size *= 1024 * 1024;
      break;
    }
  }
  for (i = 0; i < size; i++) {
    my_random = ((random() % 94) + 33);
    fputc((char)my_random, file);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x4(%rbp)
je     11b6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xee5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xeef(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11ee <main+0x6e>
lea    0xed7(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmpb   $0x0,(%rax)
je     1271 <main+0xf1>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
add    $0xffffffb5,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x22,%eax
ja     125b <main+0xdb>
mov    -0x38(%rbp),%rax
lea    0xdc5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x24(%rbp),%eax
shl    $0xa,%eax
mov    %eax,-0x24(%rbp)
jmp    125b <main+0xdb>
mov    -0x24(%rbp),%eax
shl    $0x14,%eax
mov    %eax,-0x24(%rbp)
jmp    1260 <main+0xe0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    120a <main+0x8a>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    12b6 <main+0x136>
mov    $0x0,%al
call   1060 <random@plt>
mov    $0x5e,%ecx
cltd
idiv   %ecx
add    $0x21,%edx
mov    %edx,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1050 <fputc@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1278 <main+0xf8>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1243 <main+0xc3>
mov    0x10(%rbx),%rdi
lea    0xf19(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     125c <main+0xdc>
mov    %rax,%r14
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1090 <atoi@plt>
mov    %eax,%ebp
mov    (%rbx),%cl
test   %cl,%cl
je     11f7 <main+0x77>
add    $0x1,%rbx
lea    0xe35(%rip),%rax
jmp    11de <main+0x5e>
nopl   (%rax)
shl    $0x14,%ebp
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
je     11f7 <main+0x77>
movsbl %cl,%ecx
add    $0xffffffb5,%ecx
cmp    $0x22,%ecx
ja     11d3 <main+0x53>
movslq (%rax,%rcx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
shl    $0xa,%ebp
jmp    11d3 <main+0x53>
test   %ebp,%ebp
jle    1237 <main+0xb7>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <random@plt>
cltq
imul   $0xffffffffae4c415d,%rax,%rcx
shr    $0x20,%rcx
add    %eax,%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
shr    $0x6,%ecx
add    %edx,%ecx
imul   $0x5e,%ecx,%ecx
sub    %ecx,%eax
add    $0x21,%al
movsbl %al,%edi
mov    %r14,%rsi
call   1050 <fputc@plt>
add    $0xffffffff,%ebp
jne    1200 <main+0x80>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <fclose@plt>
mov    (%rbx),%rsi
lea    0xe3f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe53(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [40 x i8] c"usage: %s file_size_in_bytes[K|M] name\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%10 = load i32, i32* %3
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 2)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 2
%21 = load i8*, i8** %20
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %5
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %18
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
store i32 %31, i32* %8
%32 = load i8**, i8*** %4
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %9
br label %35
35: ; preds = %50, %27
%36 = load i8*, i8** %9
%37 = load i8, i8* %36
%38 = icmp ne i8 %37, 0
br i1 %38, label %39, label %53
39: ; preds = %35
%40 = load i8*, i8** %9
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
switch i32 %42, label %49 [
i32 107, label %43
i32 75, label %43
i32 109, label %46
i32 77, label %46
]
43: ; preds = %39, %39
%44 = load i32, i32* %8
%45 = mul nsw i32 %44, 1024
store i32 %45, i32* %8
br label %49
46: ; preds = %39, %39
%47 = load i32, i32* %8
%48 = mul nsw i32 %47, 1048576
store i32 %48, i32* %8
br label %49
49: ; preds = %39, %46, %43
br label %50
50: ; preds = %49
%51 = load i8*, i8** %9
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %9
br label %35
53: ; preds = %35
store i32 0, i32* %6
br label %54
54: ; preds = %66, %53
%55 = load i32, i32* %6
%56 = load i32, i32* %8
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %69
58: ; preds = %54
%59 = call i32 (...) @random()
%60 = srem i32 %59, 94
%61 = add nsw i32 %60, 33
store i32 %61, i32* %7
%62 = load i32, i32* %7
%63 = trunc i32 %62 to i8
%64 = load i32*, i32** %5
%65 = call i32 @fputc(i8 signext %63, i32* %64)
br label %66
66: ; preds = %58
%67 = load i32, i32* %6
%68 = add nsw i32 %67, 1
store i32 %68, i32* %6
br label %54
69: ; preds = %54
%70 = load i32*, i32** %5
%71 = call i32 @fclose(i32* %70)
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"usage: %s file_size_in_bytes[K|M] name\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [6 x i8] c"fopen\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = load i8, i8* %18
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %34, %16
%23 = phi i32 [ %19, %16 ], [ %35, %34 ]
%24 = icmp sgt i32 %23, 0
br i1 %24, label %39, label %48
25: ; preds = %16, %34
%26 = phi i8 [ %37, %34 ], [ %20, %16 ]
%27 = phi i8* [ %36, %34 ], [ %18, %16 ]
%28 = phi i32 [ %35, %34 ], [ %19, %16 ]
%29 = sext i8 %26 to i32
switch i32 %29, label %34 [
i32 107, label %30
i32 75, label %30
i32 109, label %32
i32 77, label %32
]
30: ; preds = %25, %25
%31 = shl nsw i32 %28, 10
br label %34
32: ; preds = %25, %25
%33 = shl nsw i32 %28, 20
br label %34
34: ; preds = %30, %32, %25
%35 = phi i32 [ %28, %25 ], [ %33, %32 ], [ %31, %30 ]
%36 = getelementptr inbounds i8, i8* %27, i64 1
%37 = load i8, i8* %36
%38 = icmp eq i8 %37, 0
br i1 %38, label %22, label %25
39: ; preds = %22, %39
%40 = phi i32 [ %46, %39 ], [ 0, %22 ]
%41 = tail call i32 (...) @random()
%42 = srem i32 %41, 94
%43 = trunc i32 %42 to i8
%44 = add nsw i8 %43, 33
%45 = tail call i32 @fputc(i8 signext %44, i32* %11)
%46 = add nuw nsw i32 %40, 1
%47 = icmp eq i32 %46, %23
br i1 %47, label %48, label %39
48: ; preds = %39, %22
%49 = tail call i32 @fclose(i32* %11)
ret void
}