#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 uint16_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ SEEK_SET;
int atoi(char *);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
char read(int, char *, int);
uint16_t ainTransfer(int fd, int port) {
  int i;
  char buf[16];
  char actual;
  int val, sum, min, max;
  uint16_t retVal;
  lseek(fd, 0, SEEK_SET);
  actual = read(fd, buf, sizeof(buf) - 1);
  buf[actual] = '\0';
  min = val = atoi(buf);
  max = 0;
  sum = 0;
  for (i = 17; i; --i) {
    lseek(fd, 0, SEEK_SET);
    actual = read(fd, buf, sizeof(buf) - 1);
    if (actual > 0) {
      buf[actual] = '\0';
      val = atoi(buf);
    };
    if (val < min) {
      sum += min;
      min = val;
    } else if (val > max) {
      sum += max;
      max = val;
    } else {
      sum += val;
    };
  };
  retVal = sum * (218.0 / 118);
  return retVal;
}


x86 assembly (clang, -O0):
<ainTransfer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2e98(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xf,%edx
call   1040 <read@plt>
mov    %al,-0x21(%rbp)
movsbq -0x21(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    %eax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x11,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1248 <ainTransfer+0x118>
mov    -0x4(%rbp),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xf,%edx
call   1040 <read@plt>
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jle    11e7 <ainTransfer+0xb7>
movsbq -0x21(%rbp),%rax
movb   $0x0,-0x20(%rbp,%rax,1)
lea    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x30(%rbp),%eax
jge    1207 <ainTransfer+0xd7>
mov    -0x30(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x30(%rbp)
jmp    1235 <ainTransfer+0x105>
mov    -0x28(%rbp),%eax
cmp    -0x34(%rbp),%eax
jle    1227 <ainTransfer+0xf7>
mov    -0x34(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%eax
mov    %eax,-0x34(%rbp)
jmp    1230 <ainTransfer+0x100>
mov    -0x28(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    1235 <ainTransfer+0x105>
jmp    123a <ainTransfer+0x10a>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1193 <ainTransfer+0x63>
cvtsi2sdl -0x2c(%rbp),%xmm0
movsd  0xdab(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ainTransfer>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebp
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
xor    %r12d,%r12d
xor    %esi,%esi
call   1030 <lseek@plt>
lea    0x10(%rsp),%r14
mov    %ebp,0x8(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xf,%edx
call   1040 <read@plt>
movsbq %al,%rax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r14,%rdi
call   1050 <atoi@plt>
mov    %eax,%ebp
mov    $0xffffffef,%eax
xor    %r14d,%r14d
mov    %ebp,%r13d
mov    0x8(%rsp),%ebx
jmp    11ba <ainTransfer+0x8a>
nop
cmp    %r12d,%r13d
mov    %r13d,%eax
cmovg  %r12d,%eax
mov    %r12d,%ecx
cmovg  %r13d,%ecx
cmp    %ebp,%r13d
cmovl  %ebp,%eax
cmovl  %r13d,%ebp
cmovge %ecx,%r12d
add    %eax,%r14d
mov    0xc(%rsp),%eax
inc    %eax
je     11fd <ainTransfer+0xcd>
mov    %eax,0xc(%rsp)
mov    0x2e1b(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %ebx,%edi
lea    0x10(%rsp),%r15
mov    %r15,%rsi
mov    $0xf,%edx
call   1040 <read@plt>
test   %al,%al
jle    1190 <ainTransfer+0x60>
movzbl %al,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %r15,%rdi
call   1050 <atoi@plt>
mov    %eax,%r13d
jmp    1190 <ainTransfer+0x60>
cvtsi2sd %r14d,%xmm0
mulsd  0xdf6(%rip),%xmm0
cvttsd2si %xmm0,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_SET = global i32 0
define i32 @ainTransfer(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [16 x i8]
%7 = alloca i8
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%13 = load i32, i32* %3
%14 = load i32, i32* @SEEK_SET
%15 = call i32 @lseek(i32 %13, i32 0, i32 %14)
%16 = load i32, i32* %3
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%18 = call signext i8 @read(i32 %16, i8* %17, i32 15)
store i8 %18, i8* %7
%19 = load i8, i8* %7
%20 = sext i8 %19 to i64
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %20
store i8 0, i8* %21
%22 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %8
store i32 %23, i32* %10
store i32 0, i32* %11
store i32 0, i32* %9
store i32 17, i32* %5
br label %24
24: ; preds = %67, %2
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %70
27: ; preds = %24
%28 = load i32, i32* %3
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @lseek(i32 %28, i32 0, i32 %29)
%31 = load i32, i32* %3
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%33 = call signext i8 @read(i32 %31, i8* %32, i32 15)
store i8 %33, i8* %7
%34 = load i8, i8* %7
%35 = sext i8 %34 to i32
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %43
37: ; preds = %27
%38 = load i8, i8* %7
%39 = sext i8 %38 to i64
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 %39
store i8 0, i8* %40
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%42 = call i32 @atoi(i8* %41)
store i32 %42, i32* %8
br label %43
43: ; preds = %37, %27
%44 = load i32, i32* %8
%45 = load i32, i32* %10
%46 = icmp slt i32 %44, %45
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i32, i32* %10
%49 = load i32, i32* %9
%50 = add nsw i32 %49, %48
store i32 %50, i32* %9
%51 = load i32, i32* %8
store i32 %51, i32* %10
br label %66
52: ; preds = %43
%53 = load i32, i32* %8
%54 = load i32, i32* %11
%55 = icmp sgt i32 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %52
%57 = load i32, i32* %11
%58 = load i32, i32* %9
%59 = add nsw i32 %58, %57
store i32 %59, i32* %9
%60 = load i32, i32* %8
store i32 %60, i32* %11
br label %65
61: ; preds = %52
%62 = load i32, i32* %8
%63 = load i32, i32* %9
%64 = add nsw i32 %63, %62
store i32 %64, i32* %9
br label %65
65: ; preds = %61, %56
br label %66
66: ; preds = %65, %47
br label %67
67: ; preds = %66
%68 = load i32, i32* %5
%69 = add nsw i32 %68, -1
store i32 %69, i32* %5
br label %24
70: ; preds = %24
%71 = load i32, i32* %9
%72 = sitofp i32 %71 to double
%73 = fmul double %72, 0x3FFD8F2FBA938682
%74 = fptosi double %73 to i32
store i32 %74, i32* %12
%75 = load i32, i32* %12
ret i32 %75
}

LLVM IR (-O2):
@SEEK_SET = global i32 0
define i32 @ainTransfer(i32 %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = load i32, i32* @SEEK_SET
%6 = tail call i32 @lseek(i32 %0, i32 0, i32 %5)
%7 = call signext i8 @read(i32 %0, i8* %4, i32 15)
%8 = sext i8 %7 to i64
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %8
store i8 0, i8* %9
%10 = call i32 @atoi(i8* %4)
br label %11
11: ; preds = %2, %25
%12 = phi i32 [ 17, %2 ], [ %35, %25 ]
%13 = phi i32 [ 0, %2 ], [ %33, %25 ]
%14 = phi i32 [ %10, %2 ], [ %32, %25 ]
%15 = phi i32 [ 0, %2 ], [ %34, %25 ]
%16 = phi i32 [ %10, %2 ], [ %26, %25 ]
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @lseek(i32 %0, i32 0, i32 %17)
%19 = call signext i8 @read(i32 %0, i8* %4, i32 15)
%20 = icmp sgt i8 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %11
%22 = zext i8 %19 to i64
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 %22
store i8 0, i8* %23
%24 = call i32 @atoi(i8* %4)
br label %25
25: ; preds = %21, %11
%26 = phi i32 [ %24, %21 ], [ %16, %11 ]
%27 = icmp slt i32 %26, %14
%28 = icmp sgt i32 %26, %13
%29 = select i1 %28, i32 %13, i32 %26
%30 = select i1 %28, i32 %26, i32 %13
%31 = select i1 %27, i32 %14, i32 %29
%32 = select i1 %27, i32 %26, i32 %14
%33 = select i1 %27, i32 %13, i32 %30
%34 = add nsw i32 %31, %15
%35 = add nsw i32 %12, -1
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %11
37: ; preds = %25
%38 = sitofp i32 %34 to double
%39 = fmul double %38, 0x3FFD8F2FBA938682
%40 = fptosi double %39 to i32
ret i32 %40
}