#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 */
scalar_t__ get_htp();
int /*<<< orphan*/ is_hdr_valid_iso(int /*<<< orphan*/);
int /*<<< orphan*/ raw2iso(int);
void hdr_iso_toggle(void *priv, int delta) {
  int *v = (int *)priv;
  do {
    *v = ({
           int _x = (*v - (get_htp() ? 80 : 72) + delta);
           int _m = (128 - (get_htp() ? 80 : 72) + 1);
           (_x % _m + _m) % _m;
         }) +
         (get_htp() ? 80 : 72);
  } while (!is_hdr_valid_iso(raw2iso(*v)));
}


x86 assembly (clang, -O0):
<hdr_iso_toggle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <get_htp@plt>
mov    %rax,%rsi
mov    -0x2c(%rbp),%eax
mov    $0x48,%ecx
mov    $0x50,%edx
cmp    $0x0,%rsi
cmovne %edx,%ecx
sub    %ecx,%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <get_htp@plt>
mov    %rax,%rdx
mov    $0x48,%ecx
mov    $0x50,%eax
cmp    $0x0,%rdx
cmovne %eax,%ecx
mov    $0x80,%eax
sub    %ecx,%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %edx,%eax
add    -0x20(%rbp),%eax
cltd
idivl  -0x20(%rbp)
mov    %edx,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <get_htp@plt>
mov    -0x28(%rbp),%ecx
mov    %rax,%rsi
mov    $0x48,%eax
mov    $0x50,%edx
cmp    $0x0,%rsi
cmovne %edx,%eax
add    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <raw2iso@plt>
mov    %eax,%edi
call   1040 <is_hdr_valid_iso@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1147 <hdr_iso_toggle+0x17>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hdr_iso_toggle>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
nopw   0x0(%rax,%rax,1)
mov    (%rbx),%ebp
add    %r14d,%ebp
xor    %eax,%eax
call   1030 <get_htp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    -0x50(%rbp,%rcx,8),%ebp
xor    %eax,%eax
call   1030 <get_htp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    0x31(,%rcx,8),%esi
mov    %ebp,%eax
cltd
idiv   %esi
lea    (%rdx,%rcx,8),%eax
add    $0x31,%eax
cbtw
idiv   %sil
movsbl %ah,%ebp
xor    %eax,%eax
call   1030 <get_htp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    0x48(%rbp,%rcx,8),%edi
mov    %edi,(%rbx)
call   1050 <raw2iso@plt>
mov    %eax,%edi
call   1040 <is_hdr_valid_iso@plt>
test   %eax,%eax
je     1140 <hdr_iso_toggle+0x10>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @hdr_iso_toggle(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to i32*
store i32* %10, i32** %5
br label %11
11: ; preds = %41, %2
%12 = load i32*, i32** %5
%13 = load i32, i32* %12
%14 = call i64 (...) @get_htp()
%15 = icmp ne i64 %14, 0
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 80, i32 72
%18 = sub nsw i32 %13, %17
%19 = load i32, i32* %4
%20 = add nsw i32 %18, %19
store i32 %20, i32* %6
%21 = call i64 (...) @get_htp()
%22 = icmp ne i64 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 80, i32 72
%25 = sub nsw i32 128, %24
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i32, i32* %6
%28 = load i32, i32* %7
%29 = srem i32 %27, %28
%30 = load i32, i32* %7
%31 = add nsw i32 %29, %30
%32 = load i32, i32* %7
%33 = srem i32 %31, %32
store i32 %33, i32* %8
%34 = load i32, i32* %8
%35 = call i64 (...) @get_htp()
%36 = icmp ne i64 %35, 0
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 80, i32 72
%39 = add nsw i32 %34, %38
%40 = load i32*, i32** %5
store i32 %39, i32* %40
br label %41
41: ; preds = %11
%42 = load i32*, i32** %5
%43 = load i32, i32* %42
%44 = call i32 @raw2iso(i32 %43)
%45 = call i32 @is_hdr_valid_iso(i32 %44)
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %11, label %48
48: ; preds = %41
ret void
}

LLVM IR (-O2):
define void @hdr_iso_toggle(i8* nocapture %0, i32 %1) {
%3 = bitcast i8* %0 to i32*
br label %4
4: ; preds = %4, %2
%5 = load i32, i32* %3
%6 = tail call i64 (...) @get_htp()
%7 = icmp eq i64 %6, 0
%8 = select i1 %7, i32 -72, i32 -80
%9 = add i32 %5, %1
%10 = add i32 %9, %8
%11 = tail call i64 (...) @get_htp()
%12 = icmp eq i64 %11, 0
%13 = select i1 %12, i32 57, i32 49
%14 = srem i32 %10, %13
%15 = add nsw i32 %13, %14
%16 = trunc i32 %15 to i8
%17 = trunc i32 %13 to i8
%18 = srem i8 %16, %17
%19 = sext i8 %18 to i32
%20 = tail call i64 (...) @get_htp()
%21 = icmp eq i64 %20, 0
%22 = select i1 %21, i32 72, i32 80
%23 = add nsw i32 %22, %19
store i32 %23, i32* %3
%24 = tail call i32 @raw2iso(i32 %23)
%25 = tail call i32 @is_hdr_valid_iso(i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %4, label %27
27: ; preds = %4
ret void
}