#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*/ fprintf(int /*<<< orphan*/, 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;
int main(int c, char *v[]) {
  if (c != 3) {
    fprintf(stderr, "usage:\n\t%s infile outfile\n", *v);
    return 1;
  }
  int w, h, pixeldim;
  float *x = iio_read_image_float_vec(v[1], &w, &h, &pixeldim);
  if (!x) {
    fprintf(stderr,
            "failed to read an image from file "
            "\"%s\"\n",
            v[1]);
    return 1;
  }
  fprintf(stderr, "got a %dx%d image with %d channels\n", w, h, pixeldim);
  for (int i = 0; i < pixeldim; i++)
    fprintf(stderr, "p0: %g\n", (float)x[i]);
  iio_save_image_float_vec(v[2], x, w, h, pixeldim);
  free(x);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     118a <main+0x4a>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x132>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1040 <iio_read_image_float_vec@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11dd <main+0x9d>
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe51(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1272 <main+0x132>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe4c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1247 <main+0x107>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe35(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1205 <main+0xc5>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
call   1060 <iio_save_image_float_vec@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r15
cmp    $0x3,%edi
jne    1204 <main+0xc4>
mov    0x8(%r15),%rdi
lea    0x14(%rsp),%rsi
lea    0x10(%rsp),%rdx
lea    0xc(%rsp),%rcx
call   1040 <iio_read_image_float_vec@plt>
mov    0x2e67(%rip),%r12
mov    (%r12),%edi
test   %rax,%rax
je     1219 <main+0xd9>
mov    %rax,%rbp
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    0xc(%rsp),%r8d
lea    0xea6(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0xc(%rsp),%r8d
test   %r8d,%r8d
jle    11e6 <main+0xa6>
xor    %ebx,%ebx
lea    0xead(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edi
movss  0x0(%rbp,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r13,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0x1,%rbx
movslq 0xc(%rsp),%r8
cmp    %r8,%rbx
jl     11c0 <main+0x80>
mov    0x10(%r15),%rdi
mov    0x14(%rsp),%edx
mov    0x10(%rsp),%ecx
mov    %rbp,%rsi
call   1060 <iio_save_image_float_vec@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
jmp    1231 <main+0xf1>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rdx
lea    0xde9(%rip),%rsi
jmp    1224 <main+0xe4>
mov    0x8(%r15),%rdx
lea    0xdf7(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [27 x i8] c"usage:\0A\09%s infile outfile\0A\00"
@.str.1 = [40 x i8] c"failed to read an image from file \22%s\22\0A\00"
@.str.2 = [36 x i8] c"got a %dx%d image with %d channels\0A\00"
@.str.3 = [8 x i8] c"p0: %g\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca float*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 3
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = load i8*, i8** %15
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %64
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call float* @iio_read_image_float_vec(i8* %21, i32* %6, i32* %7, i32* %8)
store float* %22, float** %9
%23 = load float*, float** %9
%24 = icmp ne float* %23, null
br i1 %24, label %31, label %25
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %29)
store i32 1, i32* %3
br label %64
31: ; preds = %18
%32 = load i32, i32* @stderr
%33 = load i32, i32* %6
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %34, i32 %35)
store i32 0, i32* %10
br label %37
37: ; preds = %50, %31
%38 = load i32, i32* %10
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %53
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = load float*, float** %9
%44 = load i32, i32* %10
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds float, float* %43, i64 %45
%47 = load float, float* %46
%48 = fpext float %47 to double
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %48)
br label %50
50: ; preds = %41
%51 = load i32, i32* %10
%52 = add nsw i32 %51, 1
store i32 %52, i32* %10
br label %37
53: ; preds = %37
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 2
%56 = load i8*, i8** %55
%57 = load float*, float** %9
%58 = load i32, i32* %6
%59 = load i32, i32* %7
%60 = load i32, i32* %8
%61 = call i32 @iio_save_image_float_vec(i8* %56, float* %57, i32 %58, i32 %59, i32 %60)
%62 = load float*, float** %9
%63 = call i32 @free(float* %62)
store i32 0, i32* %3
br label %64
64: ; preds = %53, %25, %13
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [27 x i8] c"usage:\0A\09%s infile outfile\0A\00"
@.str.1 = [40 x i8] c"failed to read an image from file \22%s\22\0A\00"
@.str.2 = [36 x i8] c"got a %dx%d image with %d channels\0A\00"
@.str.3 = [8 x i8] c"p0: %g\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = icmp eq i32 %0, 3
br i1 %6, label %11, label %7
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %1
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %9)
br label %51
11: ; preds = %2
%12 = bitcast i32* %3 to i8*
%13 = bitcast i32* %4 to i8*
%14 = bitcast i32* %5 to i8*
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = call float* @iio_read_image_float_vec(i8* %16, i32* %3, i32* %4, i32* %5)
%18 = icmp eq float* %17, null
%19 = load i32, i32* @stderr
br i1 %18, label %20, label %23
20: ; preds = %11
%21 = load i8*, i8** %15
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %49
23: ; preds = %11
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = load i32, i32* %5
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %24, i32 %25, i32 %26)
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 0
br i1 %29, label %38, label %30
30: ; preds = %38, %23
%31 = phi i32 [ %28, %23 ], [ %46, %38 ]
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
%34 = load i32, i32* %3
%35 = load i32, i32* %4
%36 = call i32 @iio_save_image_float_vec(i8* %33, float* %17, i32 %34, i32 %35, i32 %31)
%37 = call i32 @free(float* %17)
br label %49
38: ; preds = %23, %38
%39 = phi i64 [ %45, %38 ], [ 0, %23 ]
%40 = load i32, i32* @stderr
%41 = getelementptr inbounds float, float* %17, i64 %39
%42 = load float, float* %41
%43 = fpext float %42 to double
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), double %43)
%45 = add nuw nsw i64 %39, 1
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = icmp slt i64 %45, %47
br i1 %48, label %38, label %30
49: ; preds = %30, %20
%50 = phi i32 [ 0, %30 ], [ 1, %20 ]
br label %51
51: ; preds = %49, %7
%52 = phi i32 [ 1, %7 ], [ %50, %49 ]
ret i32 %52
}