#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;

/* Variables and functions */
int atoi(char *);
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 /*<<< orphan*/ setpx(int /*<<< orphan*/ *, int, int, int, int);
int size(int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  uint8_t *img;
  int w, h;
  int sz;
  int x, y;
  int c;
  if (argc != 3) {
    fprintf(stderr, "Usage: %s width height\n", argv[0]);
    return 1;
  }
  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 some gradient stripes\n");
  for (y = 0, c = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
      setpx(img, w, x, y, c);
      c++;
      c &= 0xff;
    }
  }
  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    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11da <main+0x4a>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1368 <main+0x1d8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
call   1040 <size@plt>
mov    %eax,-0x24(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x24(%rbp),%r8d
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1258 <main+0xc8>
lea    0xdf4(%rip),%rdi
call   1090 <perror@plt>
movl   $0x2,-0x4(%rbp)
jmp    1368 <main+0x1d8>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    0x2d73(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1310 <main+0x180>
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    12fd <main+0x16d>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    -0x30(%rbp),%r8d
call   1080 <setpx@plt>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12b9 <main+0x129>
jmp    1302 <main+0x172>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a6 <main+0x116>
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd6a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    0x2ca3(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xd49(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1274 <main+0xe4>
mov    0x8(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%ebp
mov    0x10(%rbx),%rdi
call   10a0 <atoi@plt>
mov    %eax,%r12d
mov    %ebp,%edi
mov    %eax,%esi
call   1040 <size@plt>
mov    %eax,%ebx
mov    0x2e10(%rip),%r14
mov    (%r14),%edi
lea    0xe3e(%rip),%rsi
mov    %ebp,%edx
mov    %r12d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebx,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12ef <main+0x15f>
mov    %rax,%r13
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebx,0x4(%rsp)
mov    %ebx,%edx
call   1050 <memset@plt>
mov    (%r14),%edi
lea    0xe3e(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%edi
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
test   %r12d,%r12d
jle    1295 <main+0x105>
xor    %ebx,%ebx
xor    %r14d,%r14d
jmp    1249 <main+0xb9>
nopl   (%rax)
add    $0x1,%r14d
cmp    %r12d,%r14d
je     1295 <main+0x105>
test   %ebp,%ebp
jle    1240 <main+0xb0>
xor    %r15d,%r15d
mov    %r13,%rdi
mov    %ebp,%esi
mov    %r15d,%edx
mov    %r14d,%ecx
mov    %ebx,%r8d
call   1080 <setpx@plt>
add    $0x1,%ebx
movzbl %bl,%ebx
add    $0x1,%r15d
cmp    %r15d,%ebp
jne    1250 <main+0xc0>
jmp    1240 <main+0xb0>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd79(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    12e0 <main+0x150>
mov    0x2d44(%rip),%rbx
mov    (%rbx),%edi
lea    0xde5(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%ecx
mov    %r13,%rdi
mov    0x4(%rsp),%esi
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    %r13,%rdi
call   1030 <free@plt>
mov    (%rbx),%edi
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd45(%rip),%rdi
call   1090 <perror@plt>
mov    $0x2,%eax
jmp    12e0 <main+0x150>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s width height\0A\00"
@.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 = [31 x i8] c"Drawing some gradient stripes\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 i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 3
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %91
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %8
%30 = load i32, i32* %7
%31 = load i32, i32* %8
%32 = call i32 @size(i32 %30, i32 %31)
store i32 %32, i32* %9
%33 = load i32, i32* @stderr
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35, i32 %36)
%38 = load i32, i32* %9
%39 = call i32* @malloc(i32 %38)
store i32* %39, i32** %6
%40 = load i32*, i32** %6
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %21
%43 = 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 %91
44: ; preds = %21
%45 = load i32*, i32** %6
%46 = load i32, i32* %9
%47 = call i32 @memset(i32* %45, i32 0, i32 %46)
%48 = load i32, i32* @stderr
%49 = load i32*, i32** %6
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %49)
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %11
store i32 0, i32* %12
br label %53
53: ; preds = %77, %44
%54 = load i32, i32* %11
%55 = load i32, i32* %8
%56 = icmp slt i32 %54, %55
br i1 %56, label %57, label %80
57: ; preds = %53
store i32 0, i32* %10
br label %58
58: ; preds = %73, %57
%59 = load i32, i32* %10
%60 = load i32, i32* %7
%61 = icmp slt i32 %59, %60
br i1 %61, label %62, label %76
62: ; preds = %58
%63 = load i32*, i32** %6
%64 = load i32, i32* %7
%65 = load i32, i32* %10
%66 = load i32, i32* %11
%67 = load i32, i32* %12
%68 = call i32 @setpx(i32* %63, i32 %64, i32 %65, i32 %66, i32 %67)
%69 = load i32, i32* %12
%70 = add nsw i32 %69, 1
store i32 %70, i32* %12
%71 = load i32, i32* %12
%72 = and i32 %71, 255
store i32 %72, i32* %12
br label %73
73: ; preds = %62
%74 = load i32, i32* %10
%75 = add nsw i32 %74, 1
store i32 %75, i32* %10
br label %58
76: ; preds = %58
br label %77
77: ; preds = %76
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %53
80: ; preds = %53
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%83 = load i32*, i32** %6
%84 = load i32, i32* %9
%85 = load i32, i32* @stdout
%86 = call i32 @fwrite(i32* %83, i32 %84, i32 1, i32 %85)
%87 = load i32*, i32** %6
%88 = call i32 @free(i32* %87)
%89 = load i32, i32* @stderr
%90 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* %3
br label %91
91: ; preds = %80, %42, %15
%92 = load i32, i32* %3
ret i32 %92
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Usage: %s width height\0A\00"
@.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 = [31 x i8] c"Drawing some gradient stripes\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 = icmp eq i32 %0, 3
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %54
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 2
%13 = load i8*, i8** %12
%14 = tail call i32 @atoi(i8* %13)
%15 = tail call i32 @size(i32 %11, i32 %14)
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %14, i32 %15)
%18 = tail call i32* @malloc(i32 %15)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %8
%21 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %54
22: ; preds = %8
%23 = tail call i32 @memset(i32* %18, i32 0, i32 %15)
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i32* %18)
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp sgt i32 %14, 0
br i1 %28, label %29, label %46
29: ; preds = %22
%30 = icmp sgt i32 %11, 0
br label %31
31: ; preds = %29, %42
%32 = phi i32 [ 0, %29 ], [ %43, %42 ]
%33 = phi i32 [ 0, %29 ], [ %44, %42 ]
br i1 %30, label %34, label %42
34: ; preds = %31, %34
%35 = phi i32 [ %39, %34 ], [ %32, %31 ]
%36 = phi i32 [ %40, %34 ], [ 0, %31 ]
%37 = tail call i32 @setpx(i32* %18, i32 %11, i32 %36, i32 %33, i32 %35)
%38 = add nsw i32 %35, 1
%39 = and i32 %38, 255
%40 = add nuw nsw i32 %36, 1
%41 = icmp eq i32 %40, %11
br i1 %41, label %42, label %34
42: ; preds = %34, %31
%43 = phi i32 [ %32, %31 ], [ %39, %34 ]
%44 = add nuw nsw i32 %33, 1
%45 = icmp eq i32 %44, %14
br i1 %45, label %46, label %31
46: ; preds = %42, %22
%47 = load i32, i32* @stderr
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%49 = load i32, i32* @stdout
%50 = tail call i32 @fwrite(i32* %18, i32 %15, i32 1, i32 %49)
%51 = tail call i32 @free(i32* %18)
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %46, %20, %4
%55 = phi i32 [ 1, %4 ], [ 2, %20 ], [ 0, %46 ]
ret i32 %55
}