#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 */
typedef int uint64_t;
typedef int kk;

/* Variables and functions */
int arc4random();
int potr_1(int, int, int, int);
uint64_t recover_lo(uint64_t secret_key, uint64_t hi_key) {
  uint64_t kk = hi_key;
  for (int i = 31; i >= 0; i--) {
    uint64_t m1, m2, c11, c12, n;
    uint64_t delta_p, delta_m;
    m1 = (((uint64_t)arc4random()) << 32) ^ arc4random();
    m2 = (((uint64_t)arc4random()) << 32) ^ arc4random();
    n = (((uint64_t)arc4random()) << 32) ^ 0x80000000ULL;
    delta_p = (1ULL << (i)) - ((kk)&0xFFFFFFFF00000000ULL) +
              (((((~kk) & 0x00000000FFFFFFFFULL)) >> (i + 1)) << (i + 1));
    delta_m = (1ULL << (i)) + ((kk)&0xFFFFFFFF00000000ULL) +
              ((kk)&0x00000000FFFFFFFFULL);
    c11 = potr_1(secret_key + delta_p, n ^ (1ULL << (32)), m1 ^ (1ULL << (32)),
                 m2);
    c12 = potr_1(
        secret_key - delta_m, n,
        m1 ^
            ((((((1ULL << (32))) & 0x8000000000000000ULL)
                   ? ((((1ULL << (32)))) << 1ULL) ^ 0x000000000000001BULL
                   : (((1ULL << (32))) << 1ULL)) &
              0x8000000000000000ULL)
                 ? ((((((1ULL << (32))) & 0x8000000000000000ULL)
                          ? ((((1ULL << (32)))) << 1ULL) ^ 0x000000000000001BULL
                          : (((1ULL << (32))) << 1ULL)))
                    << 1ULL) ^
                       0x000000000000001BULL
                 : (((((1ULL << (32))) & 0x8000000000000000ULL)
                         ? ((((1ULL << (32)))) << 1ULL) ^ 0x000000000000001BULL
                         : (((1ULL << (32))) << 1ULL))
                    << 1ULL)),
        m2);
    if (c11 == (c12 ^ (1ULL << (32))))
      kk |= (1ULL << (i));
  }
  return kk;
}


x86 assembly (clang, -O0):
<recover_lo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1f,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     12e0 <recover_lo+0x1c0>
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
xor    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
xor    %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    $0x20,%ecx
shl    %cl,%eax
cltq
movabs $0x80000000,%rcx
xor    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
movslq -0xc(%rbp),%rcx
movabs $0xffffffff00000000,%rdx
ff ff ff
and    %rdx,%rcx
sub    %rcx,%rax
mov    -0xc(%rbp),%ecx
xor    $0xffffffff,%ecx
movslq %ecx,%rdx
movabs $0xffffffff,%rcx
and    %rcx,%rdx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
shr    %cl,%rdx
mov    -0x10(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,%ecx
shl    %cl,%rdx
mov    %rdx,%rcx
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
movslq -0xc(%rbp),%rcx
movabs $0xffffffff00000000,%rdx
ff ff ff
and    %rdx,%rcx
add    %rcx,%rax
movslq -0xc(%rbp),%rcx
movabs $0xffffffff,%rdx
and    %rdx,%rcx
add    %rcx,%rax
mov    %eax,-0x2c(%rbp)
mov    -0x4(%rbp),%edi
add    -0x28(%rbp),%edi
movslq -0x24(%rbp),%rax
movabs $0x100000000,%rcx
xor    %rcx,%rax
mov    %eax,%esi
movslq -0x14(%rbp),%rax
movabs $0x100000000,%rcx
xor    %rcx,%rax
mov    %eax,%edx
mov    -0x18(%rbp),%ecx
call   1030 <potr_1@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
sub    -0x2c(%rbp),%edi
mov    -0x24(%rbp),%esi
movslq -0x14(%rbp),%rax
movabs $0x400000000,%rcx
xor    %rcx,%rax
mov    %eax,%edx
mov    -0x18(%rbp),%ecx
call   1030 <potr_1@plt>
mov    %eax,-0x20(%rbp)
movslq -0x1c(%rbp),%rax
movslq -0x20(%rbp),%rcx
movabs $0x100000000,%rdx
xor    %rdx,%rcx
cmp    %rcx,%rax
jne    12cd <recover_lo+0x1ad>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
mov    %rax,%rcx
movslq -0xc(%rbp),%rax
or     %rcx,%rax
mov    %eax,-0xc(%rbp)
jmp    12d2 <recover_lo+0x1b2>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    113b <recover_lo+0x1b>
mov    -0xc(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recover_lo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %edi,%r14d
mov    $0x1f,%ebp
movabs $0x100000000,%r12
jmp    1159 <recover_lo+0x39>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
or     %ebx,%r13d
sub    $0x1,%rbp
jb     11c5 <recover_lo+0xa5>
xor    %eax,%eax
call   1040 <arc4random@plt>
xor    %eax,%eax
call   1040 <arc4random@plt>
xor    %eax,%eax
call   1040 <arc4random@plt>
xor    %eax,%eax
call   1040 <arc4random@plt>
xor    %eax,%eax
call   1040 <arc4random@plt>
mov    $0x1,%ebx
mov    %ebp,%ecx
shl    %cl,%rbx
mov    %r13d,%eax
lea    0x1(%rbp),%ecx
mov    $0xffffffffffffffff,%rdi
shl    %cl,%rdi
not    %eax
and    %eax,%edi
add    %ebx,%edi
add    %r14d,%edi
call   1030 <potr_1@plt>
mov    %eax,%r15d
mov    %r14d,%edi
sub    %r13d,%edi
sub    %ebx,%edi
call   1030 <potr_1@plt>
movslq %r15d,%rcx
cltq
xor    %r12,%rax
cmp    %rcx,%rax
je     1150 <recover_lo+0x30>
xor    %ebx,%ebx
jmp    1150 <recover_lo+0x30>
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @recover_lo(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%14 = load i32, i32* %4
store i32 %14, i32* %5
store i32 31, i32* %6
br label %15
15: ; preds = %103, %2
%16 = load i32, i32* %6
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %106
18: ; preds = %15
%19 = call i32 (...) @arc4random()
%20 = shl i32 %19, 32
%21 = call i32 (...) @arc4random()
%22 = xor i32 %20, %21
store i32 %22, i32* %7
%23 = call i32 (...) @arc4random()
%24 = shl i32 %23, 32
%25 = call i32 (...) @arc4random()
%26 = xor i32 %24, %25
store i32 %26, i32* %8
%27 = call i32 (...) @arc4random()
%28 = shl i32 %27, 32
%29 = sext i32 %28 to i64
%30 = xor i64 %29, 2147483648
%31 = trunc i64 %30 to i32
store i32 %31, i32* %11
%32 = load i32, i32* %6
%33 = zext i32 %32 to i64
%34 = shl i64 1, %33
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = and i64 %36, -4294967296
%38 = sub i64 %34, %37
%39 = load i32, i32* %5
%40 = xor i32 %39, -1
%41 = sext i32 %40 to i64
%42 = and i64 %41, 4294967295
%43 = load i32, i32* %6
%44 = add nsw i32 %43, 1
%45 = zext i32 %44 to i64
%46 = lshr i64 %42, %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
%49 = zext i32 %48 to i64
%50 = shl i64 %46, %49
%51 = add i64 %38, %50
%52 = trunc i64 %51 to i32
store i32 %52, i32* %12
%53 = load i32, i32* %6
%54 = zext i32 %53 to i64
%55 = shl i64 1, %54
%56 = load i32, i32* %5
%57 = sext i32 %56 to i64
%58 = and i64 %57, -4294967296
%59 = add i64 %55, %58
%60 = load i32, i32* %5
%61 = sext i32 %60 to i64
%62 = and i64 %61, 4294967295
%63 = add i64 %59, %62
%64 = trunc i64 %63 to i32
store i32 %64, i32* %13
%65 = load i32, i32* %3
%66 = load i32, i32* %12
%67 = add nsw i32 %65, %66
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = xor i64 %69, 4294967296
%71 = trunc i64 %70 to i32
%72 = load i32, i32* %7
%73 = sext i32 %72 to i64
%74 = xor i64 %73, 4294967296
%75 = trunc i64 %74 to i32
%76 = load i32, i32* %8
%77 = call i32 @potr_1(i32 %67, i32 %71, i32 %75, i32 %76)
store i32 %77, i32* %9
%78 = load i32, i32* %3
%79 = load i32, i32* %13
%80 = sub nsw i32 %78, %79
%81 = load i32, i32* %11
%82 = load i32, i32* %7
%83 = sext i32 %82 to i64
%84 = xor i64 %83, 17179869184
%85 = trunc i64 %84 to i32
%86 = load i32, i32* %8
%87 = call i32 @potr_1(i32 %80, i32 %81, i32 %85, i32 %86)
store i32 %87, i32* %10
%88 = load i32, i32* %9
%89 = sext i32 %88 to i64
%90 = load i32, i32* %10
%91 = sext i32 %90 to i64
%92 = xor i64 %91, 4294967296
%93 = icmp eq i64 %89, %92
br i1 %93, label %94, label %102
94: ; preds = %18
%95 = load i32, i32* %6
%96 = zext i32 %95 to i64
%97 = shl i64 1, %96
%98 = load i32, i32* %5
%99 = sext i32 %98 to i64
%100 = or i64 %99, %97
%101 = trunc i64 %100 to i32
store i32 %101, i32* %5
br label %102
102: ; preds = %94, %18
br label %103
103: ; preds = %102
%104 = load i32, i32* %6
%105 = add nsw i32 %104, -1
store i32 %105, i32* %6
br label %15
106: ; preds = %15
%107 = load i32, i32* %5
ret i32 %107
}

LLVM IR (-O2):
define i32 @recover_lo(i32 %0, i32 %1) {
br label %4
3: ; preds = %4
ret i32 %31
4: ; preds = %2, %4
%5 = phi i64 [ 31, %2 ], [ %32, %4 ]
%6 = phi i32 [ %1, %2 ], [ %31, %4 ]
%7 = tail call i32 (...) @arc4random()
%8 = tail call i32 (...) @arc4random()
%9 = tail call i32 (...) @arc4random()
%10 = tail call i32 (...) @arc4random()
%11 = tail call i32 (...) @arc4random()
%12 = shl nuw i64 1, %5
%13 = xor i32 %6, -1
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %5, 1
%16 = shl nsw i64 -1, %15
%17 = and i64 %16, %14
%18 = add nuw i64 %17, %12
%19 = trunc i64 %18 to i32
%20 = trunc i64 %12 to i32
%21 = add nsw i32 %19, %0
%22 = tail call i32 @potr_1(i32 %21, i32 poison, i32 poison, i32 poison)
%23 = add i32 %6, %20
%24 = sub i32 %0, %23
%25 = tail call i32 @potr_1(i32 %24, i32 poison, i32 poison, i32 poison)
%26 = sext i32 %22 to i64
%27 = sext i32 %25 to i64
%28 = xor i64 %27, 4294967296
%29 = icmp eq i64 %28, %26
%30 = select i1 %29, i32 %20, i32 0
%31 = or i32 %30, %6
%32 = add nsw i64 %5, -1
%33 = icmp eq i64 %5, 0
br i1 %33, label %3, label %4
}