#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 scalar_t__ useconds_t;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ abs(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int, int, long, int);
scalar_t__ getpid();
int /*<<< orphan*/ printf(char *, char *, char *);
int rand();
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ usleep(scalar_t__);
int main(int argc, char *argv[]) {
  char *output = NULL;
  if (argc != 1) {
    if (argc != 2 || strcmp(argv[1], "--help") == 0) {
      printf("Usage\n\n%s\nprints squares from 0 to 100 to stdout\n\n%s "
             "file\nprints squares to file\n",
             argv[0], argv[0]);
      exit(1);
    }
    output = argv[1];
  }
  FILE *out = NULL;
  if (output == NULL) {
    out = stdout;
  } else {
    out = fopen(output, "a");
  }
  int i;
  pid_t pid = getpid();
  for (i = 0; i <= 100; i++) {
    useconds_t duration = (useconds_t)(abs(rand() % 1000000));
    fprintf(out, "%4d^2=%6d %7ld (%4d)\n", i, i * i, (long)duration, (int)pid);
    fflush(out);
    usleep(duration);
  }
  fclose(out);
  exit(0);
}


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)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     1230 <main+0x80>
cmpl   $0x2,-0x8(%rbp)
jne    1200 <main+0x50>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe0f(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1224 <main+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf2(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1256 <main+0xa6>
mov    0x2d96(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    126a <main+0xba>
mov    -0x18(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jg     12e7 <main+0x137>
mov    $0x0,%al
call   10c0 <rand@plt>
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
call   1030 <abs@plt>
cltq
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x24(%rbp),%ecx
imul   -0x24(%rbp),%ecx
mov    -0x38(%rbp),%r8
mov    -0x30(%rbp),%rax
mov    %eax,%r9d
lea    0xd99(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1090 <fflush@plt>
mov    -0x38(%rbp),%rdi
call   10d0 <usleep@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    127c <main+0xcc>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
je     11f3 <main+0x53>
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11ca <main+0x2a>
mov    0x8(%rbx),%rdi
lea    0xe40(%rip),%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11e6 <main+0x46>
mov    (%rbx),%rdx
lea    0xe33(%rip),%rdi
mov    %rdx,%rsi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x8(%rbx),%rdi
test   %rdi,%rdi
jne    127b <main+0xdb>
mov    0x2de6(%rip),%rax
mov    (%rax),%r12
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%r14
lea    0xe4d(%rip),%r15
xor    %ebp,%ebp
xor    %eax,%eax
call   10b0 <rand@plt>
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,%ebx
neg    %ebx
cmovs  %eax,%ebx
mov    %ebp,%ecx
imul   %ebp,%ecx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %rbx,%r8
mov    %r14d,%r9d
call   1070 <fprintf@plt>
mov    %r12,%rdi
call   1080 <fflush@plt>
mov    %rbx,%rdi
call   10c0 <usleep@plt>
add    $0x1,%ebp
cmp    $0x65,%ebp
jne    1210 <main+0x70>
mov    %r12,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xdd7(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r12
jmp    11fd <main+0x5d>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [82 x i8] c"Usage\0A\0A%s\0Aprints squares from 0 to 100 to stdout\0A\0A%s file\0Aprints squares to file\0A\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [22 x i8] c"%4d^2=%6d %7ld (%4d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 1
br i1 %12, label %13, label %35
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %22, label %16
16: ; preds = %13
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %31
22: ; preds = %16, %13
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %28)
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %16
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %6
br label %35
35: ; preds = %31, %2
store i32* null, i32** %7
%36 = load i8*, i8** %6
%37 = icmp eq i8* %36, null
br i1 %37, label %38, label %40
38: ; preds = %35
%39 = load i32*, i32** @stdout
store i32* %39, i32** %7
br label %43
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = call i32* @fopen(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %42, i32** %7
br label %43
43: ; preds = %40, %38
%44 = call i64 (...) @getpid()
store i64 %44, i64* %9
store i32 0, i32* %8
br label %45
45: ; preds = %66, %43
%46 = load i32, i32* %8
%47 = icmp sle i32 %46, 100
br i1 %47, label %48, label %69
48: ; preds = %45
%49 = call i32 (...) @rand()
%50 = srem i32 %49, 1000000
%51 = call i32 @abs(i32 %50)
%52 = sext i32 %51 to i64
store i64 %52, i64* %10
%53 = load i32*, i32** %7
%54 = load i32, i32* %8
%55 = load i32, i32* %8
%56 = load i32, i32* %8
%57 = mul nsw i32 %55, %56
%58 = load i64, i64* %10
%59 = load i64, i64* %9
%60 = trunc i64 %59 to i32
%61 = call i32 @fprintf(i32* %53, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %54, i32 %57, i64 %58, i32 %60)
%62 = load i32*, i32** %7
%63 = call i32 @fflush(i32* %62)
%64 = load i64, i64* %10
%65 = call i32 @usleep(i64 %64)
br label %66
66: ; preds = %48
%67 = load i32, i32* %8
%68 = add nsw i32 %67, 1
store i32 %68, i32* %8
br label %45
69: ; preds = %45
%70 = load i32*, i32** %7
%71 = call i32 @fclose(i32* %70)
%72 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@.str.1 = [82 x i8] c"Usage\0A\0A%s\0Aprints squares from 0 to 100 to stdout\0A\0A%s file\0Aprints squares to file\0A\00"
@stdout = global i32* null
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [22 x i8] c"%4d^2=%6d %7ld (%4d)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
switch i32 %0, label %8 [
i32 1, label %15
i32 2, label %3
]
3: ; preds = %2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2, %3
%9 = load i8*, i8** %1
%10 = tail call i32 @printf(i8* getelementptr inbounds ([82 x i8], [82 x i8]* @.str.1, i64 0, i64 0), i8* %9, i8* %9)
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %3
%13 = load i8*, i8** %4
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %2, %12
%16 = load i32*, i32** @stdout
br label %19
17: ; preds = %12
%18 = tail call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %19
19: ; preds = %17, %15
%20 = phi i32* [ %16, %15 ], [ %18, %17 ]
%21 = tail call i64 (...) @getpid()
%22 = trunc i64 %21 to i32
br label %23
23: ; preds = %19, %23
%24 = phi i32 [ 0, %19 ], [ %33, %23 ]
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 1000000
%27 = tail call i32 @llvm.abs.i32(i32 %26, i1 true)
%28 = zext i32 %27 to i64
%29 = mul nuw nsw i32 %24, %24
%30 = tail call i32 @fprintf(i32* %20, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %24, i32 %29, i64 %28, i32 %22)
%31 = tail call i32 @fflush(i32* %20)
%32 = tail call i32 @usleep(i64 %28)
%33 = add nuw nsw i32 %24, 1
%34 = icmp eq i32 %33, 101
br i1 %34, label %35, label %23
35: ; preds = %23
%36 = tail call i32 @fclose(i32* %20)
%37 = tail call i32 @exit(i32 0)
unreachable
}