#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*/ printf(char *, ...);
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;
  (printf("init_coil IN\n"));
  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));
    (printf("init_coil!\n"));
    rt = yas_cdrv_actuate_initcoil();
    if (rt < 0) {
      (printf("yas_cdrv_actuate_initcoil failed[%d]\n", rt));
      return rt;
    }
    if (get_overflow(d) || !is_valid_offset(get_offset(d)))
      set_measure_state(d, (2));
    else
      set_measure_state(d, (0));
  }
  (printf("init_coil OUT\n"));
  return 0;
}


x86 assembly (clang, -O0):
<init_coil>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10c0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   10b0 <utimer_update@plt>
mov    -0x10(%rbp),%rdi
call   10e0 <get_initcoil_gaveup@plt>
cmp    $0x0,%eax
jne    1259 <init_coil+0x89>
mov    -0x10(%rbp),%rdi
call   10d0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   10b0 <utimer_update@plt>
mov    -0x10(%rbp),%rdi
call   10d0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
cmp    $0x0,%rax
je     1254 <init_coil+0x84>
mov    -0x10(%rbp),%rdi
call   10d0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1090 <utimer_clear_timeout@plt>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1060 <set_initcoil_gaveup@plt>
jmp    1259 <init_coil+0x89>
mov    -0x10(%rbp),%rdi
call   10c0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
cmp    $0x0,%rax
je     1322 <init_coil+0x152>
mov    -0x10(%rbp),%rdi
call   10e0 <get_initcoil_gaveup@plt>
cmp    $0x0,%eax
jne    1322 <init_coil+0x152>
mov    -0x10(%rbp),%rdi
call   10c0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1090 <utimer_clear_timeout@plt>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1030 <yas_cdrv_actuate_initcoil@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12d3 <init_coil+0x103>
mov    -0x14(%rbp),%esi
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1337 <init_coil+0x167>
mov    -0x10(%rbp),%rdi
call   1050 <get_overflow@plt>
cmp    $0x0,%rax
jne    12ff <init_coil+0x12f>
mov    -0x10(%rbp),%rdi
call   10f0 <get_offset@plt>
mov    %eax,%edi
call   10a0 <is_valid_offset@plt>
cmp    $0x0,%eax
jne    1312 <init_coil+0x142>
mov    -0x10(%rbp),%rdi
mov    $0x2,%esi
call   1070 <set_measure_state@plt>
jmp    131d <init_coil+0x14d>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <set_measure_state@plt>
jmp    1322 <init_coil+0x152>
lea    0xd17(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
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
lea    0xe39(%rip),%rdi
call   1070 <puts@plt>
mov    %rbx,%rdi
call   10d0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   10c0 <utimer_update@plt>
mov    %rbx,%rdi
call   10f0 <get_initcoil_gaveup@plt>
test   %eax,%eax
jne    124c <init_coil+0x6c>
mov    %rbx,%rdi
call   10e0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   10c0 <utimer_update@plt>
mov    %rbx,%rdi
call   10e0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
test   %rax,%rax
je     124c <init_coil+0x6c>
mov    %rbx,%rdi
call   10e0 <get_initcoil_giveup_timer@plt>
mov    %eax,%edi
call   10a0 <utimer_clear_timeout@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <set_initcoil_gaveup@plt>
mov    %rbx,%rdi
call   10d0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   1040 <utimer_is_timeout@plt>
test   %rax,%rax
je     12c5 <init_coil+0xe5>
mov    %rbx,%rdi
call   10f0 <get_initcoil_gaveup@plt>
test   %eax,%eax
jne    12c5 <init_coil+0xe5>
mov    %rbx,%rdi
call   10d0 <get_initcoil_timer@plt>
mov    %eax,%edi
call   10a0 <utimer_clear_timeout@plt>
lea    0xdbf(%rip),%rdi
call   1070 <puts@plt>
xor    %eax,%eax
call   1030 <yas_cdrv_actuate_initcoil@plt>
test   %eax,%eax
js     12dc <init_coil+0xfc>
mov    %rbx,%rdi
call   1050 <get_overflow@plt>
mov    $0x2,%esi
test   %rax,%rax
jne    12bd <init_coil+0xdd>
mov    %rbx,%rdi
call   1100 <get_offset@plt>
mov    %eax,%edi
call   10b0 <is_valid_offset@plt>
xor    %esi,%esi
test   %eax,%eax
sete   %sil
add    %esi,%esi
mov    %rbx,%rdi
call   1080 <set_measure_state@plt>
lea    0xd67(%rip),%rdi
call   1070 <puts@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebp
lea    0xd1b(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    12d3 <init_coil+0xf3>

LLVM IR (-O0):
%struct.yas_driver = type { i32 }
@.str = [14 x i8] c"init_coil IN\0A\00"
@.str.1 = [12 x i8] c"init_coil!\0A\00"
@.str.2 = [38 x i8] c"yas_cdrv_actuate_initcoil failed[%d]\0A\00"
@.str.3 = [15 x i8] c"init_coil OUT\0A\00"
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 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = load %struct.yas_driver*, %struct.yas_driver** %3
%7 = call i32 @get_initcoil_timer(%struct.yas_driver* %6)
%8 = call i32 @utimer_update(i32 %7)
%9 = load %struct.yas_driver*, %struct.yas_driver** %3
%10 = call i32 @get_initcoil_gaveup(%struct.yas_driver* %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %27, label %12
12: ; preds = %1
%13 = load %struct.yas_driver*, %struct.yas_driver** %3
%14 = call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %13)
%15 = call i32 @utimer_update(i32 %14)
%16 = load %struct.yas_driver*, %struct.yas_driver** %3
%17 = call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %16)
%18 = call i64 @utimer_is_timeout(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %12
%21 = load %struct.yas_driver*, %struct.yas_driver** %3
%22 = call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %21)
%23 = call i32 @utimer_clear_timeout(i32 %22)
%24 = load %struct.yas_driver*, %struct.yas_driver** %3
%25 = call i32 @set_initcoil_gaveup(%struct.yas_driver* %24, i32 1)
br label %26
26: ; preds = %20, %12
br label %27
27: ; preds = %26, %1
%28 = load %struct.yas_driver*, %struct.yas_driver** %3
%29 = call i32 @get_initcoil_timer(%struct.yas_driver* %28)
%30 = call i64 @utimer_is_timeout(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %64
32: ; preds = %27
%33 = load %struct.yas_driver*, %struct.yas_driver** %3
%34 = call i32 @get_initcoil_gaveup(%struct.yas_driver* %33)
%35 = icmp ne i32 %34, 0
br i1 %35, label %64, label %36
36: ; preds = %32
%37 = load %struct.yas_driver*, %struct.yas_driver** %3
%38 = call i32 @get_initcoil_timer(%struct.yas_driver* %37)
%39 = call i32 @utimer_clear_timeout(i32 %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%41 = call i32 (...) @yas_cdrv_actuate_initcoil()
store i32 %41, i32* %4
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %48
44: ; preds = %36
%45 = load i32, i32* %4
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = load i32, i32* %4
store i32 %47, i32* %2
br label %66
48: ; preds = %36
%49 = load %struct.yas_driver*, %struct.yas_driver** %3
%50 = call i64 @get_overflow(%struct.yas_driver* %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %57, label %52
52: ; preds = %48
%53 = load %struct.yas_driver*, %struct.yas_driver** %3
%54 = call i32 @get_offset(%struct.yas_driver* %53)
%55 = call i32 @is_valid_offset(i32 %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %60, label %57
57: ; preds = %52, %48
%58 = load %struct.yas_driver*, %struct.yas_driver** %3
%59 = call i32 @set_measure_state(%struct.yas_driver* %58, i32 2)
br label %63
60: ; preds = %52
%61 = load %struct.yas_driver*, %struct.yas_driver** %3
%62 = call i32 @set_measure_state(%struct.yas_driver* %61, i32 0)
br label %63
63: ; preds = %60, %57
br label %64
64: ; preds = %63, %32, %27
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %66
66: ; preds = %64, %44
%67 = load i32, i32* %2
ret i32 %67
}

LLVM IR (-O2):
%struct.yas_driver = type { i32 }
@.str.2 = [38 x i8] c"yas_cdrv_actuate_initcoil failed[%d]\0A\00"
@str = [13 x i8] c"init_coil IN\00"
@str.4 = [14 x i8] c"init_coil OUT\00"
@str.5 = [11 x i8] c"init_coil!\00"
define i32 @init_coil(%struct.yas_driver* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @get_initcoil_timer(%struct.yas_driver* %0)
%4 = tail call i32 @utimer_update(i32 %3)
%5 = tail call i32 @get_initcoil_gaveup(%struct.yas_driver* %0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = tail call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %0)
%9 = tail call i32 @utimer_update(i32 %8)
%10 = tail call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %0)
%11 = tail call i64 @utimer_is_timeout(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = tail call i32 @get_initcoil_giveup_timer(%struct.yas_driver* %0)
%15 = tail call i32 @utimer_clear_timeout(i32 %14)
%16 = tail call i32 @set_initcoil_gaveup(%struct.yas_driver* %0, i32 1)
br label %17
17: ; preds = %7, %13, %1
%18 = tail call i32 @get_initcoil_timer(%struct.yas_driver* %0)
%19 = tail call i64 @utimer_is_timeout(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %43, label %21
21: ; preds = %17
%22 = tail call i32 @get_initcoil_gaveup(%struct.yas_driver* %0)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %43
24: ; preds = %21
%25 = tail call i32 @get_initcoil_timer(%struct.yas_driver* %0)
%26 = tail call i32 @utimer_clear_timeout(i32 %25)
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.5, i64 0, i64 0))
%28 = tail call i32 (...) @yas_cdrv_actuate_initcoil()
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %24
%31 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %45
32: ; preds = %24
%33 = tail call i64 @get_overflow(%struct.yas_driver* %0)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = tail call i32 @get_offset(%struct.yas_driver* %0)
%37 = tail call i32 @is_valid_offset(i32 %36)
%38 = icmp eq i32 %37, 0
%39 = select i1 %38, i32 2, i32 0
br label %40
40: ; preds = %35, %32
%41 = phi i32 [ 2, %32 ], [ %39, %35 ]
%42 = tail call i32 @set_measure_state(%struct.yas_driver* %0, i32 %41)
br label %43
43: ; preds = %40, %21, %17
%44 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.4, i64 0, i64 0))
br label %45
45: ; preds = %43, %30
%46 = phi i32 [ 0, %43 ], [ %28, %30 ]
ret i32 %46
}