#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 atoi(char *);
int /*<<< orphan*/ downsa2d(float *, float *, int, int, int, int, char);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(float *);
float *iio_read_image_float_vec(char *, int *, int *, int *);
int /*<<< orphan*/ iio_save_image_float_vec(char *, float *, int, int, int);
int /*<<< orphan*/ stderr;
float *xmalloc(int);
int main_downsa(int c, char *v[]) {
  if (c != 5 && c != 4 && c != 3) {
    fprintf(stderr, "usage:\n\t%s {i|e|a|v|r|f} n [in [out]]\n", *v);
    return EXIT_FAILURE;
  }
  int n = atoi(v[2]);
  char *in = c > 3 ? v[3] : "-";
  char *out = c > 4 ? v[4] : "-";
  int w, h, pd;
  float *x = iio_read_image_float_vec(in, &w, &h, &pd);
  int W = w / n;
  int H = h / n;
  float *y = xmalloc(W * H * pd * sizeof *y);
  downsa2d(y, x, w, h, pd, n, v[1][0]);
  iio_save_image_float_vec(out, y, W, H, pd);
  free(x);
  free(y);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main_downsa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11ca <main_downsa+0x5a>
cmpl   $0x4,-0x8(%rbp)
je     11ca <main_downsa+0x5a>
cmpl   $0x3,-0x8(%rbp)
je     11ca <main_downsa+0x5a>
mov    0x2e3c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4c(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    12e7 <main_downsa+0x177>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    11f5 <main_downsa+0x85>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    1205 <main_downsa+0x95>
lea    0xe2b(%rip),%rax
mov    %rax,-0x58(%rbp)
jmp    1205 <main_downsa+0x95>
mov    -0x58(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    1228 <main_downsa+0xb8>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    1238 <main_downsa+0xc8>
lea    0xdf8(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    1238 <main_downsa+0xc8>
mov    -0x60(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x34(%rbp),%rcx
call   1050 <iio_read_image_float_vec@plt>
mov    %rax,-0x40(%rbp)
mov    -0x2c(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x44(%rbp)
mov    -0x30(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,-0x48(%rbp)
mov    -0x44(%rbp),%eax
imul   -0x48(%rbp),%eax
imul   -0x34(%rbp),%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <xmalloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    -0x34(%rbp),%r8d
mov    -0x14(%rbp),%r9d
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
mov    %eax,(%rsp)
call   1040 <downsa2d@plt>
mov    -0x28(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    -0x48(%rbp),%ecx
mov    -0x34(%rbp),%r8d
call   1080 <iio_save_image_float_vec@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_downsa>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    -0x3(%rbp),%eax
cmp    $0x3,%eax
jae    11af <main_downsa+0x3f>
mov    0x10(%rbx),%rdi
call   1090 <atoi@plt>
mov    %eax,%r12d
lea    0xe89(%rip),%rax
cmp    $0x4,%ebp
jb     11d3 <main_downsa+0x63>
mov    0x18(%rbx),%rdi
je     11d6 <main_downsa+0x66>
mov    0x20(%rbx),%rax
jmp    11d6 <main_downsa+0x66>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe3e(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e0a(%rip),%rax
jmp    1270 <main_downsa+0x100>
mov    %rax,%rdi
mov    %rax,0x20(%rsp)
lea    0x1c(%rsp),%rsi
lea    0x18(%rsp),%rdx
lea    0x14(%rsp),%rcx
call   1050 <iio_read_image_float_vec@plt>
mov    %rax,%r15
mov    0x1c(%rsp),%eax
cltd
idiv   %r12d
mov    %eax,%r13d
mov    0x18(%rsp),%eax
cltd
idiv   %r12d
mov    %eax,%ebp
mov    %r13d,%edi
imul   %eax,%edi
imul   0x14(%rsp),%edi
shl    $0x2,%edi
call   1060 <xmalloc@plt>
mov    %rax,%r14
mov    0x1c(%rsp),%edx
mov    0x18(%rsp),%ecx
mov    0x14(%rsp),%r8d
mov    0x8(%rbx),%rax
movsbl (%rax),%eax
mov    %eax,(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12d,%r9d
call   1040 <downsa2d@plt>
mov    0x14(%rsp),%r8d
mov    0x20(%rsp),%rdi
mov    %r14,%rsi
mov    %r13d,%edx
mov    %ebp,%ecx
call   1080 <iio_save_image_float_vec@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"usage:\0A\09%s {i|e|a|v|r|f} n [in [out]]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [2 x i8] c"-\00"
@EXIT_SUCCESS = global i32 0
define i32 @main_downsa(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca float*
%13 = alloca i32
%14 = alloca i32
%15 = alloca float*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 5
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 ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
store i32 %29, i32* %3
br label %93
30: ; preds = %21, %18, %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %6
%35 = load i32, i32* %4
%36 = icmp sgt i32 %35, 3
br i1 %36, label %37, label %41
37: ; preds = %30
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 3
%40 = load i8*, i8** %39
br label %42
41: ; preds = %30
br label %42
42: ; preds = %41, %37
%43 = phi i8* [ %40, %37 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %41 ]
store i8* %43, i8** %7
%44 = load i32, i32* %4
%45 = icmp sgt i32 %44, 4
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i8**, i8*** %5
%48 = getelementptr inbounds i8*, i8** %47, i64 4
%49 = load i8*, i8** %48
br label %51
50: ; preds = %42
br label %51
51: ; preds = %50, %46
%52 = phi i8* [ %49, %46 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %50 ]
store i8* %52, i8** %8
%53 = load i8*, i8** %7
%54 = call float* @iio_read_image_float_vec(i8* %53, i32* %9, i32* %10, i32* %11)
store float* %54, float** %12
%55 = load i32, i32* %9
%56 = load i32, i32* %6
%57 = sdiv i32 %55, %56
store i32 %57, i32* %13
%58 = load i32, i32* %10
%59 = load i32, i32* %6
%60 = sdiv i32 %58, %59
store i32 %60, i32* %14
%61 = load i32, i32* %13
%62 = load i32, i32* %14
%63 = mul nsw i32 %61, %62
%64 = load i32, i32* %11
%65 = mul nsw i32 %63, %64
%66 = sext i32 %65 to i64
%67 = mul i64 %66, 4
%68 = trunc i64 %67 to i32
%69 = call float* @xmalloc(i32 %68)
store float* %69, float** %15
%70 = load float*, float** %15
%71 = load float*, float** %12
%72 = load i32, i32* %9
%73 = load i32, i32* %10
%74 = load i32, i32* %11
%75 = load i32, i32* %6
%76 = load i8**, i8*** %5
%77 = getelementptr inbounds i8*, i8** %76, i64 1
%78 = load i8*, i8** %77
%79 = getelementptr inbounds i8, i8* %78, i64 0
%80 = load i8, i8* %79
%81 = call i32 @downsa2d(float* %70, float* %71, i32 %72, i32 %73, i32 %74, i32 %75, i8 signext %80)
%82 = load i8*, i8** %8
%83 = load float*, float** %15
%84 = load i32, i32* %13
%85 = load i32, i32* %14
%86 = load i32, i32* %11
%87 = call i32 @iio_save_image_float_vec(i8* %82, float* %83, i32 %84, i32 %85, i32 %86)
%88 = load float*, float** %12
%89 = call i32 @free(float* %88)
%90 = load float*, float** %15
%91 = call i32 @free(float* %90)
%92 = load i32, i32* @EXIT_SUCCESS
store i32 %92, i32* %3
br label %93
93: ; preds = %51, %24
%94 = load i32, i32* %3
ret i32 %94
}

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