#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*/ delayUsBusy(int);
int /*<<< orphan*/ pinHigh(int);
int /*<<< orphan*/ pinLow(int);
int /*<<< orphan*/ pinModeIn(int);
int /*<<< orphan*/ pinModeOut(int);
int /*<<< orphan*/ pinPUD(int, int /*<<< orphan*/);
scalar_t__ pinRead(int);
int onewire_reset(int pin) {
  pinPUD(pin, 0);
  pinModeOut(pin);
  pinLow(pin);
  delayUsBusy(640);
  pinHigh(pin);
  pinModeIn(pin);
  for (int i = 80; i; i--) {
    if (!pinRead(pin)) {
      for (int i = 250; i; i--) {
        if (pinRead(pin)) {
          return 1;
        }
        delayUsBusy(1);
      }
      return 0;
    }
    delayUsBusy(1);
  }
  delayUsBusy(1);
  return 0;
}


x86 assembly (clang, -O0):
<onewire_reset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1050 <pinPUD@plt>
mov    -0x8(%rbp),%edi
call   1060 <pinModeOut@plt>
mov    -0x8(%rbp),%edi
call   1080 <pinLow@plt>
mov    $0x280,%edi
call   1030 <delayUsBusy@plt>
mov    -0x8(%rbp),%edi
call   1040 <pinHigh@plt>
mov    -0x8(%rbp),%edi
call   1070 <pinModeIn@plt>
movl   $0x50,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     123d <onewire_reset+0xcd>
mov    -0x8(%rbp),%edi
call   1090 <pinRead@plt>
cmp    $0x0,%rax
jne    1225 <onewire_reset+0xb5>
movl   $0xfa,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1219 <onewire_reset+0xa9>
mov    -0x8(%rbp),%edi
call   1090 <pinRead@plt>
cmp    $0x0,%rax
je     1201 <onewire_reset+0x91>
movl   $0x1,-0x4(%rbp)
jmp    124e <onewire_reset+0xde>
mov    $0x1,%edi
call   1030 <delayUsBusy@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11d9 <onewire_reset+0x69>
movl   $0x0,-0x4(%rbp)
jmp    124e <onewire_reset+0xde>
mov    $0x1,%edi
call   1030 <delayUsBusy@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11b6 <onewire_reset+0x46>
mov    $0x1,%edi
call   1030 <delayUsBusy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<onewire_reset>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebx
xor    %esi,%esi
call   1050 <pinPUD@plt>
mov    %ebx,%edi
call   1060 <pinModeOut@plt>
mov    %ebx,%edi
call   1080 <pinLow@plt>
mov    $0x280,%edi
call   1030 <delayUsBusy@plt>
mov    %ebx,%edi
call   1040 <pinHigh@plt>
mov    %ebx,%edi
call   1070 <pinModeIn@plt>
mov    $0xffffffb0,%ebp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1090 <pinRead@plt>
test   %rax,%rax
je     11d6 <onewire_reset+0x66>
mov    $0x1,%edi
call   1030 <delayUsBusy@plt>
inc    %ebp
jne    11b0 <onewire_reset+0x40>
mov    $0x1,%edi
call   1030 <delayUsBusy@plt>
jmp    120a <onewire_reset+0x9a>
mov    $0xffffff06,%ebp
mov    $0x1,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1090 <pinRead@plt>
test   %rax,%rax
jne    120d <onewire_reset+0x9d>
mov    $0x1,%edi
call   1030 <delayUsBusy@plt>
inc    %ebp
jne    11f0 <onewire_reset+0x80>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @onewire_reset(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = call i32 @pinPUD(i32 %6, i32 0)
%8 = load i32, i32* %3
%9 = call i32 @pinModeOut(i32 %8)
%10 = load i32, i32* %3
%11 = call i32 @pinLow(i32 %10)
%12 = call i32 @delayUsBusy(i32 640)
%13 = load i32, i32* %3
%14 = call i32 @pinHigh(i32 %13)
%15 = load i32, i32* %3
%16 = call i32 @pinModeIn(i32 %15)
store i32 80, i32* %4
br label %17
17: ; preds = %41, %1
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %44
20: ; preds = %17
%21 = load i32, i32* %3
%22 = call i64 @pinRead(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %39, label %24
24: ; preds = %20
store i32 250, i32* %5
br label %25
25: ; preds = %35, %24
%26 = load i32, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32, i32* %3
%30 = call i64 @pinRead(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 1, i32* %2
br label %46
33: ; preds = %28
%34 = call i32 @delayUsBusy(i32 1)
br label %35
35: ; preds = %33
%36 = load i32, i32* %5
%37 = add nsw i32 %36, -1
store i32 %37, i32* %5
br label %25
38: ; preds = %25
store i32 0, i32* %2
br label %46
39: ; preds = %20
%40 = call i32 @delayUsBusy(i32 1)
br label %41
41: ; preds = %39
%42 = load i32, i32* %4
%43 = add nsw i32 %42, -1
store i32 %43, i32* %4
br label %17
44: ; preds = %17
%45 = call i32 @delayUsBusy(i32 1)
store i32 0, i32* %2
br label %46
46: ; preds = %44, %38, %32
%47 = load i32, i32* %2
ret i32 %47
}

LLVM IR (-O2):
define i32 @onewire_reset(i32 %0) {
%2 = tail call i32 @pinPUD(i32 %0, i32 0)
%3 = tail call i32 @pinModeOut(i32 %0)
%4 = tail call i32 @pinLow(i32 %0)
%5 = tail call i32 @delayUsBusy(i32 640)
%6 = tail call i32 @pinHigh(i32 %0)
%7 = tail call i32 @pinModeIn(i32 %0)
br label %8
8: ; preds = %1, %20
%9 = phi i32 [ 80, %1 ], [ %22, %20 ]
%10 = tail call i64 @pinRead(i32 %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8, %16
%13 = phi i32 [ %18, %16 ], [ 250, %8 ]
%14 = tail call i64 @pinRead(i32 %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %12
%17 = tail call i32 @delayUsBusy(i32 1)
%18 = add nsw i32 %13, -1
%19 = icmp eq i32 %18, 0
br i1 %19, label %26, label %12
20: ; preds = %8
%21 = tail call i32 @delayUsBusy(i32 1)
%22 = add nsw i32 %9, -1
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %8
24: ; preds = %20
%25 = tail call i32 @delayUsBusy(i32 1)
br label %26
26: ; preds = %12, %16, %24
%27 = phi i32 [ 0, %24 ], [ 1, %12 ], [ 0, %16 ]
ret i32 %27
}