#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*/ uint8_t;
struct timespec {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int atoi(char *);
int /*<<< orphan*/ circle(int /*<<< orphan*/ *, int, int);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ *malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int size(int, int);
int /*<<< orphan*/ srand(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  struct timespec now;
  uint8_t *img;
  int w, h;
  int sz;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s width height\n", argv[0]);
    return 1;
  }
  clock_gettime(CLOCK_MONOTONIC, &now);
  srand((int)now.tv_sec ^ (int)now.tv_nsec);
  w = atoi(argv[1]);
  h = atoi(argv[2]);
  sz = size(w, h);
  fprintf(stderr, "Image size: %dx%d  Array size: %d\n", w, h, sz);
  img = malloc(sz);
  if (img == NULL) {
    perror("Failed to allocate image");
    return 2;
  }
  memset(img, 0, sz);
  fprintf(stderr, "Allocated image at %p\n", img);
  fprintf(stderr, "Drawing a circle\n");
  circle(img, w, h);
  fprintf(stderr, "Writing image to stdout\n");
  fwrite(img, sz, 1, stdout);
  free(img);
  fprintf(stderr, "Goodbye.\n");
  return 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)
cmpl   $0x3,-0x8(%rbp)
je     11fa <main+0x4a>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe19(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <main+0x192>
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    -0x18(%rbp),%rax
mov    %eax,%edi
mov    -0x20(%rbp),%rax
xor    %eax,%edi
call   1070 <srand@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x30(%rbp),%esi
call   1040 <size@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
lea    0xdb3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x34(%rbp),%edi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    129b <main+0xeb>
lea    0xdb1(%rip),%rdi
call   10b0 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1342 <main+0x192>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1090 <circle@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xd83(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    0x2cc1(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%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
sub    $0x18,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    12cd <main+0x11d>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1050 <clock_gettime@plt>
mov    0x8(%rsp),%edi
xor    0x10(%rsp),%edi
call   1070 <srand@plt>
mov    0x8(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r15d
mov    0x10(%rbx),%rdi
call   10c0 <atoi@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %eax,%esi
call   1040 <size@plt>
mov    %eax,%ebp
mov    0x2dc3(%rip),%r13
mov    0x0(%r13),%edi
lea    0xdf8(%rip),%rsi
xor    %r14d,%r14d
mov    %r15d,%edx
mov    %r12d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %ebp,%edi
call   10a0 <malloc@plt>
test   %rax,%rax
je     12ff <main+0x14f>
mov    %rax,%rbx
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <memset@plt>
mov    0x0(%r13),%edi
lea    0xdf7(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%r13),%edi
lea    0xdf9(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
mov    %r12d,%edx
call   1090 <circle@plt>
mov    0x0(%r13),%edi
lea    0xdeb(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
call   10d0 <fwrite@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%edi
lea    0xdd2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12ed <main+0x13d>
mov    0x2d04(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd20(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd35(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x2,%r14d
jmp    12ed <main+0x13d>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s width height\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.1 = [35 x i8] c"Image size: %dx%d Array size: %d\0A\00"
@.str.2 = [25 x i8] c"Failed to allocate image\00"
@.str.3 = [23 x i8] c"Allocated image at %p\0A\00"
@.str.4 = [18 x i8] c"Drawing a circle\0A\00"
@.str.5 = [25 x i8] c"Writing image to stdout\0A\00"
@stdout = global i32 0
@.str.6 = [10 x i8] c"Goodbye.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.timespec
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
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 i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 1, i32* %3
br label %75
19: ; preds = %2
%20 = load i32, i32* @CLOCK_MONOTONIC
%21 = call i32 @clock_gettime(i32 %20, %struct.timespec* %6)
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%26 = load i64, i64* %25
%27 = trunc i64 %26 to i32
%28 = xor i32 %24, %27
%29 = call i32 @srand(i32 %28)
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %8
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %9
%38 = load i32, i32* %8
%39 = load i32, i32* %9
%40 = call i32 @size(i32 %38, i32 %39)
store i32 %40, i32* %10
%41 = load i32, i32* @stderr
%42 = load i32, i32* %8
%43 = load i32, i32* %9
%44 = load i32, i32* %10
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43, i32 %44)
%46 = load i32, i32* %10
%47 = call i32* @malloc(i32 %46)
store i32* %47, i32** %7
%48 = load i32*, i32** %7
%49 = icmp eq i32* %48, null
br i1 %49, label %50, label %52
50: ; preds = %19
%51 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %75
52: ; preds = %19
%53 = load i32*, i32** %7
%54 = load i32, i32* %10
%55 = call i32 @memset(i32* %53, i32 0, i32 %54)
%56 = load i32, i32* @stderr
%57 = load i32*, i32** %7
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %57)
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%61 = load i32*, i32** %7
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = call i32 @circle(i32* %61, i32 %62, i32 %63)
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%67 = load i32*, i32** %7
%68 = load i32, i32* %10
%69 = load i32, i32* @stdout
%70 = call i32 @fwrite(i32* %67, i32 %68, i32 1, i32 %69)
%71 = load i32*, i32** %7
%72 = call i32 @free(i32* %71)
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %75
75: ; preds = %52, %50, %13
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s width height\0A\00"
@CLOCK_MONOTONIC = global i32 0
@.str.1 = [35 x i8] c"Image size: %dx%d Array size: %d\0A\00"
@.str.2 = [25 x i8] c"Failed to allocate image\00"
@.str.3 = [23 x i8] c"Allocated image at %p\0A\00"
@.str.4 = [18 x i8] c"Drawing a circle\0A\00"
@.str.5 = [25 x i8] c"Writing image to stdout\0A\00"
@stdout = global i32 0
@.str.6 = [10 x i8] c"Goodbye.\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %47
10: ; preds = %2
%11 = load i32, i32* @CLOCK_MONOTONIC
%12 = call i32 @clock_gettime(i32 %11, %struct.timespec* %3)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%14 = load i64, i64* %13
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%16 = load i64, i64* %15
%17 = xor i64 %16, %14
%18 = trunc i64 %17 to i32
%19 = call i32 @srand(i32 %18)
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @atoi(i8* %21)
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @size(i32 %22, i32 %25)
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %22, i32 %25, i32 %26)
%29 = call i32* @malloc(i32 %26)
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %10
%32 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %47
33: ; preds = %10
%34 = call i32 @memset(i32* %29, i32 0, i32 %26)
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %29)
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 @circle(i32* %29, i32 %22, i32 %25)
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%42 = load i32, i32* @stdout
%43 = call i32 @fwrite(i32* %29, i32 %26, i32 1, i32 %42)
%44 = call i32 @free(i32* %29)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %33, %31, %6
%48 = phi i32 [ 1, %6 ], [ 2, %31 ], [ 0, %33 ]
ret i32 %48
}