#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 */
void *malloc(int);
int /*<<< orphan*/ plotInt2Ppm(char *, int, int, int **);
int rgb2Int(int, int, int);
void testPlotInt() {
  int width = 1024, height = 1024;
  int **pic = malloc(height * sizeof(int *));
  for (int y = 0; y < height; ++y) {
    pic[y] = malloc(width * sizeof(int));
  }
  for (int x = 0; x < width; ++x) {
    for (int y = 0; y < height; ++y) {
      pic[x][y] = rgb2Int(x % 255, y % 255, (x + y) % 255);
    }
  }
  plotInt2Ppm("test-plt-int.ppm", width, height, pic);
}


x86 assembly (clang, -O0):
<testPlotInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x400,-0x4(%rbp)
movl   $0x400,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1198 <testPlotInt+0x68>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <testPlotInt+0x30>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1221 <testPlotInt+0xf1>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    120e <testPlotInt+0xde>
mov    -0x18(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%edi
mov    -0x1c(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
mov    %edx,%esi
mov    -0x18(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    $0xff,%ecx
cltd
idiv   %ecx
call   1030 <rgb2Int@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b2 <testPlotInt+0x82>
jmp    1213 <testPlotInt+0xe3>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119f <testPlotInt+0x6f>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xdce(%rip),%rdi
call   1040 <plotInt2Ppm@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testPlotInt>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x2000,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x1000,%edi
call   1050 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    $0x400,%rbx
jne    1150 <testPlotInt+0x20>
xor    %r15d,%r15d
mov    $0x80808081,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15d,%r13d
imul   %r12,%r13
shr    $0x27,%r13
mov    %r13d,%eax
shl    $0x8,%eax
sub    %eax,%r13d
add    %r15d,%r13d
mov    %r15d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %ebx,%esi
imul   %r12,%rsi
shr    $0x27,%rsi
mov    %esi,%eax
shl    $0x8,%eax
sub    %eax,%esi
add    %ebx,%esi
mov    %ebp,%edx
imul   %r12,%rdx
shr    $0x27,%rdx
mov    %edx,%eax
shl    $0x8,%eax
sub    %eax,%edx
add    %ebp,%edx
mov    %r13d,%edi
call   1030 <rgb2Int@plt>
mov    (%r14,%r15,8),%rcx
mov    %eax,(%rcx,%rbx,4)
add    $0x1,%rbx
add    $0x1,%ebp
cmp    $0x400,%rbx
jne    11a0 <testPlotInt+0x70>
add    $0x1,%r15
cmp    $0x400,%r15
jne    1180 <testPlotInt+0x50>
lea    0xe07(%rip),%rdi
mov    $0x400,%esi
mov    $0x400,%edx
mov    %r14,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <plotInt2Ppm@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"test-plt-int.ppm\00"
define void @testPlotInt() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 1024, i32* %1
store i32 1024, i32* %2
%7 = load i32, i32* %2
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 8
%10 = trunc i64 %9 to i32
%11 = call i8* @malloc(i32 %10)
%12 = bitcast i8* %11 to i32**
store i32** %12, i32*** %3
store i32 0, i32* %4
br label %13
13: ; preds = %28, %0
%14 = load i32, i32* %4
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = mul i64 %19, 4
%21 = trunc i64 %20 to i32
%22 = call i8* @malloc(i32 %21)
%23 = bitcast i8* %22 to i32*
%24 = load i32**, i32*** %3
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32*, i32** %24, i64 %26
store i32* %23, i32** %27
br label %28
28: ; preds = %17
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %13
31: ; preds = %13
store i32 0, i32* %5
br label %32
32: ; preds = %63, %31
%33 = load i32, i32* %5
%34 = load i32, i32* %1
%35 = icmp slt i32 %33, %34
br i1 %35, label %36, label %66
36: ; preds = %32
store i32 0, i32* %6
br label %37
37: ; preds = %59, %36
%38 = load i32, i32* %6
%39 = load i32, i32* %2
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %62
41: ; preds = %37
%42 = load i32, i32* %5
%43 = srem i32 %42, 255
%44 = load i32, i32* %6
%45 = srem i32 %44, 255
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = add nsw i32 %46, %47
%49 = srem i32 %48, 255
%50 = call i32 @rgb2Int(i32 %43, i32 %45, i32 %49)
%51 = load i32**, i32*** %3
%52 = load i32, i32* %5
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds i32*, i32** %51, i64 %53
%55 = load i32*, i32** %54
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 %50, i32* %58
br label %59
59: ; preds = %41
%60 = load i32, i32* %6
%61 = add nsw i32 %60, 1
store i32 %61, i32* %6
br label %37
62: ; preds = %37
br label %63
63: ; preds = %62
%64 = load i32, i32* %5
%65 = add nsw i32 %64, 1
store i32 %65, i32* %5
br label %32
66: ; preds = %32
%67 = load i32, i32* %1
%68 = load i32, i32* %2
%69 = load i32**, i32*** %3
%70 = call i32 @plotInt2Ppm(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %67, i32 %68, i32** %69)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"test-plt-int.ppm\00"
define void @testPlotInt() {
%1 = tail call dereferenceable_or_null(8192) i8* @malloc(i32 8192)
%2 = bitcast i8* %1 to i32**
br label %3
3: ; preds = %0, %3
%4 = phi i64 [ 0, %0 ], [ %8, %3 ]
%5 = tail call dereferenceable_or_null(4096) i8* @malloc(i32 4096)
%6 = getelementptr inbounds i32*, i32** %2, i64 %4
%7 = bitcast i32** %6 to i8**
store i8* %5, i8** %7
%8 = add nuw nsw i64 %4, 1
%9 = icmp eq i64 %8, 1024
br i1 %9, label %10, label %3
10: ; preds = %3, %17
%11 = phi i64 [ %18, %17 ], [ 0, %3 ]
%12 = trunc i64 %11 to i32
%13 = urem i32 %12, 255
%14 = getelementptr inbounds i32*, i32** %2, i64 %11
br label %20
15: ; preds = %17
%16 = tail call i32 @plotInt2Ppm(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 1024, i32 1024, i32** %2)
ret void
17: ; preds = %20
%18 = add nuw nsw i64 %11, 1
%19 = icmp eq i64 %18, 1024
br i1 %19, label %15, label %10
20: ; preds = %10, %20
%21 = phi i64 [ 0, %10 ], [ %31, %20 ]
%22 = trunc i64 %21 to i16
%23 = urem i16 %22, 255
%24 = zext i16 %23 to i32
%25 = add nuw nsw i64 %21, %11
%26 = trunc i64 %25 to i32
%27 = urem i32 %26, 255
%28 = tail call i32 @rgb2Int(i32 %13, i32 %24, i32 %27)
%29 = load i32*, i32** %14
%30 = getelementptr inbounds i32, i32* %29, i64 %21
store i32 %28, i32* %30
%31 = add nuw nsw i64 %21, 1
%32 = icmp eq i64 %31, 1024
br i1 %32, label %17, label %20
}