#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 Dpi_check_dpid_ids();
scalar_t__ Dpi_start_dpid();
int Dpi_check_dpid(int num_tries) {
  static int starting = 0;
  int check_st = 1, ret = 2;
  check_st = Dpi_check_dpid_ids();
  ;
  if (check_st == 1) {
    starting = 0;
    ret = 0;
  } else {
    if (!starting) {
      if (Dpi_start_dpid() == 0) {
        starting = 1;
        ret = 1;
      }
    } else if (++starting < num_tries) {
      ret = 1;
    } else {
      starting = 0;
    }
  }

  ;
  return ret;
}


x86 assembly (clang, -O0):
<Dpi_check_dpid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x2,-0xc(%rbp)
mov    $0x0,%al
call   1030 <Dpi_check_dpid_ids@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    1163 <Dpi_check_dpid+0x43>
movl   $0x0,0x2edd(%rip)
movl   $0x0,-0xc(%rbp)
jmp    11cf <Dpi_check_dpid+0xaf>
cmpl   $0x0,0x2eca(%rip)
jne    1197 <Dpi_check_dpid+0x77>
mov    $0x0,%al
call   1040 <Dpi_start_dpid@plt>
cmp    $0x0,%rax
jne    1192 <Dpi_check_dpid+0x72>
movl   $0x1,0x2ea9(%rip)
movl   $0x1,-0xc(%rbp)
jmp    11ca <Dpi_check_dpid+0xaa>
mov    0x2e97(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e8e(%rip)
cmp    -0x4(%rbp),%eax
jge    11bb <Dpi_check_dpid+0x9b>
movl   $0x1,-0xc(%rbp)
jmp    11c5 <Dpi_check_dpid+0xa5>
movl   $0x0,0x2e6f(%rip)
jmp    11ca <Dpi_check_dpid+0xaa>
jmp    11cf <Dpi_check_dpid+0xaf>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Dpi_check_dpid>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <Dpi_check_dpid_ids@plt>
cmp    $0x1,%eax
jne    113f <Dpi_check_dpid+0x1f>
movl   $0x0,0x2ef7(%rip)
jmp    1187 <Dpi_check_dpid+0x67>
mov    0x2eef(%rip),%eax
test   %eax,%eax
je     1167 <Dpi_check_dpid+0x47>
add    $0x1,%eax
xor    %ecx,%ecx
xor    %edx,%edx
cmp    %ebp,%eax
cmovl  %eax,%ecx
setl   %dl
mov    %ecx,0x2ed6(%rip)
mov    $0x2,%ebx
sub    %edx,%ebx
jmp    1187 <Dpi_check_dpid+0x67>
xor    %eax,%eax
call   1040 <Dpi_start_dpid@plt>
mov    $0x2,%ebx
test   %rax,%rax
jne    1187 <Dpi_check_dpid+0x67>
movl   $0x1,0x2eb2(%rip)
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@Dpi_check_dpid.starting = internal global i32 0
define i32 @Dpi_check_dpid(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %3
store i32 2, i32* %4
%5 = call i32 (...) @Dpi_check_dpid_ids()
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* @Dpi_check_dpid.starting
store i32 0, i32* %4
br label %26
9: ; preds = %1
%10 = load i32, i32* @Dpi_check_dpid.starting
%11 = icmp ne i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = call i64 (...) @Dpi_start_dpid()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %12
store i32 1, i32* @Dpi_check_dpid.starting
store i32 1, i32* %4
br label %16
16: ; preds = %15, %12
br label %25
17: ; preds = %9
%18 = load i32, i32* @Dpi_check_dpid.starting
%19 = add nsw i32 %18, 1
store i32 %19, i32* @Dpi_check_dpid.starting
%20 = load i32, i32* %2
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 1, i32* %4
br label %24
23: ; preds = %17
store i32 0, i32* @Dpi_check_dpid.starting
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %16
br label %26
26: ; preds = %25, %8
%27 = load i32, i32* %4
ret i32 %27
}

LLVM IR (-O2):
@Dpi_check_dpid.starting = internal unnamed_addr global i32 0
define i32 @Dpi_check_dpid(i32 %0) {
%2 = tail call i32 (...) @Dpi_check_dpid_ids()
%3 = icmp eq i32 %2, 1
br i1 %3, label %4, label %5
4: ; preds = %1
store i32 0, i32* @Dpi_check_dpid.starting
br label %17
5: ; preds = %1
%6 = load i32, i32* @Dpi_check_dpid.starting
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5
%9 = tail call i64 (...) @Dpi_start_dpid()
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %8
store i32 1, i32* @Dpi_check_dpid.starting
br label %17
12: ; preds = %5
%13 = add nsw i32 %6, 1
%14 = icmp slt i32 %13, %0
%15 = select i1 %14, i32 %13, i32 0
store i32 %15, i32* @Dpi_check_dpid.starting
%16 = select i1 %14, i32 1, i32 2
br label %17
17: ; preds = %12, %11, %8, %4
%18 = phi i32 [ 0, %4 ], [ 1, %11 ], [ 2, %8 ], [ %16, %12 ]
ret i32 %18
}