#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 read_ec(int, unsigned char *);
int write_ec(int, int);
int turn_on_fans() {
  unsigned char val;
  int ret = write_ec(147, 4);
  ret &= write_ec(150, 4);
  ret &= read_ec(147, &val);
  ret &= (val == 4);
  ret &= read_ec(150, &val);
  ret &= (val == 4);
  return ret;
}


x86 assembly (clang, -O0):
<turn_on_fans>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x93,%edi
mov    $0x4,%esi
call   1040 <write_ec@plt>
mov    %eax,-0x8(%rbp)
mov    $0x96,%edi
mov    $0x4,%esi
call   1040 <write_ec@plt>
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x93,%edi
lea    -0x1(%rbp),%rsi
call   1030 <read_ec@plt>
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    $0x96,%edi
lea    -0x1(%rbp),%rsi
call   1030 <read_ec@plt>
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
movzbl -0x1(%rbp),%eax
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
and    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<turn_on_fans>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x93,%edi
mov    $0x4,%esi
call   1040 <write_ec@plt>
mov    %eax,%ebx
mov    $0x96,%edi
mov    $0x4,%esi
call   1040 <write_ec@plt>
mov    %eax,%ebp
and    %ebx,%ebp
lea    0x7(%rsp),%r14
mov    $0x93,%edi
mov    %r14,%rsi
call   1030 <read_ec@plt>
mov    %eax,%r15d
xor    %ebx,%ebx
cmpb   $0x4,0x7(%rsp)
sete   %bl
mov    $0x96,%edi
mov    %r14,%rsi
call   1030 <read_ec@plt>
xor    %ecx,%ecx
cmpb   $0x4,0x7(%rsp)
sete   %cl
and    %r15d,%eax
and    %ebp,%eax
and    %ebx,%eax
and    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @turn_on_fans() {
%1 = alloca i8
%2 = alloca i32
%3 = call i32 @write_ec(i32 147, i32 4)
store i32 %3, i32* %2
%4 = call i32 @write_ec(i32 150, i32 4)
%5 = load i32, i32* %2
%6 = and i32 %5, %4
store i32 %6, i32* %2
%7 = call i32 @read_ec(i32 147, i8* %1)
%8 = load i32, i32* %2
%9 = and i32 %8, %7
store i32 %9, i32* %2
%10 = load i8, i8* %1
%11 = zext i8 %10 to i32
%12 = icmp eq i32 %11, 4
%13 = zext i1 %12 to i32
%14 = load i32, i32* %2
%15 = and i32 %14, %13
store i32 %15, i32* %2
%16 = call i32 @read_ec(i32 150, i8* %1)
%17 = load i32, i32* %2
%18 = and i32 %17, %16
store i32 %18, i32* %2
%19 = load i8, i8* %1
%20 = zext i8 %19 to i32
%21 = icmp eq i32 %20, 4
%22 = zext i1 %21 to i32
%23 = load i32, i32* %2
%24 = and i32 %23, %22
store i32 %24, i32* %2
%25 = load i32, i32* %2
ret i32 %25
}

LLVM IR (-O2):
define i32 @turn_on_fans() {
%1 = alloca i8
%2 = tail call i32 @write_ec(i32 147, i32 4)
%3 = tail call i32 @write_ec(i32 150, i32 4)
%4 = and i32 %3, %2
%5 = call i32 @read_ec(i32 147, i8* %1)
%6 = and i32 %4, %5
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 4
%9 = zext i1 %8 to i32
%10 = call i32 @read_ec(i32 150, i8* %1)
%11 = load i8, i8* %1
%12 = icmp eq i8 %11, 4
%13 = zext i1 %12 to i32
%14 = and i32 %6, %10
%15 = and i32 %14, %9
%16 = and i32 %15, %13
ret i32 %16
}