#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 /*<<< orphan*/ draw_line(unsigned int *, int, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
unsigned int *malloc(int);
int /*<<< orphan*/ stderr;
void draw(int width, int height) {
  unsigned int *image_data = malloc(sizeof(int) * width * height);
  if (!image_data) {
    fprintf(stderr, "Could not allocate data buffer.\n");
    exit(1);
  }
  for (int y = 0; y < height; ++y) {
    draw_line(image_data, width, height, y);
  }
}


x86 assembly (clang, -O0):
<draw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
movslq -0x8(%rbp),%rcx
imul   %rcx,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1193 <draw+0x53>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c6 <draw+0x86>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1040 <draw_line@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119a <draw+0x5a>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<draw>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%r14d
imul   %esi,%edi
shl    $0x2,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1191 <draw+0x51>
test   %ebx,%ebx
jle    1186 <draw+0x46>
mov    %rax,%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
mov    %r14d,%esi
mov    %ebx,%edx
mov    %ebp,%ecx
call   1040 <draw_line@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1170 <draw+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe5f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [33 x i8] c"Could not allocate data buffer.\0A\00"
define void @draw(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %3
%8 = sext i32 %7 to i64
%9 = mul i64 4, %8
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 %9, %11
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
store i32 0, i32* %6
br label %22
22: ; preds = %32, %21
%23 = load i32, i32* %6
%24 = load i32, i32* %4
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %35
26: ; preds = %22
%27 = load i32*, i32** %5
%28 = load i32, i32* %3
%29 = load i32, i32* %4
%30 = load i32, i32* %6
%31 = call i32 @draw_line(i32* %27, i32 %28, i32 %29, i32 %30)
br label %32
32: ; preds = %26
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %22
35: ; preds = %22
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Could not allocate data buffer.\0A\00"
define void @draw(i32 %0, i32 %1) {
%3 = shl i32 %0, 2
%4 = mul i32 %3, %1
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = icmp sgt i32 %1, 0
br i1 %8, label %14, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %14, %7
ret void
14: ; preds = %7, %14
%15 = phi i32 [ %17, %14 ], [ 0, %7 ]
%16 = tail call i32 @draw_line(i32* %5, i32 %0, i32 %1, i32 %15)
%17 = add nuw nsw i32 %15, 1
%18 = icmp eq i32 %17, %1
br i1 %18, label %13, label %14
}