#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*/ TOSH_CLR_GIO1_PIN();
int /*<<< orphan*/ TOSH_MAKE_ADC2_INPUT();
int /*<<< orphan*/ TOSH_MAKE_GIO1_INPUT();
int /*<<< orphan*/ TOSH_MAKE_GIO1_OUTPUT();
unsigned char TOSH_READ_GIO1_PIN();
int /*<<< orphan*/ TOSH_SEL_ADC2_IOFUNC();
int /*<<< orphan*/ TOSH_SEL_GIO1_IOFUNC();
int /*<<< orphan*/ TOSH_uwait(int);
unsigned char ds2770_init(void) {
  unsigned char presence;
  TOSH_SEL_ADC2_IOFUNC();
  TOSH_MAKE_ADC2_INPUT();
  TOSH_SEL_GIO1_IOFUNC();
  TOSH_MAKE_GIO1_OUTPUT();
  TOSH_CLR_GIO1_PIN();
  TOSH_uwait(300);
  TOSH_MAKE_GIO1_INPUT();
  TOSH_uwait(40);
  presence = TOSH_READ_GIO1_PIN();
  TOSH_uwait(250);
  return !presence;
}


x86 assembly (clang, -O0):
<ds2770_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <TOSH_SEL_ADC2_IOFUNC@plt>
mov    $0x0,%al
call   10a0 <TOSH_MAKE_ADC2_INPUT@plt>
mov    $0x0,%al
call   1030 <TOSH_SEL_GIO1_IOFUNC@plt>
mov    $0x0,%al
call   1050 <TOSH_MAKE_GIO1_OUTPUT@plt>
mov    $0x0,%al
call   1080 <TOSH_CLR_GIO1_PIN@plt>
mov    $0x12c,%edi
call   1090 <TOSH_uwait@plt>
mov    $0x0,%al
call   1070 <TOSH_MAKE_GIO1_INPUT@plt>
mov    $0x28,%edi
call   1090 <TOSH_uwait@plt>
mov    $0x0,%al
call   1060 <TOSH_READ_GIO1_PIN@plt>
mov    %al,-0x1(%rbp)
mov    $0xfa,%edi
call   1090 <TOSH_uwait@plt>
cmpb   $0x0,-0x1(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ds2770_init>:
push   %rbx
xor    %eax,%eax
call   1040 <TOSH_SEL_ADC2_IOFUNC@plt>
xor    %eax,%eax
call   10a0 <TOSH_MAKE_ADC2_INPUT@plt>
xor    %eax,%eax
call   1030 <TOSH_SEL_GIO1_IOFUNC@plt>
xor    %eax,%eax
call   1050 <TOSH_MAKE_GIO1_OUTPUT@plt>
xor    %eax,%eax
call   1080 <TOSH_CLR_GIO1_PIN@plt>
mov    $0x12c,%edi
call   1090 <TOSH_uwait@plt>
xor    %eax,%eax
call   1070 <TOSH_MAKE_GIO1_INPUT@plt>
mov    $0x28,%edi
call   1090 <TOSH_uwait@plt>
xor    %eax,%eax
call   1060 <TOSH_READ_GIO1_PIN@plt>
mov    %eax,%ebx
mov    $0xfa,%edi
call   1090 <TOSH_uwait@plt>
test   %bl,%bl
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
define zeroext i8 @ds2770_init() {
%1 = alloca i8
%2 = call i32 (...) @TOSH_SEL_ADC2_IOFUNC()
%3 = call i32 (...) @TOSH_MAKE_ADC2_INPUT()
%4 = call i32 (...) @TOSH_SEL_GIO1_IOFUNC()
%5 = call i32 (...) @TOSH_MAKE_GIO1_OUTPUT()
%6 = call i32 (...) @TOSH_CLR_GIO1_PIN()
%7 = call i32 @TOSH_uwait(i32 300)
%8 = call i32 (...) @TOSH_MAKE_GIO1_INPUT()
%9 = call i32 @TOSH_uwait(i32 40)
%10 = call zeroext i8 (...) @TOSH_READ_GIO1_PIN()
store i8 %10, i8* %1
%11 = call i32 @TOSH_uwait(i32 250)
%12 = load i8, i8* %1
%13 = icmp ne i8 %12, 0
%14 = xor i1 %13, true
%15 = zext i1 %14 to i32
%16 = trunc i32 %15 to i8
ret i8 %16
}

LLVM IR (-O2):
define zeroext i8 @ds2770_init() {
%1 = tail call i32 (...) @TOSH_SEL_ADC2_IOFUNC()
%2 = tail call i32 (...) @TOSH_MAKE_ADC2_INPUT()
%3 = tail call i32 (...) @TOSH_SEL_GIO1_IOFUNC()
%4 = tail call i32 (...) @TOSH_MAKE_GIO1_OUTPUT()
%5 = tail call i32 (...) @TOSH_CLR_GIO1_PIN()
%6 = tail call i32 @TOSH_uwait(i32 300)
%7 = tail call i32 (...) @TOSH_MAKE_GIO1_INPUT()
%8 = tail call i32 @TOSH_uwait(i32 40)
%9 = tail call zeroext i8 (...) @TOSH_READ_GIO1_PIN()
%10 = tail call i32 @TOSH_uwait(i32 250)
%11 = icmp eq i8 %9, 0
%12 = zext i1 %11 to i8
ret i8 %12
}