#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;

/* Variables and functions */
int arc4random();
int potr_1(int, int, int, int);
uint64_t recover_hi(uint64_t secret_key) {
  uint64_t kk = 0;
  for (int i = 62; i >= 32; i--) {
    uint64_t m1, m2, c11, c12, n;
    m1 = (((uint64_t)arc4random()) << 32) ^ arc4random();
    m2 = (((uint64_t)arc4random()) << 32) ^ arc4random();
    n = (((uint64_t)arc4random()) << 32) ^ 0x80000000ULL;
    c11 = potr_1(secret_key, n, m1, m2);
    c12 = potr_1(
        secret_key + (1ULL << (i)), n ^ (1ULL << (i)),
        m1 ^ (1ULL << (i)) ^
            ((((((1ULL << (i))) & 0x8000000000000000ULL)
                   ? ((((1ULL << (i)))) << 1ULL) ^ 0x000000000000001BULL
                   : (((1ULL << (i))) << 1ULL)) &
              0x8000000000000000ULL)
                 ? ((((((1ULL << (i))) & 0x8000000000000000ULL)
                          ? ((((1ULL << (i)))) << 1ULL) ^ 0x000000000000001BULL
                          : (((1ULL << (i))) << 1ULL)))
                    << 1ULL) ^
                       0x000000000000001BULL
                 : (((((1ULL << (i))) & 0x8000000000000000ULL)
                         ? ((((1ULL << (i)))) << 1ULL) ^ 0x000000000000001BULL
                         : (((1ULL << (i))) << 1ULL))
                    << 1ULL)),
        m2);
    if (c11 != (c12 ^ (1ULL << (i))))
      kk |= (1ULL << (i));
  }
  return kk;
}


x86 assembly (clang, -O0):
<recover_hi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x3e,-0xc(%rbp)
cmpl   $0x20,-0xc(%rbp)
jl     13b7 <recover_hi+0x297>
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1040 <arc4random@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
xor    %ecx,%eax
mov    %eax,-0x10(%rbp)
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
cltq
movabs $0x80000000,%rcx
xor    %rcx,%rax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   1030 <potr_1@plt>
mov    %eax,-0x18(%rbp)
movslq -0x4(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    %rdx,%rcx
add    %rcx,%rax
mov    %eax,-0x30(%rbp)
movslq -0x20(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    %rdx,%rcx
xor    %rcx,%rax
mov    %eax,-0x2c(%rbp)
movslq -0x10(%rbp),%rax
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    %rdx,%rcx
xor    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
movabs $0x8000000000000000,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     1246 <recover_hi+0x126>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
shl    $0x1,%rax
xor    $0x1b,%rax
mov    %rax,-0x40(%rbp)
jmp    125b <recover_hi+0x13b>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
shl    $0x1,%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
movabs $0x8000000000000000,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     12e2 <recover_hi+0x1c2>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
movabs $0x8000000000000000,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     12b8 <recover_hi+0x198>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
shl    $0x1,%rax
xor    $0x1b,%rax
mov    %rax,-0x48(%rbp)
jmp    12cd <recover_hi+0x1ad>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
shl    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
shl    $0x1,%rax
xor    $0x1b,%rax
mov    %rax,-0x50(%rbp)
jmp    1345 <recover_hi+0x225>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
movabs $0x8000000000000000,%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     1324 <recover_hi+0x204>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
shl    $0x1,%rax
xor    $0x1b,%rax
mov    %rax,-0x58(%rbp)
jmp    1339 <recover_hi+0x219>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
shl    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    -0x50(%rbp),%rcx
xor    %rcx,%rax
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
call   1030 <potr_1@plt>
mov    %eax,-0x1c(%rbp)
movslq -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rcx,-0x60(%rbp)
mov    -0xc(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%rdx
mov    -0x60(%rbp),%rcx
xor    %rdx,%rcx
cmp    %rcx,%rax
je     13a4 <recover_hi+0x284>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
mov    $0x1,%eax
shl    %cl,%rax
mov    %rax,%rcx
movslq -0x8(%rbp),%rax
or     %rcx,%rax
mov    %eax,-0x8(%rbp)
jmp    13a9 <recover_hi+0x289>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1139 <recover_hi+0x19>
mov    -0x8(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recover_hi>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %r12d,%r12d
mov    $0x3f,%ebx
xor    %r13d,%r13d
nopl   0x0(%rax)
add    $0xffffffffffffffff,%rbx
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    %r14d,%edi
call   1030 <potr_1@plt>
mov    %eax,%r15d
mov    $0x1,%ebp
mov    %ebx,%ecx
shl    %cl,%rbp
lea    (%r14,%rbp,1),%edi
call   1030 <potr_1@plt>
movslq %r15d,%rcx
cltq
btc    %rbx,%rax
cmp    %rcx,%rax
cmove  %r12d,%ebp
or     %ebp,%r13d
cmp    $0x20,%rbx
ja     1140 <recover_hi+0x20>
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_hi(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
store i32 62, i32* %4
br label %10
10: ; preds = %137, %1
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 32
br i1 %12, label %13, label %140
13: ; preds = %10
%14 = call i32 (...) @arc4random()
%15 = shl i32 %14, 32
%16 = call i32 (...) @arc4random()
%17 = xor i32 %15, %16
store i32 %17, i32* %5
%18 = call i32 (...) @arc4random()
%19 = shl i32 %18, 32
%20 = call i32 (...) @arc4random()
%21 = xor i32 %19, %20
store i32 %21, i32* %6
%22 = call i32 (...) @arc4random()
%23 = shl i32 %22, 32
%24 = sext i32 %23 to i64
%25 = xor i64 %24, 2147483648
%26 = trunc i64 %25 to i32
store i32 %26, i32* %9
%27 = load i32, i32* %2
%28 = load i32, i32* %9
%29 = load i32, i32* %5
%30 = load i32, i32* %6
%31 = call i32 @potr_1(i32 %27, i32 %28, i32 %29, i32 %30)
store i32 %31, i32* %7
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = load i32, i32* %4
%35 = zext i32 %34 to i64
%36 = shl i64 1, %35
%37 = add i64 %33, %36
%38 = trunc i64 %37 to i32
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = load i32, i32* %4
%42 = zext i32 %41 to i64
%43 = shl i64 1, %42
%44 = xor i64 %40, %43
%45 = trunc i64 %44 to i32
%46 = load i32, i32* %5
%47 = sext i32 %46 to i64
%48 = load i32, i32* %4
%49 = zext i32 %48 to i64
%50 = shl i64 1, %49
%51 = xor i64 %47, %50
%52 = load i32, i32* %4
%53 = zext i32 %52 to i64
%54 = shl i64 1, %53
%55 = and i64 %54, -9223372036854775808
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %13
%58 = load i32, i32* %4
%59 = zext i32 %58 to i64
%60 = shl i64 1, %59
%61 = shl i64 %60, 1
%62 = xor i64 %61, 27
br label %68
63: ; preds = %13
%64 = load i32, i32* %4
%65 = zext i32 %64 to i64
%66 = shl i64 1, %65
%67 = shl i64 %66, 1
br label %68
68: ; preds = %63, %57
%69 = phi i64 [ %62, %57 ], [ %67, %63 ]
%70 = and i64 %69, -9223372036854775808
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %93
72: ; preds = %68
%73 = load i32, i32* %4
%74 = zext i32 %73 to i64
%75 = shl i64 1, %74
%76 = and i64 %75, -9223372036854775808
%77 = icmp ne i64 %76, 0
br i1 %77, label %78, label %84
78: ; preds = %72
%79 = load i32, i32* %4
%80 = zext i32 %79 to i64
%81 = shl i64 1, %80
%82 = shl i64 %81, 1
%83 = xor i64 %82, 27
br label %89
84: ; preds = %72
%85 = load i32, i32* %4
%86 = zext i32 %85 to i64
%87 = shl i64 1, %86
%88 = shl i64 %87, 1
br label %89
89: ; preds = %84, %78
%90 = phi i64 [ %83, %78 ], [ %88, %84 ]
%91 = shl i64 %90, 1
%92 = xor i64 %91, 27
br label %113
93: ; preds = %68
%94 = load i32, i32* %4
%95 = zext i32 %94 to i64
%96 = shl i64 1, %95
%97 = and i64 %96, -9223372036854775808
%98 = icmp ne i64 %97, 0
br i1 %98, label %99, label %105
99: ; preds = %93
%100 = load i32, i32* %4
%101 = zext i32 %100 to i64
%102 = shl i64 1, %101
%103 = shl i64 %102, 1
%104 = xor i64 %103, 27
br label %110
105: ; preds = %93
%106 = load i32, i32* %4
%107 = zext i32 %106 to i64
%108 = shl i64 1, %107
%109 = shl i64 %108, 1
br label %110
110: ; preds = %105, %99
%111 = phi i64 [ %104, %99 ], [ %109, %105 ]
%112 = shl i64 %111, 1
br label %113
113: ; preds = %110, %89
%114 = phi i64 [ %92, %89 ], [ %112, %110 ]
%115 = xor i64 %51, %114
%116 = trunc i64 %115 to i32
%117 = load i32, i32* %6
%118 = call i32 @potr_1(i32 %38, i32 %45, i32 %116, i32 %117)
store i32 %118, i32* %8
%119 = load i32, i32* %7
%120 = sext i32 %119 to i64
%121 = load i32, i32* %8
%122 = sext i32 %121 to i64
%123 = load i32, i32* %4
%124 = zext i32 %123 to i64
%125 = shl i64 1, %124
%126 = xor i64 %122, %125
%127 = icmp ne i64 %120, %126
br i1 %127, label %128, label %136
128: ; preds = %113
%129 = load i32, i32* %4
%130 = zext i32 %129 to i64
%131 = shl i64 1, %130
%132 = load i32, i32* %3
%133 = sext i32 %132 to i64
%134 = or i64 %133, %131
%135 = trunc i64 %134 to i32
store i32 %135, i32* %3
br label %136
136: ; preds = %128, %113
br label %137
137: ; preds = %136
%138 = load i32, i32* %4
%139 = add nsw i32 %138, -1
store i32 %139, i32* %4
br label %10
140: ; preds = %10
%141 = load i32, i32* %3
ret i32 %141
}

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