#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 curs_set(int);
void set_cursor_state(int on) {
  static int normal_state = -1;
  static int on_last;
  if (normal_state < 0 && !on) {
    normal_state = curs_set(0);
    on_last = on;
  } else if (on != on_last) {
    curs_set(on ? normal_state : 0);
    on_last = on;
  }
}


x86 assembly (clang, -O0):
<set_cursor_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,0x2f06(%rip)
jge    114d <set_cursor_state+0x3d>
cmpl   $0x0,-0x4(%rbp)
jne    114d <set_cursor_state+0x3d>
xor    %edi,%edi
call   1030 <curs_set@plt>
mov    %eax,0x2ee9(%rip)
mov    -0x4(%rbp),%eax
mov    %eax,0x2ee8(%rip)
jmp    1194 <set_cursor_state+0x84>
mov    -0x4(%rbp),%eax
cmp    0x2eda(%rip),%eax
je     118f <set_cursor_state+0x7f>
cmpl   $0x0,-0x4(%rbp)
je     1174 <set_cursor_state+0x64>
mov    0x2ebc(%rip),%eax
mov    %eax,-0x8(%rbp)
jmp    117e <set_cursor_state+0x6e>
xor    %eax,%eax
mov    %eax,-0x8(%rbp)
jmp    117e <set_cursor_state+0x6e>
mov    -0x8(%rbp),%edi
call   1030 <curs_set@plt>
mov    -0x4(%rbp),%eax
mov    %eax,0x2ea1(%rip)
jmp    1194 <set_cursor_state+0x84>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_cursor_state>:
push   %rbx
mov    %edi,%ebx
mov    0x2f0f(%rip),%edi
test   %ebx,%ebx
jne    1132 <set_cursor_state+0x22>
test   %edi,%edi
jns    1132 <set_cursor_state+0x22>
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <curs_set@plt>
mov    %eax,0x2ef8(%rip)
jmp    1144 <set_cursor_state+0x34>
cmp    %ebx,0x2ef8(%rip)
je     114a <set_cursor_state+0x3a>
test   %ebx,%ebx
cmove  %ebx,%edi
call   1030 <curs_set@plt>
mov    %ebx,0x2ee6(%rip)
pop    %rbx
ret

LLVM IR (-O0):
@set_cursor_state.normal_state = internal global i32 -1
@set_cursor_state.on_last = internal global i32 0
define void @set_cursor_state(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* @set_cursor_state.normal_state
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %5
%9 = call i32 @curs_set(i32 0)
store i32 %9, i32* @set_cursor_state.normal_state
%10 = load i32, i32* %2
store i32 %10, i32* @set_cursor_state.on_last
br label %26
11: ; preds = %5, %1
%12 = load i32, i32* %2
%13 = load i32, i32* @set_cursor_state.on_last
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load i32, i32* %2
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load i32, i32* @set_cursor_state.normal_state
br label %21
20: ; preds = %15
br label %21
21: ; preds = %20, %18
%22 = phi i32 [ %19, %18 ], [ 0, %20 ]
%23 = call i32 @curs_set(i32 %22)
%24 = load i32, i32* %2
store i32 %24, i32* @set_cursor_state.on_last
br label %25
25: ; preds = %21, %11
br label %26
26: ; preds = %25, %8
ret void
}

LLVM IR (-O2):
@set_cursor_state.normal_state = internal unnamed_addr global i32 -1
@set_cursor_state.on_last = internal unnamed_addr global i32 0
define void @set_cursor_state(i32 %0) {
%2 = load i32, i32* @set_cursor_state.normal_state
%3 = icmp sgt i32 %2, -1
%4 = icmp ne i32 %0, 0
%5 = or i1 %4, %3
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @curs_set(i32 0)
store i32 %7, i32* @set_cursor_state.normal_state
br label %14
8: ; preds = %1
%9 = load i32, i32* @set_cursor_state.on_last
%10 = icmp eq i32 %9, %0
br i1 %10, label %16, label %11
11: ; preds = %8
%12 = select i1 %4, i32 %2, i32 0
%13 = tail call i32 @curs_set(i32 %12)
br label %14
14: ; preds = %6, %11
%15 = phi i32 [ %0, %11 ], [ 0, %6 ]
store i32 %15, i32* @set_cursor_state.on_last
br label %16
16: ; preds = %14, %8
ret void
}