#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 */
struct yas_driver {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ get_initcoil_gaveup(struct yas_driver *);
int /*<<< orphan*/ get_initcoil_giveup_timer(struct yas_driver *);
int /*<<< orphan*/ get_initcoil_timer(struct yas_driver *);
int /*<<< orphan*/ get_offset(struct yas_driver *);
scalar_t__ get_overflow(struct yas_driver *);
int /*<<< orphan*/ is_valid_offset(int /*<<< orphan*/);
int /*<<< orphan*/ set_initcoil_gaveup(struct yas_driver *, int);
int /*<<< orphan*/ set_measure_state(struct yas_driver *, int);
int /*<<< orphan*/ utimer_clear_timeout(int /*<<< orphan*/);
scalar_t__ utimer_is_timeout(int /*<<< orphan*/);
int /*<<< orphan*/ utimer_update(int /*<<< orphan*/);
int yas_cdrv_actuate_initcoil();
int init_coil(struct yas_driver *d) {
  int rt;
  ;
  utimer_update(get_initcoil_timer(d));
  if (!get_initcoil_gaveup(d)) {
    utimer_update(get_initcoil_giveup_timer(d));
    if (utimer_is_timeout(get_initcoil_giveup_timer(d))) {
      utimer_clear_timeout(get_initcoil_giveup_timer(d));
      set_initcoil_gaveup(d, (!(0)));
    }
  }
  if (utimer_is_timeout(get_initcoil_timer(d)) && !get_initcoil_gaveup(d)) {
    utimer_clear_timeout(get_initcoil_timer(d));
    ;
    rt = yas_cdrv_actuate_initcoil();
    if (rt < 0) {
      ;
      return rt;
    }
    if (get_overflow(d) || !is_valid_offset(get_offset(d)))
      set_measure_state(d, (2));
    else
      set_measure_state(d, (0));
  };
  return 0;
}


x86 assembly (clang, -O0):
<init_coil>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   10a0 <utimer_update@plt>
mov    -0x10(%rbp),%rdi
call   10d0 <get_initcoil_gaveup@plt>
cmp    $0x0,%eax
jne    123b <init_coil+0x7b>
mov    -0x10(%rbp),%rdi
call   10c0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   10a0 <utimer_update@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
cmp    $0x0,%rax
je     1236 <init_coil+0x76>
mov    -0x10(%rbp),%rdi
call   10c0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1080 <utimer_clear_timeout@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <set_initcoil_gaveup@plt>
jmp    123b <init_coil+0x7b>
mov    -0x10(%rbp),%rdi
call   10b0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
cmp    $0x0,%rax
je     12e5 <init_coil+0x125>
mov    -0x10(%rbp),%rdi
call   10d0 <get_initcoil_gaveup@plt>
cmp    $0x0,%eax
jne    12e5 <init_coil+0x125>
mov    -0x10(%rbp),%rdi
call   10b0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1080 <utimer_clear_timeout@plt>
mov    $0x0,%al
call   1030 <yas_cdrv_actuate_initcoil@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1296 <init_coil+0xd6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ec <init_coil+0x12c>
mov    -0x10(%rbp),%rdi
call   1050 <get_overflow@plt>
cmp    $0x0,%rax
jne    12c2 <init_coil+0x102>
mov    -0x10(%rbp),%rdi
call   10e0 <get_offset@plt>
mov    %eax,%edi
call   1090 <is_valid_offset@plt>
cmp    $0x0,%eax
jne    12d5 <init_coil+0x115>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1070 <set_measure_state@plt>
jmp    12e0 <init_coil+0x120>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <set_measure_state@plt>
jmp    12e5 <init_coil+0x125>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_coil>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   10b0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   10a0 <utimer_update@plt>
mov    %rbx,%rdi
call   10d0 <get_initcoil_gaveup@plt>
test   %eax,%eax
jne    121d <init_coil+0x5d>
mov    %rbx,%rdi
call   10c0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   10a0 <utimer_update@plt>
mov    %rbx,%rdi
call   10c0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
test   %rax,%rax
je     121d <init_coil+0x5d>
mov    %rbx,%rdi
call   10c0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1080 <utimer_clear_timeout@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <set_initcoil_gaveup@plt>
mov    %rbx,%rdi
call   10b0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     1292 <init_coil+0xd2>
mov    %rbx,%rdi
call   10d0 <get_initcoil_gaveup@plt>
test   %eax,%eax
jne    1292 <init_coil+0xd2>
mov    %rbx,%rdi
call   10b0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1080 <utimer_clear_timeout@plt>
xor    %eax,%eax
call   1030 <yas_cdrv_actuate_initcoil@plt>
test   %eax,%eax
js     1290 <init_coil+0xd0>
mov    %rbx,%rdi
call   1050 <get_overflow@plt>
mov    $0x2,%esi
test   %rax,%rax
jne    1284 <init_coil+0xc4>
mov    %rbx,%rdi
call   10e0 <get_offset@plt>
mov    %eax,%edi
call   1090 <is_valid_offset@plt>
xor    %esi,%esi
test   %eax,%eax
sete   %sil
add    %esi,%esi
mov    %rbx,%rdi
call   1070 <set_measure_state@plt>
xor    %ebp,%ebp
jmp    1292 <init_coil+0xd2>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.yas_driver = type { i32 }
define i32 @init_coil(%struct.yas_driver* %0) {
%2 = alloca i32
%3 = alloca %struct.yas_driver*
%4 = alloca i32
store %struct.yas_driver* %0, %struct.yas_driver** %3
%5 = load %struct.yas_driver*, %struct.yas_driver** %3
%6 = call i32 @get_initcoil_timer(%struct.yas_driver* %5)
%7 = call i32 @utimer_update(i32 %6)
%8 = load %struct.yas_driver*, %struct.yas_driver** %3
%9 = call i32 @get_initcoil_gaveup(%struct.yas_driver* %8)
%10 = icmp ne i32 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %1
%12 = load %struct.yas_driver*, %struct.yas_driver** %3
%13 = call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %12)
%14 = call i32 @utimer_update(i32 %13)
%15 = load %struct.yas_driver*, %struct.yas_driver** %3
%16 = call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %15)
%17 = call i64 @utimer_is_timeout(i32 %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %11
%20 = load %struct.yas_driver*, %struct.yas_driver** %3
%21 = call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %20)
%22 = call i32 @utimer_clear_timeout(i32 %21)
%23 = load %struct.yas_driver*, %struct.yas_driver** %3
%24 = call i32 @set_initcoil_gaveup(%struct.yas_driver* %23, i32 1)
br label %25
25: ; preds = %19, %11
br label %26
26: ; preds = %25, %1
%27 = load %struct.yas_driver*, %struct.yas_driver** %3
%28 = call i32 @get_initcoil_timer(%struct.yas_driver* %27)
%29 = call i64 @utimer_is_timeout(i32 %28)
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %60
31: ; preds = %26
%32 = load %struct.yas_driver*, %struct.yas_driver** %3
%33 = call i32 @get_initcoil_gaveup(%struct.yas_driver* %32)
%34 = icmp ne i32 %33, 0
br i1 %34, label %60, label %35
35: ; preds = %31
%36 = load %struct.yas_driver*, %struct.yas_driver** %3
%37 = call i32 @get_initcoil_timer(%struct.yas_driver* %36)
%38 = call i32 @utimer_clear_timeout(i32 %37)
%39 = call i32 (...) @yas_cdrv_actuate_initcoil()
store i32 %39, i32* %4
%40 = load i32, i32* %4
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %35
%43 = load i32, i32* %4
store i32 %43, i32* %2
br label %61
44: ; preds = %35
%45 = load %struct.yas_driver*, %struct.yas_driver** %3
%46 = call i64 @get_overflow(%struct.yas_driver* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %53, label %48
48: ; preds = %44
%49 = load %struct.yas_driver*, %struct.yas_driver** %3
%50 = call i32 @get_offset(%struct.yas_driver* %49)
%51 = call i32 @is_valid_offset(i32 %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %56, label %53
53: ; preds = %48, %44
%54 = load %struct.yas_driver*, %struct.yas_driver** %3
%55 = call i32 @set_measure_state(%struct.yas_driver* %54, i32 2)
br label %59
56: ; preds = %48
%57 = load %struct.yas_driver*, %struct.yas_driver** %3
%58 = call i32 @set_measure_state(%struct.yas_driver* %57, i32 0)
br label %59
59: ; preds = %56, %53
br label %60
60: ; preds = %59, %31, %26
store i32 0, i32* %2
br label %61
61: ; preds = %60, %42
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
%struct.yas_driver = type { i32 }
define i32 @init_coil(%struct.yas_driver* %0) {
%2 = tail call i32 @get_initcoil_timer(%struct.yas_driver* %0)
%3 = tail call i32 @utimer_update(i32 %2)
%4 = tail call i32 @get_initcoil_gaveup(%struct.yas_driver* %0)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %16
6: ; preds = %1
%7 = tail call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %0)
%8 = tail call i32 @utimer_update(i32 %7)
%9 = tail call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %0)
%10 = tail call i64 @utimer_is_timeout(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %6
%13 = tail call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %0)
%14 = tail call i32 @utimer_clear_timeout(i32 %13)
%15 = tail call i32 @set_initcoil_gaveup(%struct.yas_driver* %0, i32 1)
br label %16
16: ; preds = %6, %12, %1
%17 = tail call i32 @get_initcoil_timer(%struct.yas_driver* %0)
%18 = tail call i64 @utimer_is_timeout(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %39, label %20
20: ; preds = %16
%21 = tail call i32 @get_initcoil_gaveup(%struct.yas_driver* %0)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = tail call i32 @get_initcoil_timer(%struct.yas_driver* %0)
%25 = tail call i32 @utimer_clear_timeout(i32 %24)
%26 = tail call i32 (...) @yas_cdrv_actuate_initcoil()
%27 = icmp slt i32 %26, 0
br i1 %27, label %39, label %28
28: ; preds = %23
%29 = tail call i64 @get_overflow(%struct.yas_driver* %0)
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = tail call i32 @get_offset(%struct.yas_driver* %0)
%33 = tail call i32 @is_valid_offset(i32 %32)
%34 = icmp eq i32 %33, 0
%35 = select i1 %34, i32 2, i32 0
br label %36
36: ; preds = %31, %28
%37 = phi i32 [ 2, %28 ], [ %35, %31 ]
%38 = tail call i32 @set_measure_state(%struct.yas_driver* %0, i32 %37)
br label %39
39: ; preds = %36, %16, %20, %23
%40 = phi i32 [ %26, %23 ], [ 0, %20 ], [ 0, %16 ], [ 0, %36 ]
ret i32 %40
}