#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 atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fd, size, count, i;
  char *buffer;
  if (argc != 3) {
    printf("usage: %s blocksize blockcount\n", argv[0]);
    exit(1);
  }
  if ((fd = open("rawio.out", O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0) {
    perror("rawio.out");
    exit(2);
  }
  size = atoi(argv[1]);
  count = atoi(argv[2]);
  buffer = malloc(size);
  for (i = 0; i < count; ++i) {
    write(fd, buffer, size);
  }
  free(buffer);
  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     11cd <main+0x3d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe42(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%esi
mov    0x2e1b(%rip),%rax
or     (%rax),%esi
mov    0x2e0a(%rip),%rax
or     (%rax),%esi
lea    0xe31(%rip),%rdi
mov    $0x180,%edx
call   1080 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    121b <main+0x8b>
lea    0xe14(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1277 <main+0xe7>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <write@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    124e <main+0xbe>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
cmp    $0x3,%edi
jne    122e <main+0x9e>
mov    0x2e1d(%rip),%rax
mov    0x2e46(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e33(%rip),%rax
or     (%rax),%esi
lea    0xe5a(%rip),%rdi
mov    $0x180,%edx
call   1080 <open@plt>
test   %eax,%eax
js     1247 <main+0xb7>
mov    %eax,%r15d
mov    0x8(%r14),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
mov    0x10(%r14),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebx
mov    %r12d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %ebx,%ebx
jle    1213 <main+0x83>
nopl   (%rax)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1040 <write@plt>
add    $0xffffffff,%ebx
jne    1200 <main+0x70>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%rsi
lea    0xdc8(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdd2(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"usage: %s blocksize blockcount\0A\00"
@.str.1 = [10 x i8] c"rawio.out\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
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 i32
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %19
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %20, %21
%23 = load i32, i32* @O_TRUNC
%24 = or i32 %22, %23
%25 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 384)
store i32 %25, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%29 = call i32 @exit(i32 2)
unreachable
30: ; preds = %19
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %8
%39 = load i32, i32* %7
%40 = call i8* @malloc(i32 %39)
store i8* %40, i8** %10
store i32 0, i32* %9
br label %41
41: ; preds = %50, %30
%42 = load i32, i32* %9
%43 = load i32, i32* %8
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i32, i32* %6
%47 = load i8*, i8** %10
%48 = load i32, i32* %7
%49 = call i32 @write(i32 %46, i8* %47, i32 %48)
br label %50
50: ; preds = %45
%51 = load i32, i32* %9
%52 = add nsw i32 %51, 1
store i32 %52, i32* %9
br label %41
53: ; preds = %41
%54 = load i8*, i8** %10
%55 = call i32 @free(i8* %54)
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"usage: %s blocksize blockcount\0A\00"
@.str.1 = [10 x i8] c"rawio.out\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
define i32 @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 ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = load i32, i32* @O_WRONLY
%10 = load i32, i32* @O_CREAT
%11 = or i32 %10, %9
%12 = load i32, i32* @O_TRUNC
%13 = or i32 %11, %12
%14 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 384)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %8
%17 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 2)
unreachable
19: ; preds = %8
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = tail call i8* @malloc(i32 %22)
%27 = icmp sgt i32 %25, 0
br i1 %27, label %28, label %33
28: ; preds = %19, %28
%29 = phi i32 [ %31, %28 ], [ 0, %19 ]
%30 = tail call i32 @write(i32 %14, i8* %26, i32 %22)
%31 = add nuw nsw i32 %29, 1
%32 = icmp eq i32 %31, %25
br i1 %32, label %33, label %28
33: ; preds = %28, %19
%34 = tail call i32 @free(i8* %26)
%35 = tail call i32 @close(i32 %14)
ret i32 0
}