#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 EOF;
int atoi(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
void *malloc(int);
int /*<<< orphan*/ memset(void *, char, int);
int /*<<< orphan*/ optarg;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
char *strerror(int);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int opt;
  int retval = 0;
  int sz = 0;
  int noexit = 0;
  int usemem = 0;
  int verbose = 0;
  void *buf = NULL;
  if (argc == 1) {
    usage();
    exit(1);
  }
  while ((opt = getopt(argc, argv, "?ws:uv")) != EOF) {
    switch (opt) {
    case 's':
      sz = atoi(optarg);
      if (sz == 0)
        printf("error, specify size in kbytes for -s\n\n");
      break;
    case 'u':
      usemem = 1;
      break;
    case 'v':
      verbose = 1;
      break;
    case 'w':
      noexit = 1;
      break;
    case 'h':
    case '?':
    default:
      usage();
      exit(1);
    }
  }
  if (sz == 0) {
    usage();
    exit(1);
  }
  if (verbose)
    printf("allocating memory...\n");
  buf = malloc(sz * 1024);
  if (buf == NULL) {
    printf("error, malloc failed, %d, %s\n", errno, strerror(errno));
    exit(1);
  }
  if (usemem) {
    if (verbose)
      printf("filling memory with 'C' (for Chris)...\n");
    memset(buf, 'C', sz * 1024);
  }
  if (noexit) {
    if (verbose)
      printf("waiting forever...\n");
    while (1)
      sleep(10);
  }
  if (verbose)
    printf("exiting with joy...\n");
  return retval;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ec <main+0x5c>
mov    $0x0,%al
call   1060 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11f1 <main+0x61>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xee5(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd2(%rip),%rcx
cmp    (%rcx),%eax
je     12ac <main+0x11c>
mov    -0x14(%rbp),%eax
add    $0xffffffc1,%eax
mov    %eax,%ecx
mov    %rcx,-0x38(%rbp)
sub    $0x38,%eax
ja     1296 <main+0x106>
mov    -0x38(%rbp),%rax
lea    0xdca(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
call   1080 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1268 <main+0xd8>
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12a7 <main+0x117>
movl   $0x1,-0x24(%rbp)
jmp    12a7 <main+0x117>
movl   $0x1,-0x28(%rbp)
jmp    12a7 <main+0x117>
movl   $0x1,-0x20(%rbp)
jmp    12a7 <main+0x117>
jmp    1296 <main+0x106>
mov    $0x0,%al
call   1060 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11f1 <main+0x61>
cmpl   $0x0,-0x1c(%rbp)
jne    12c7 <main+0x137>
mov    $0x0,%al
call   1060 <usage@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x28(%rbp)
je     12df <main+0x14f>
lea    0xe3a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%edi
shl    $0xa,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1331 <main+0x1a1>
mov    0x2cd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
call   10a0 <strerror@plt>
mov    -0x3c(%rbp),%esi
mov    %rax,%rdx
lea    0xe08(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
je     1367 <main+0x1d7>
cmpl   $0x0,-0x28(%rbp)
je     1353 <main+0x1c3>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%edx
shl    $0xa,%edx
mov    $0x43,%esi
call   1040 <memset@plt>
cmpl   $0x0,-0x20(%rbp)
je     139d <main+0x20d>
cmpl   $0x0,-0x28(%rbp)
je     1389 <main+0x1f9>
lea    0xdec(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    138e <main+0x1fe>
mov    $0xa,%edi
call   10b0 <sleep@plt>
jmp    138e <main+0x1fe>
cmpl   $0x0,-0x28(%rbp)
je     13b5 <main+0x225>
lea    0xdd4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
je     131d <main+0x17d>
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe54(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2e14(%rip),%rcx
cmp    (%rcx),%eax
je     131d <main+0x17d>
movl   $0x0,0x4(%rsp)
lea    0xe1d(%rip),%r13
xor    %r12d,%r12d
movl   $0x0,(%rsp)
xor    %r14d,%r14d
jmp    1226 <main+0x86>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movl   $0x1,(%rsp)
mov    %r15d,%r12d
mov    %ebp,%edi
mov    %rbx,%rsi
lea    0xdfe(%rip),%rdx
call   1080 <getopt@plt>
mov    0x2dbe(%rip),%rcx
cmp    (%rcx),%eax
je     127b <main+0xdb>
add    $0xffffff8d,%eax
cmp    $0x4,%eax
ja     131d <main+0x17d>
mov    %r12d,%r15d
mov    $0x1,%r12d
movslq 0x0(%r13,%rax,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   1090 <atoi@plt>
test   %eax,%eax
je     126a <main+0xca>
mov    %eax,%r14d
jmp    1207 <main+0x67>
nopl   0x0(%rax)
movl   $0x1,0x4(%rsp)
jmp    1207 <main+0x67>
lea    0xe2b(%rip),%rdi
call   1030 <puts@plt>
xor    %r14d,%r14d
jmp    1207 <main+0x67>
test   %r14d,%r14d
je     131d <main+0x17d>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
je     1298 <main+0xf8>
lea    0xdf4(%rip),%rdi
call   1030 <puts@plt>
shl    $0xa,%r14d
mov    %r14d,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     132e <main+0x18e>
test   %r12d,%r12d
je     12d5 <main+0x135>
mov    %rax,%rbx
test   %ebp,%ebp
je     12c5 <main+0x125>
lea    0xda0(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
mov    $0x43,%esi
mov    %r14d,%edx
call   1050 <memset@plt>
cmpl   $0x0,(%rsp)
je     12fc <main+0x15c>
test   %ebp,%ebp
je     12f0 <main+0x150>
lea    0xd67(%rip),%rdi
call   1030 <puts@plt>
nopl   0x0(%rax,%rax,1)
mov    $0xa,%edi
call   10c0 <sleep@plt>
jmp    12f0 <main+0x150>
test   %ebp,%ebp
je     130c <main+0x16c>
lea    0xd32(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
call   1070 <usage@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2c9b(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%edi
call   10b0 <strerror@plt>
lea    0xcd6(%rip),%rdi
mov    %ebx,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"?ws:uv\00"
@EOF = global i32 0
@optarg = global i32 0
@.str.1 = [39 x i8] c"error, specify size in kbytes for -s\0A\0A\00"
@.str.2 = [22 x i8] c"allocating memory...\0A\00"
@.str.3 = [30 x i8] c"error, malloc failed, %d, %s\0A\00"
@errno = global i32 0
@.str.4 = [40 x i8] c"filling memory with 'C' (for Chris)...\0A\00"
@.str.5 = [20 x i8] c"waiting forever...\0A\00"
@.str.6 = [21 x i8] c"exiting with joy...\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i8* null, i8** %12
%13 = load i32, i32* %4
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (...) @usage()
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
br label %19
19: ; preds = %42, %18
%20 = load i32, i32* %4
%21 = load i8**, i8*** %5
%22 = call i32 @getopt(i32 %20, i8** %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %22, i32* %6
%23 = load i32, i32* @EOF
%24 = icmp ne i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %19
%26 = load i32, i32* %6
switch i32 %26, label %39 [
i32 115, label %27
i32 117, label %35
i32 118, label %36
i32 119, label %37
i32 104, label %38
i32 63, label %38
]
27: ; preds = %25
%28 = load i32, i32* @optarg
%29 = call i32 @atoi(i32 %28)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %27
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %42
35: ; preds = %25
store i32 1, i32* %10
br label %42
36: ; preds = %25
store i32 1, i32* %11
br label %42
37: ; preds = %25
store i32 1, i32* %9
br label %42
38: ; preds = %25, %25
br label %39
39: ; preds = %25, %38
%40 = call i32 (...) @usage()
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %37, %36, %35, %34
br label %19
43: ; preds = %19
%44 = load i32, i32* %8
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %43
%47 = call i32 (...) @usage()
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %43
%50 = load i32, i32* %11
%51 = icmp ne i32 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %49
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %54
54: ; preds = %52, %49
%55 = load i32, i32* %8
%56 = mul nsw i32 %55, 1024
%57 = call i8* @malloc(i32 %56)
store i8* %57, i8** %12
%58 = load i8*, i8** %12
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %66
60: ; preds = %54
%61 = load i32, i32* @errno
%62 = load i32, i32* @errno
%63 = call i8* @strerror(i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %61, i8* %63)
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %54
%67 = load i32, i32* %10
%68 = icmp ne i32 %67, 0
br i1 %68, label %69, label %79
69: ; preds = %66
%70 = load i32, i32* %11
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %74
72: ; preds = %69
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
br label %74
74: ; preds = %72, %69
%75 = load i8*, i8** %12
%76 = load i32, i32* %8
%77 = mul nsw i32 %76, 1024
%78 = call i32 @memset(i8* %75, i8 signext 67, i32 %77)
br label %79
79: ; preds = %74, %66
%80 = load i32, i32* %9
%81 = icmp ne i32 %80, 0
br i1 %81, label %82, label %90
82: ; preds = %79
%83 = load i32, i32* %11
%84 = icmp ne i32 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
br label %88
88: ; preds = %87, %88
%89 = call i32 @sleep(i32 10)
br label %88
90: ; preds = %79
%91 = load i32, i32* %11
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %95
93: ; preds = %90
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0))
br label %95
95: ; preds = %93, %90
%96 = load i32, i32* %7
ret i32 %96
}

LLVM IR (-O2):
@.str = [7 x i8] c"?ws:uv\00"
@EOF = global i32 0
@optarg = global i32 0
@.str.3 = [30 x i8] c"error, malloc failed, %d, %s\0A\00"
@errno = global i32 0
@str = [20 x i8] c"exiting with joy...\00"
@str.7 = [19 x i8] c"waiting forever...\00"
@str.8 = [39 x i8] c"filling memory with 'C' (for Chris)...\00"
@str.9 = [21 x i8] c"allocating memory...\00"
@str.10 = [38 x i8] c"error, specify size in kbytes for -s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EOF
%7 = icmp eq i32 %5, %6
br i1 %7, label %38, label %11
8: ; preds = %2
%9 = tail call i32 (...) @usage()
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %4, %28
%12 = phi i32 [ %33, %28 ], [ %5, %4 ]
%13 = phi i32 [ %32, %28 ], [ 0, %4 ]
%14 = phi i32 [ %31, %28 ], [ 0, %4 ]
%15 = phi i32 [ %30, %28 ], [ 0, %4 ]
%16 = phi i32 [ %29, %28 ], [ 0, %4 ]
switch i32 %12, label %25 [
i32 115, label %17
i32 117, label %28
i32 118, label %23
i32 119, label %24
]
17: ; preds = %11
%18 = load i32, i32* @optarg
%19 = tail call i32 @atoi(i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.10, i64 0, i64 0))
br label %28
23: ; preds = %11
br label %28
24: ; preds = %11
br label %28
25: ; preds = %11
%26 = tail call i32 (...) @usage()
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %11, %17, %21, %24, %23
%29 = phi i32 [ %16, %24 ], [ %16, %23 ], [ 0, %21 ], [ %19, %17 ], [ %16, %11 ]
%30 = phi i32 [ 1, %24 ], [ %15, %23 ], [ %15, %21 ], [ %15, %17 ], [ %15, %11 ]
%31 = phi i32 [ %14, %24 ], [ %14, %23 ], [ %14, %21 ], [ %14, %17 ], [ 1, %11 ]
%32 = phi i32 [ %13, %24 ], [ 1, %23 ], [ %13, %21 ], [ %13, %17 ], [ %13, %11 ]
%33 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%34 = load i32, i32* @EOF
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %11
36: ; preds = %28
%37 = icmp eq i32 %29, 0
br i1 %37, label %38, label %41
38: ; preds = %4, %36
%39 = tail call i32 (...) @usage()
%40 = tail call i32 @exit(i32 1)
unreachable
41: ; preds = %36
%42 = icmp eq i32 %32, 0
br i1 %42, label %45, label %43
43: ; preds = %41
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.9, i64 0, i64 0))
br label %45
45: ; preds = %43, %41
%46 = shl nsw i32 %29, 10
%47 = tail call i8* @malloc(i32 %46)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %54
49: ; preds = %45
%50 = load i32, i32* @errno
%51 = tail call i8* @strerror(i32 %50)
%52 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %50, i8* %51)
%53 = tail call i32 @exit(i32 1)
unreachable
54: ; preds = %45
%55 = icmp eq i32 %31, 0
br i1 %55, label %61, label %56
56: ; preds = %54
br i1 %42, label %59, label %57
57: ; preds = %56
%58 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
br label %59
59: ; preds = %57, %56
%60 = tail call i32 @memset(i8* %47, i8 signext 67, i32 %46)
br label %61
61: ; preds = %59, %54
%62 = icmp eq i32 %30, 0
br i1 %62, label %69, label %63
63: ; preds = %61
br i1 %42, label %66, label %64
64: ; preds = %63
%65 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
br label %66
66: ; preds = %64, %63
br label %67
67: ; preds = %66, %67
%68 = tail call i32 @sleep(i32 10)
br label %67
69: ; preds = %61
br i1 %42, label %72, label %70
70: ; preds = %69
%71 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %72
72: ; preds = %70, %69
ret i32 0
}