#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fwrite(char *, int, int, int /*<<< orphan*/ *);
char getopt(int, char **, char *);
int /*<<< orphan*/ make_block(unsigned int, char *);
char *optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printusage(int, char **);
int main(int argc, char *argv[]) {
  FILE *fp;
  unsigned int blk_count, i;
  char block[512];
  char c;
  blk_count = 0;
  if (argc != 5) {
    printusage(argc, argv);
    exit(0);
  }
  while ((c = getopt(argc, argv, "n:f:h")) != -1) {
    switch (c) {
    case 'n':
      blk_count = atoi(optarg);
      printf("Writing %d blocks...\n", blk_count);
      break;
    case 'f':
      fp = fopen(optarg, "w");
      if (fp == NULL) {
        printf("Could not create file: '%s'\n", optarg);
        exit(1);
      }
      break;
    case 'h':
      printusage(argc, argv);
      exit(0);
      break;
    }
  }
  if (fp == NULL) {
    printf("Must specify filename!\n");
    exit(1);
  }
  if (blk_count == 0) {
    printf("Must specify block count!\n");
    exit(1);
  }
  for (i = 0; i < blk_count; i++) {
    make_block(i, block);
    if (fwrite(block, 512, 1, fp) <= 0) {
      printf("Error saving block %d!\n", i);
      exit(1);
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11cd <main+0x3d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <printusage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    11d2 <main+0x42>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe20(%rip),%rdx
call   1080 <getopt@plt>
mov    %al,-0x221(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     12c6 <main+0x136>
movsbl -0x221(%rbp),%eax
mov    %eax,-0x228(%rbp)
sub    $0x66,%eax
je     1262 <main+0xd2>
jmp    1212 <main+0x82>
mov    -0x228(%rbp),%eax
sub    $0x68,%eax
je     12ae <main+0x11e>
jmp    1226 <main+0x96>
mov    -0x228(%rbp),%eax
sub    $0x6e,%eax
jne    12c1 <main+0x131>
jmp    123a <main+0xaa>
mov    0x2db7(%rip),%rax
mov    (%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
lea    0xdb0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12c1 <main+0x131>
mov    0x2d8f(%rip),%rax
mov    (%rax),%rdi
lea    0xda9(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12a9 <main+0x119>
mov    0x2d6a(%rip),%rax
mov    (%rax),%rsi
lea    0xd86(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12c1 <main+0x131>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1060 <printusage@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    11d2 <main+0x42>
cmpq   $0x0,-0x18(%rbp)
jne    12e9 <main+0x159>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    130b <main+0x17b>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    137f <main+0x1ef>
mov    -0x20(%rbp),%edi
lea    -0x220(%rbp),%rsi
call   1040 <make_block@plt>
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x200,%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
cmp    $0x0,%rax
jg     136c <main+0x1dc>
mov    -0x20(%rbp),%esi
lea    0xd13(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1371 <main+0x1e1>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1312 <main+0x182>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%r14
cmp    $0x5,%edi
jne    1307 <main+0x167>
lea    0xe3c(%rip),%rdx
mov    $0x5,%edi
mov    %r14,%rsi
call   1090 <getopt@plt>
cmp    $0xff,%al
je     1316 <main+0x176>
mov    0x2e18(%rip),%rbp
lea    0xe19(%rip),%r12
lea    0xe18(%rip),%rbx
xor    %r15d,%r15d
jmp    122c <main+0x8c>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%rbp),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x5,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1090 <getopt@plt>
cmp    $0xff,%al
je     1284 <main+0xe4>
movsbl %al,%eax
cmp    $0x66,%eax
je     1250 <main+0xb0>
cmp    $0x6e,%eax
je     1200 <main+0x60>
cmp    $0x68,%eax
jne    1218 <main+0x78>
jmp    1302 <main+0x162>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x0(%rbp),%rdi
lea    0xdc1(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1218 <main+0x78>
mov    0x0(%rbp),%rsi
lea    0xdab(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
test   %r13,%r13
je     1316 <main+0x176>
test   %r15d,%r15d
je     131f <main+0x17f>
xor    %ebp,%ebp
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <make_block@plt>
mov    %rbx,%rdi
mov    $0x200,%esi
mov    $0x1,%edx
mov    %r13,%rcx
call   10c0 <fwrite@plt>
test   %rax,%rax
jle    12e8 <main+0x148>
add    $0x1,%ebp
cmp    %ebp,%r15d
jne    12a0 <main+0x100>
mov    %r13,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd4c(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    $0x5,%edi
mov    %r14,%rsi
call   1070 <printusage@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
lea    0xd50(%rip),%rdi
jmp    1326 <main+0x186>
lea    0xd2d(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"n:f:h\00"
@optarg = global i8* null
@.str.1 = [22 x i8] c"Writing %d blocks...\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [29 x i8] c"Could not create file: '%s'\0A\00"
@.str.4 = [24 x i8] c"Must specify filename!\0A\00"
@.str.5 = [27 x i8] c"Must specify block count!\0A\00"
@.str.6 = [24 x i8] c"Error saving block %d!\0A\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 [512 x i8]
%10 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 5
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* %4
%15 = load i8**, i8*** %5
%16 = call i32 @printusage(i32 %14, i8** %15)
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %48, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call signext i8 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i8 %22, i8* %10
%23 = sext i8 %22 to i32
%24 = icmp ne i32 %23, -1
br i1 %24, label %25, label %49
25: ; preds = %19
%26 = load i8, i8* %10
%27 = sext i8 %26 to i32
switch i32 %27, label %48 [
i32 110, label %28
i32 102, label %33
i32 104, label %43
]
28: ; preds = %25
%29 = load i8*, i8** @optarg
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %31)
br label %48
33: ; preds = %25
%34 = load i8*, i8** @optarg
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %35, i32** %6
%36 = load i32*, i32** %6
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %42
38: ; preds = %33
%39 = load i8*, i8** @optarg
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33
br label %48
43: ; preds = %25
%44 = load i32, i32* %4
%45 = load i8**, i8*** %5
%46 = call i32 @printusage(i32 %44, i8** %45)
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %25, %42, %28
br label %19
49: ; preds = %19
%50 = load i32*, i32** %6
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %49
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %49
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %55
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %55
store i32 0, i32* %8
br label %62
62: ; preds = %79, %61
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = icmp ult i32 %63, %64
br i1 %65, label %66, label %82
66: ; preds = %62
%67 = load i32, i32* %8
%68 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%69 = call i32 @make_block(i32 %67, i8* %68)
%70 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%71 = load i32*, i32** %6
%72 = call i64 @fwrite(i8* %70, i32 512, i32 1, i32* %71)
%73 = icmp sle i64 %72, 0
br i1 %73, label %74, label %78
74: ; preds = %66
%75 = load i32, i32* %8
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %66
br label %79
79: ; preds = %78
%80 = load i32, i32* %8
%81 = add i32 %80, 1
store i32 %81, i32* %8
br label %62
82: ; preds = %62
%83 = load i32*, i32** %6
%84 = call i32 @fclose(i32* %83)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"n:f:h\00"
@optarg = global i8* null
@.str.1 = [22 x i8] c"Writing %d blocks...\0A\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [29 x i8] c"Could not create file: '%s'\0A\00"
@.str.6 = [24 x i8] c"Error saving block %d!\0A\00"
@str = [26 x i8] c"Must specify block count!\00"
@str.7 = [23 x i8] c"Must specify filename!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = icmp eq i32 %0, 5
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = tail call signext i8 @getopt(i32 5, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i8 %7, -1
br i1 %8, label %39, label %12
9: ; preds = %2
%10 = tail call i32 @printusage(i32 %0, i8** %1)
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %6, %32
%13 = phi i8 [ %35, %32 ], [ %7, %6 ]
%14 = phi i32* [ %34, %32 ], [ undef, %6 ]
%15 = phi i32 [ %33, %32 ], [ 0, %6 ]
%16 = sext i8 %13 to i32
switch i32 %16, label %32 [
i32 110, label %17
i32 102, label %21
i32 104, label %29
]
17: ; preds = %12
%18 = load i8*, i8** @optarg
%19 = tail call i32 @atoi(i8* %18)
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %19)
br label %32
21: ; preds = %12
%22 = load i8*, i8** @optarg
%23 = tail call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = load i8*, i8** @optarg
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %12
%30 = tail call i32 @printusage(i32 5, i8** %1)
%31 = tail call i32 @exit(i32 0)
unreachable
32: ; preds = %21, %12, %17
%33 = phi i32 [ %15, %12 ], [ %15, %21 ], [ %19, %17 ]
%34 = phi i32* [ %14, %12 ], [ %23, %21 ], [ %14, %17 ]
%35 = tail call signext i8 @getopt(i32 5, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%36 = icmp eq i8 %35, -1
br i1 %36, label %37, label %12
37: ; preds = %32
%38 = icmp eq i32* %34, null
br i1 %38, label %39, label %42
39: ; preds = %6, %37
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.7, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %37
%43 = icmp eq i32 %33, 0
br i1 %43, label %44, label %47
44: ; preds = %42
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%46 = tail call i32 @exit(i32 1)
unreachable
47: ; preds = %42, %55
%48 = phi i32 [ %56, %55 ], [ 0, %42 ]
%49 = call i32 @make_block(i32 %48, i8* %4)
%50 = call i64 @fwrite(i8* %4, i32 512, i32 1, i32* %34)
%51 = icmp slt i64 %50, 1
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %48)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %47
%56 = add nuw i32 %48, 1
%57 = icmp eq i32 %56, %33
br i1 %57, label %58, label %47
58: ; preds = %55
%59 = call i32 @fclose(i32* %34)
ret i32 0
}