#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 */
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ S_IRUSR;
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ malloc(int);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
char rand();
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int fd, i, n;
  char *buff;
  if (argc != 3) {
    printf("Usage: %s filename filesize\n", argv[0]);
    return 1;
  }
  fd = open(argv[1], O_CREAT | O_WRONLY | O_TRUNC, S_IRUSR);
  if (fd < 0) {
    printf("Cannot open the file!");
    return 1;
  }
  n = atoi(argv[2]);
  buff = (char *)malloc(n);
  for (i = 0; i < n; i++) {
    buff[i] = 'a' + rand() % ('z' - 'a');
  }
  write(fd, buff, n);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    0x2df7(%rip),%rax
or     (%rax),%esi
mov    0x2e1e(%rip),%rax
or     (%rax),%esi
mov    0x2df5(%rip),%rax
mov    (%rax),%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1209 <main+0x99>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1284 <main+0x114>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1266 <main+0xf6>
mov    $0x0,%al
call   1090 <rand@plt>
movsbl %al,%eax
mov    $0x19,%ecx
cltd
idiv   %ecx
add    $0x61,%edx
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    122c <main+0xbc>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    122f <main+0xbf>
mov    0x8(%rbx),%rdi
mov    0x2e69(%rip),%rax
mov    0x2e2a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e4f(%rip),%rax
or     (%rax),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
call   1070 <open@plt>
test   %eax,%eax
js     1242 <main+0xd2>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1080 <atoi@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
test   %r15d,%r15d
jle    1215 <main+0xa5>
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1090 <rand@plt>
movsbl %al,%eax
lea    (%rax,%rax,4),%ecx
lea    (%rax,%rcx,8),%ecx
movzwl %cx,%edx
shr    $0xa,%ecx
shr    $0xf,%edx
add    %cl,%dl
movzbl %dl,%ecx
lea    (%rcx,%rcx,4),%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %cl,%al
add    $0x61,%al
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <main+0x70>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %r15d,%edx
call   1030 <write@plt>
mov    %r14d,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1255 <main+0xe5>
mov    (%rbx),%rsi
lea    0xdc7(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1250 <main+0xe0>
lea    0xdd4(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: %s filename filesize\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@.str.1 = [22 x i8] c"Cannot open the file!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 3
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %15)
store i32 1, i32* %3
br label %64
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_CREAT
%22 = load i32, i32* @O_WRONLY
%23 = or i32 %21, %22
%24 = load i32, i32* @O_TRUNC
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IRUSR
%27 = call i32 @open(i8* %20, i32 %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %64
32: ; preds = %17
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = call i64 @malloc(i32 %37)
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %9
store i32 0, i32* %7
br label %40
40: ; preds = %54, %32
%41 = load i32, i32* %7
%42 = load i32, i32* %8
%43 = icmp slt i32 %41, %42
br i1 %43, label %44, label %57
44: ; preds = %40
%45 = call signext i8 (...) @rand()
%46 = sext i8 %45 to i32
%47 = srem i32 %46, 25
%48 = add nsw i32 97, %47
%49 = trunc i32 %48 to i8
%50 = load i8*, i8** %9
%51 = load i32, i32* %7
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 %49, i8* %53
br label %54
54: ; preds = %44
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %40
57: ; preds = %40
%58 = load i32, i32* %6
%59 = load i8*, i8** %9
%60 = load i32, i32* %8
%61 = call i32 @write(i32 %58, i8* %59, i32 %60)
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
store i32 0, i32* %3
br label %64
64: ; preds = %57, %30, %12
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: %s filename filesize\0A\00"
@O_CREAT = global i32 0
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@.str.1 = [22 x i8] c"Cannot open the file!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 3
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %40
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_CREAT
%11 = load i32, i32* @O_WRONLY
%12 = or i32 %11, %10
%13 = load i32, i32* @O_TRUNC
%14 = or i32 %12, %13
%15 = load i32, i32* @S_IRUSR
%16 = tail call i32 @open(i8* %9, i32 %14, i32 %15)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %7
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %40
20: ; preds = %7
%21 = getelementptr inbounds i8*, i8** %1, i64 2
%22 = load i8*, i8** %21
%23 = tail call i32 @atoi(i8* %22)
%24 = tail call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = icmp sgt i32 %23, 0
br i1 %26, label %27, label %37
27: ; preds = %20
%28 = zext i32 %23 to i64
br label %29
29: ; preds = %27, %29
%30 = phi i64 [ 0, %27 ], [ %35, %29 ]
%31 = tail call signext i8 (...) @rand()
%32 = srem i8 %31, 25
%33 = add nsw i8 %32, 97
%34 = getelementptr inbounds i8, i8* %25, i64 %30
store i8 %33, i8* %34
%35 = add nuw nsw i64 %30, 1
%36 = icmp eq i64 %35, %28
br i1 %36, label %37, label %29
37: ; preds = %29, %20
%38 = tail call i32 @write(i32 %16, i8* %25, i32 %23)
%39 = tail call i32 @close(i32 %16)
br label %40
40: ; preds = %37, %18, %4
%41 = phi i32 [ 1, %4 ], [ 1, %18 ], [ 0, %37 ]
ret i32 %41
}