#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ draw_line(unsigned char *, int, int, int, char, char,
                             int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
void export_motion(char *mx, char *my, unsigned char *mt, float *conf, int w,
                   int h, char *filename) {
  FILE *f;
  int x, y, i;
  for (i = 0; i < w * h; i++)
    mt[i] = 255;
  i = 0;
  for (y = 0; y < h; y++) {
    for (x = 0; x < w; x++) {
      i = y * w + x;
      if (conf[i] > 0.99) {
        draw_line(mt, w, x, y, mx[i], my[i], 0);
        mt[(y + my[i]) * w + x + mx[i]] = 128;
      }
    }
  }
  f = fopen(filename, "wb");
  if (!f) {
    printf("error: couldn't open %s for output\n", filename);
    return;
  }
  fprintf(f, "P5\n");
  fprintf(f, "%d %d\n", w, h);
  fprintf(f, "255\n");
  fwrite(mt, 1, w * h, f);
  fclose(f);
}


x86 assembly (clang, -O0):
<export_motion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    %r9d,-0x28(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    -0x24(%rbp),%ecx
imul   -0x28(%rbp),%ecx
cmp    %ecx,%eax
jge    11b7 <export_motion+0x57>
mov    -0x18(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    118b <export_motion+0x2b>
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12a4 <export_motion+0x144>
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1291 <export_motion+0x131>
mov    -0x38(%rbp),%eax
imul   -0x24(%rbp),%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x3c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdf6(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    127e <export_motion+0x11e>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x34(%rbp),%edx
mov    -0x38(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq -0x3c(%rbp),%r8
mov    (%rax,%r8,1),%r8b
mov    -0x10(%rbp),%rax
movslq -0x3c(%rbp),%r9
xor    %r10d,%r10d
movsbl %r8b,%r8d
movsbl (%rax,%r9,1),%r9d
movl   $0x0,(%rsp)
call   1060 <draw_line@plt>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%ecx
mov    -0x10(%rbp),%rdx
movslq -0x3c(%rbp),%rsi
movsbl (%rdx,%rsi,1),%edx
add    %edx,%ecx
imul   -0x24(%rbp),%ecx
add    -0x34(%rbp),%ecx
mov    -0x8(%rbp),%rdx
movslq -0x3c(%rbp),%rsi
movsbl (%rdx,%rsi,1),%edx
add    %edx,%ecx
movslq %ecx,%rcx
movb   $0x80,(%rax,%rcx,1)
jmp    1283 <export_motion+0x123>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11d8 <export_motion+0x78>
jmp    1296 <export_motion+0x136>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11c5 <export_motion+0x65>
mov    0x10(%rbp),%rdi
lea    0xd59(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12d8 <export_motion+0x178>
mov    0x10(%rbp),%rsi
lea    0xd3d(%rip),%rdi
call   1040 <printf@plt>
jmp    1336 <export_motion+0x1d6>
mov    -0x30(%rbp),%rdi
lea    0xd4c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
lea    0xd38(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
lea    0xd2d(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
imul   -0x28(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<export_motion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9d,%ebx
mov    %rdx,%r15
mov    %rsi,0x38(%rsp)
mov    %rdi,0x30(%rsp)
mov    0xa0(%rsp),%rax
mov    %rax,0x40(%rsp)
mov    %r9d,%ebp
mov    %r8d,0x10(%rsp)
imul   %r8d,%ebp
test   %ebp,%ebp
jle    11c0 <export_motion+0x50>
mov    %ebp,%edx
mov    %r15,%rdi
mov    $0xff,%esi
mov    %rcx,%r12
call   1050 <memset@plt>
mov    %r12,%rcx
mov    %ebp,0x24(%rsp)
mov    %r15,0x28(%rsp)
mov    %ebx,0x14(%rsp)
test   %ebx,%ebx
jle    12c6 <export_motion+0x156>
mov    0x10(%rsp),%eax
mov    %eax,%r12d
cltq
mov    0x14(%rsp),%edx
mov    %rdx,0x50(%rsp)
mov    %rax,0x58(%rsp)
lea    0x0(,%rax,4),%rax
mov    %rax,0x48(%rsp)
xor    %eax,%eax
mov    %rax,0x18(%rsp)
movsd  0xdf8(%rip),%xmm1
mov    0x28(%rsp),%rbp
jmp    1240 <export_motion+0xd0>
nop
mov    0x18(%rsp),%rdx
add    $0x1,%rdx
add    0x48(%rsp),%rcx
mov    0x58(%rsp),%rax
add    %rax,0x30(%rsp)
add    %rax,0x38(%rsp)
mov    %rdx,%rax
mov    %rdx,0x18(%rsp)
cmp    0x50(%rsp),%rdx
je     12c6 <export_motion+0x156>
cmpl   $0x0,0x10(%rsp)
jle    1210 <export_motion+0xa0>
xor    %ebx,%ebx
mov    %rcx,0x60(%rsp)
jmp    1259 <export_motion+0xe9>
add    $0x1,%rbx
cmp    %rbx,%r12
je     1210 <export_motion+0xa0>
movss  (%rcx,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    1250 <export_motion+0xe0>
mov    0x30(%rsp),%r13
movsbl 0x0(%r13,%rbx,1),%r8d
mov    0x38(%rsp),%r14
movsbl (%r14,%rbx,1),%r9d
movl   $0x0,(%rsp)
mov    %rbp,%rdi
mov    %r12d,%esi
mov    %ebx,%edx
mov    0x18(%rsp),%r15
mov    %r15d,%ecx
call   1070 <draw_line@plt>
movsd  0xd5f(%rip),%xmm1
movsbl (%r14,%rbx,1),%eax
movsbl 0x0(%r13,%rbx,1),%ecx
add    %r15d,%eax
imul   0x10(%rsp),%eax
add    %ecx,%eax
mov    0x60(%rsp),%rcx
add    %ebx,%eax
cltq
movb   $0x80,0x0(%rbp,%rax,1)
jmp    1250 <export_motion+0xe0>
lea    0xd3b(%rip),%rsi
mov    0x40(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1359 <export_motion+0x1e9>
mov    %rax,%rbp
lea    0xd46(%rip),%rdi
mov    $0x3,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1090 <fwrite@plt>
lea    0xd31(%rip),%rsi
mov    %rbp,%rdi
mov    0x10(%rsp),%edx
mov    0x14(%rsp),%ecx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xd1f(%rip),%rdi
mov    $0x4,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1090 <fwrite@plt>
mov    0x28(%rsp),%rdi
mov    $0x1,%esi
mov    0x24(%rsp),%edx
mov    %rbp,%rcx
call   1090 <fwrite@plt>
mov    %rbp,%rdi
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <fclose@plt>
lea    0xcab(%rip),%rdi
mov    %rbx,%rsi
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [36 x i8] c"error: couldn't open %s for output\0A\00"
@.str.2 = [4 x i8] c"P5\0A\00"
@.str.3 = [7 x i8] c"%d %d\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
define void @export_motion(i8* %0, i8* %1, i8* %2, float* %3, i32 %4, i32 %5, i8* %6) {
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca float*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i8* %0, i8** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store float* %3, float** %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i8* %6, i8** %14
store i32 0, i32* %18
br label %19
19: ; preds = %30, %7
%20 = load i32, i32* %18
%21 = load i32, i32* %12
%22 = load i32, i32* %13
%23 = mul nsw i32 %21, %22
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %33
25: ; preds = %19
%26 = load i8*, i8** %10
%27 = load i32, i32* %18
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
store i8 -1, i8* %29
br label %30
30: ; preds = %25
%31 = load i32, i32* %18
%32 = add nsw i32 %31, 1
store i32 %32, i32* %18
br label %19
33: ; preds = %19
store i32 0, i32* %18
store i32 0, i32* %17
br label %34
34: ; preds = %99, %33
%35 = load i32, i32* %17
%36 = load i32, i32* %13
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %102
38: ; preds = %34
store i32 0, i32* %16
br label %39
39: ; preds = %95, %38
%40 = load i32, i32* %16
%41 = load i32, i32* %12
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %98
43: ; preds = %39
%44 = load i32, i32* %17
%45 = load i32, i32* %12
%46 = mul nsw i32 %44, %45
%47 = load i32, i32* %16
%48 = add nsw i32 %46, %47
store i32 %48, i32* %18
%49 = load float*, float** %11
%50 = load i32, i32* %18
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds float, float* %49, i64 %51
%53 = load float, float* %52
%54 = fpext float %53 to double
%55 = fcmp ogt double %54, 0x3FEFAE147AE147AE
br i1 %55, label %56, label %94
56: ; preds = %43
%57 = load i8*, i8** %10
%58 = load i32, i32* %12
%59 = load i32, i32* %16
%60 = load i32, i32* %17
%61 = load i8*, i8** %8
%62 = load i32, i32* %18
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
%65 = load i8, i8* %64
%66 = load i8*, i8** %9
%67 = load i32, i32* %18
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %66, i64 %68
%70 = load i8, i8* %69
%71 = call i32 @draw_line(i8* %57, i32 %58, i32 %59, i32 %60, i8 signext %65, i8 signext %70, i32 0)
%72 = load i8*, i8** %10
%73 = load i32, i32* %17
%74 = load i8*, i8** %9
%75 = load i32, i32* %18
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds i8, i8* %74, i64 %76
%78 = load i8, i8* %77
%79 = sext i8 %78 to i32
%80 = add nsw i32 %73, %79
%81 = load i32, i32* %12
%82 = mul nsw i32 %80, %81
%83 = load i32, i32* %16
%84 = add nsw i32 %82, %83
%85 = load i8*, i8** %8
%86 = load i32, i32* %18
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = add nsw i32 %84, %90
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %72, i64 %92
store i8 -128, i8* %93
br label %94
94: ; preds = %56, %43
br label %95
95: ; preds = %94
%96 = load i32, i32* %16
%97 = add nsw i32 %96, 1
store i32 %97, i32* %16
br label %39
98: ; preds = %39
br label %99
99: ; preds = %98
%100 = load i32, i32* %17
%101 = add nsw i32 %100, 1
store i32 %101, i32* %17
br label %34
102: ; preds = %34
%103 = load i8*, i8** %14
%104 = call i32* @fopen(i8* %103, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %104, i32** %15
%105 = load i32*, i32** %15
%106 = icmp ne i32* %105, null
br i1 %106, label %110, label %107
107: ; preds = %102
%108 = load i8*, i8** %14
%109 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %108)
br label %127
110: ; preds = %102
%111 = load i32*, i32** %15
%112 = call i32 (i32*, i8*, ...) @fprintf(i32* %111, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%113 = load i32*, i32** %15
%114 = load i32, i32* %12
%115 = load i32, i32* %13
%116 = call i32 (i32*, i8*, ...) @fprintf(i32* %113, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %114, i32 %115)
%117 = load i32*, i32** %15
%118 = call i32 (i32*, i8*, ...) @fprintf(i32* %117, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%119 = load i8*, i8** %10
%120 = load i32, i32* %12
%121 = load i32, i32* %13
%122 = mul nsw i32 %120, %121
%123 = load i32*, i32** %15
%124 = call i32 @fwrite(i8* %119, i32 1, i32 %122, i32* %123)
%125 = load i32*, i32** %15
%126 = call i32 @fclose(i32* %125)
br label %127
127: ; preds = %110, %107
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [36 x i8] c"error: couldn't open %s for output\0A\00"
@.str.2 = [4 x i8] c"P5\0A\00"
@.str.3 = [7 x i8] c"%d %d\0A\00"
@.str.4 = [5 x i8] c"255\0A\00"
define void @export_motion(i8* nocapture %0, i8* nocapture %1, i8* %2, float* nocapture %3, i32 %4, i32 %5, i8* %6) {
%8 = mul i32 %5, %4
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %7
%13 = icmp sgt i32 %5, 0
br i1 %13, label %14, label %54
14: ; preds = %12
%15 = icmp sgt i32 %4, 0
%16 = sext i32 %4 to i64
%17 = zext i32 %5 to i64
%18 = zext i32 %4 to i64
br label %19
19: ; preds = %14, %51
%20 = phi i64 [ 0, %14 ], [ %52, %51 ]
br i1 %15, label %21, label %51
21: ; preds = %19
%22 = mul nsw i64 %20, %16
%23 = trunc i64 %20 to i32
br label %24
24: ; preds = %21, %48
%25 = phi i64 [ 0, %21 ], [ %49, %48 ]
%26 = add nsw i64 %25, %22
%27 = getelementptr inbounds float, float* %3, i64 %26
%28 = load float, float* %27
%29 = fpext float %28 to double
%30 = fcmp ogt double %29, 0x3FEFAE147AE147AE
br i1 %30, label %31, label %48
31: ; preds = %24
%32 = getelementptr inbounds i8, i8* %0, i64 %26
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %1, i64 %26
%35 = load i8, i8* %34
%36 = trunc i64 %25 to i32
%37 = tail call i32 @draw_line(i8* %2, i32 %4, i32 %36, i32 %23, i8 signext %33, i8 signext %35, i32 0)
%38 = load i8, i8* %34
%39 = sext i8 %38 to i32
%40 = add nsw i32 %23, %39
%41 = mul nsw i32 %40, %4
%42 = load i8, i8* %32
%43 = sext i8 %42 to i32
%44 = add i32 %36, %43
%45 = add i32 %44, %41
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %2, i64 %46
store i8 -128, i8* %47
br label %48
48: ; preds = %24, %31
%49 = add nuw nsw i64 %25, 1
%50 = icmp eq i64 %49, %18
br i1 %50, label %51, label %24
51: ; preds = %48, %19
%52 = add nuw nsw i64 %20, 1
%53 = icmp eq i64 %52, %17
br i1 %53, label %54, label %19
54: ; preds = %51, %12
%55 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%56 = icmp eq i32* %55, null
br i1 %56, label %57, label %59
57: ; preds = %54
%58 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %6)
br label %65
59: ; preds = %54
%60 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3, i64 1, i32* %55)
%61 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %55, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i32 %4, i32 %5)
%62 = tail call i64 bitcast (i32 (i8*, i32, i32, i32*)* @fwrite to i64 (i8*, i64, i64, i32*)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i64 4, i64 1, i32* %55)
%63 = tail call i32 @fwrite(i8* %2, i32 1, i32 %8, i32* %55)
%64 = tail call i32 @fclose(i32* %55)
br label %65
65: ; preds = %59, %57
ret void
}