#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ fail(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
float *iio_read_image_float_vec(char *, int *, int *, int *);
int /*<<< orphan*/ iio_save_image_float_vec(char *, float *, int, int, int);
int /*<<< orphan*/ invflow(float *, float *, float *, int, int, int, int, int);
int /*<<< orphan*/ stderr;
float *xmalloc(int);
int main_backflow(int c, char *v[]) {
  if (c != 2 && c != 4 && c != 3) {
    fprintf(stderr, "usage:\n\t%s flow [in [out]]\n", *v);
    return EXIT_FAILURE;
  }
  char *inname = c > 2 ? v[2] : "-";
  char *outname = c > 3 ? v[3] : "-";
  int w, h, pd;
  float *flow = iio_read_image_float_vec(v[1], &w, &h, &pd);
  if (pd != 2)
    fail("flow must have two-dimensional pixels\n");
  int iw, ih;
  float *in = iio_read_image_float_vec(inname, &iw, &ih, &pd);
  float *out = xmalloc(w * h * pd * sizeof *out);
  invflow(out, flow, in, w, h, pd, iw, ih);
  iio_save_image_float_vec(outname, out, w, h, pd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main_backflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11ba <main_backflow+0x5a>
cmpl   $0x4,-0x8(%rbp)
je     11ba <main_backflow+0x5a>
cmpl   $0x3,-0x8(%rbp)
je     11ba <main_backflow+0x5a>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5c(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12d6 <main_backflow+0x176>
cmpl   $0x2,-0x8(%rbp)
jle    11d5 <main_backflow+0x75>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    11e5 <main_backflow+0x85>
lea    0xe40(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    11e5 <main_backflow+0x85>
mov    -0x58(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1208 <main_backflow+0xa8>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    1218 <main_backflow+0xb8>
lea    0xe0d(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1218 <main_backflow+0xb8>
mov    -0x60(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x24(%rbp),%rsi
lea    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <iio_read_image_float_vec@plt>
mov    %rax,-0x38(%rbp)
cmpl   $0x2,-0x2c(%rbp)
je     1253 <main_backflow+0xf3>
lea    0xdd0(%rip),%rdi
call   1030 <fail@plt>
mov    -0x18(%rbp),%rdi
lea    -0x3c(%rbp),%rsi
lea    -0x40(%rbp),%rdx
lea    -0x2c(%rbp),%rcx
call   1040 <iio_read_image_float_vec@plt>
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x28(%rbp),%eax
imul   -0x2c(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <xmalloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    -0x28(%rbp),%r8d
mov    -0x2c(%rbp),%r9d
mov    -0x3c(%rbp),%r10d
mov    -0x40(%rbp),%eax
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1080 <invflow@plt>
mov    -0x20(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x28(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
call   1070 <iio_save_image_float_vec@plt>
mov    0x2cff(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_backflow>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    -0x2(%rdi),%eax
cmp    $0x3,%eax
jae    118b <main_backflow+0x2b>
lea    0xea2(%rip),%r14
cmp    $0x3,%edi
jb     11af <main_backflow+0x4f>
mov    0x10(%rsi),%r15
je     11b2 <main_backflow+0x52>
mov    0x18(%rsi),%r14
jmp    11b2 <main_backflow+0x52>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe62(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e2e(%rip),%rax
jmp    125e <main_backflow+0xfe>
mov    %r14,%r15
mov    0x8(%rsi),%rdi
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
call   1040 <iio_read_image_float_vec@plt>
mov    %rax,%r12
cmpl   $0x2,0x4(%rsp)
je     11e0 <main_backflow+0x80>
lea    0xe43(%rip),%rdi
call   1030 <fail@plt>
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0x4(%rsp),%rcx
mov    %r15,%rdi
call   1040 <iio_read_image_float_vec@plt>
mov    0xc(%rsp),%edi
imul   0x8(%rsp),%edi
mov    %rax,%r15
imul   0x4(%rsp),%edi
shl    $0x2,%edi
call   1050 <xmalloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%ecx
mov    0x8(%rsp),%r8d
mov    0x4(%rsp),%r9d
mov    0x14(%rsp),%r10d
mov    0x10(%rsp),%eax
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
push   %rax
push   %r10
call   1080 <invflow@plt>
add    $0x10,%rsp
mov    0xc(%rsp),%edx
mov    0x8(%rsp),%ecx
mov    0x4(%rsp),%r8d
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <iio_save_image_float_vec@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [28 x i8] c"usage:\0A\09%s flow [in [out]]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [39 x i8] c"flow must have two-dimensional pixels\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main_backflow(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca float*
%12 = alloca i32
%13 = alloca i32
%14 = alloca float*
%15 = alloca float*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 2
br i1 %17, label %18, label %30
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 4
br i1 %20, label %21, label %30
21: ; preds = %18
%22 = load i32, i32* %4
%23 = icmp ne i32 %22, 3
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i8**, i8*** %5
%27 = load i8*, i8** %26
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %85
30: ; preds = %21, %18, %2
%31 = load i32, i32* %4
%32 = icmp sgt i32 %31, 2
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 2
%36 = load i8*, i8** %35
br label %38
37: ; preds = %30
br label %38
38: ; preds = %37, %33
%39 = phi i8* [ %36, %33 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %37 ]
store i8* %39, i8** %6
%40 = load i32, i32* %4
%41 = icmp sgt i32 %40, 3
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
br label %47
46: ; preds = %38
br label %47
47: ; preds = %46, %42
%48 = phi i8* [ %45, %42 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %46 ]
store i8* %48, i8** %7
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call float* @iio_read_image_float_vec(i8* %51, i32* %8, i32* %9, i32* %10)
store float* %52, float** %11
%53 = load i32, i32* %10
%54 = icmp ne i32 %53, 2
br i1 %54, label %55, label %57
55: ; preds = %47
%56 = call i32 @fail(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %57
57: ; preds = %55, %47
%58 = load i8*, i8** %6
%59 = call float* @iio_read_image_float_vec(i8* %58, i32* %12, i32* %13, i32* %10)
store float* %59, float** %14
%60 = load i32, i32* %8
%61 = load i32, i32* %9
%62 = mul nsw i32 %60, %61
%63 = load i32, i32* %10
%64 = mul nsw i32 %62, %63
%65 = sext i32 %64 to i64
%66 = mul i64 %65, 4
%67 = trunc i64 %66 to i32
%68 = call float* @xmalloc(i32 %67)
store float* %68, float** %15
%69 = load float*, float** %15
%70 = load float*, float** %11
%71 = load float*, float** %14
%72 = load i32, i32* %8
%73 = load i32, i32* %9
%74 = load i32, i32* %10
%75 = load i32, i32* %12
%76 = load i32, i32* %13
%77 = call i32 @invflow(float* %69, float* %70, float* %71, i32 %72, i32 %73, i32 %74, i32 %75, i32 %76)
%78 = load i8*, i8** %7
%79 = load float*, float** %15
%80 = load i32, i32* %8
%81 = load i32, i32* %9
%82 = load i32, i32* %10
%83 = call i32 @iio_save_image_float_vec(i8* %78, float* %79, i32 %80, i32 %81, i32 %82)
%84 = load i32, i32* @EXIT_SUCCESS
store i32 %84, i32* %3
br label %85
85: ; preds = %57, %24
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [28 x i8] c"usage:\0A\09%s flow [in [out]]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"-\00"
@.str.2 = [39 x i8] c"flow must have two-dimensional pixels\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main_backflow(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = add i32 %0, -2
%9 = icmp ult i32 %8, 3
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %1
%13 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
br label %59
15: ; preds = %2
%16 = icmp ugt i32 %0, 2
br i1 %16, label %17, label %24
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = icmp eq i32 %0, 3
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
br label %24
24: ; preds = %15, %17, %21
%25 = phi i8* [ %19, %21 ], [ %19, %17 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %15 ]
%26 = phi i8* [ %23, %21 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %17 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %15 ]
%27 = bitcast i32* %3 to i8*
%28 = bitcast i32* %4 to i8*
%29 = bitcast i32* %5 to i8*
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = call float* @iio_read_image_float_vec(i8* %31, i32* %3, i32* %4, i32* %5)
%33 = load i32, i32* %5
%34 = icmp eq i32 %33, 2
br i1 %34, label %37, label %35
35: ; preds = %24
%36 = call i32 @fail(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %24
%38 = bitcast i32* %6 to i8*
%39 = bitcast i32* %7 to i8*
%40 = call float* @iio_read_image_float_vec(i8* %25, i32* %6, i32* %7, i32* %5)
%41 = load i32, i32* %3
%42 = load i32, i32* %4
%43 = load i32, i32* %5
%44 = shl i32 %41, 2
%45 = mul i32 %44, %42
%46 = mul i32 %45, %43
%47 = call float* @xmalloc(i32 %46)
%48 = load i32, i32* %3
%49 = load i32, i32* %4
%50 = load i32, i32* %5
%51 = load i32, i32* %6
%52 = load i32, i32* %7
%53 = call i32 @invflow(float* %47, float* %32, float* %40, i32 %48, i32 %49, i32 %50, i32 %51, i32 %52)
%54 = load i32, i32* %3
%55 = load i32, i32* %4
%56 = load i32, i32* %5
%57 = call i32 @iio_save_image_float_vec(i8* %26, float* %47, i32 %54, i32 %55, i32 %56)
%58 = load i32, i32* @EXIT_SUCCESS
br label %59
59: ; preds = %37, %10
%60 = phi i32 [ %14, %10 ], [ %58, %37 ]
ret i32 %60
}