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

/* Variables and functions */
int int_append(int, int);
int SRTHP(uint64_t max) {
  uint64_t bases[4] = {2, 3, 5, 7};
  uint64_t allowed_append[4] = {1, 2, 3, 7};
  uint64_t res = 0;
  uint64_t inner = 0;
  for (uint32_t i = 0; i < 4; i++) {
    res = bases[i];
    while (res < max) {
      inner = res;
      for (uint32_t i = 0; i < 4; i++) {
        inner = int_append(inner, allowed_append[i]);
      }
    }
  }
}


x86 assembly (clang, -O0):
<SRTHP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    0xede(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xedb(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xed8(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xed5(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x3c(%rbp)
jge    11cd <SRTHP+0xbd>
movslq -0x3c(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ba <SRTHP+0xaa>
mov    -0x34(%rbp),%eax
mov    %eax,-0x38(%rbp)
movl   $0x0,-0x40(%rbp)
cmpl   $0x4,-0x40(%rbp)
jge    11b5 <SRTHP+0xa5>
mov    -0x38(%rbp),%edi
movslq -0x40(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
call   1030 <int_append@plt>
mov    %eax,-0x38(%rbp)
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    118a <SRTHP+0x7a>
jmp    1171 <SRTHP+0x61>
jmp    11bf <SRTHP+0xaf>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    115c <SRTHP+0x4c>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SRTHP>:
push   %rax
cmp    $0x3,%edi
jl     1155 <SRTHP+0x45>
cs nopw 0x0(%rax,%rax,1)
mov    $0x2,%edi
mov    $0x1,%esi
call   1030 <int_append@plt>
mov    %eax,%edi
mov    $0x2,%esi
call   1030 <int_append@plt>
mov    %eax,%edi
mov    $0x3,%esi
call   1030 <int_append@plt>
mov    %eax,%edi
mov    $0x7,%esi
call   1030 <int_append@plt>
jmp    1120 <SRTHP+0x10>
pop    %rcx
ret

LLVM IR (-O0):
@__const.SRTHP.bases = [4 x i32] [i32 2, i32 3, i32 5, i32 7]
@__const.SRTHP.allowed_append = [4 x i32] [i32 1, i32 2, i32 3, i32 7]
define i32 @SRTHP(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4 x i32]
%5 = alloca [4 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 %0, i32* %3
%10 = bitcast [4 x i32]* %4 to i8*
%11 = bitcast [4 x i32]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
br label %12
12: ; preds = %41, %1
%13 = load i32, i32* %8
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %44
15: ; preds = %12
%16 = load i32, i32* %8
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4 x i32], [4 x i32]* %4, i64 0, i64 %17
%19 = load i32, i32* %18
store i32 %19, i32* %6
br label %20
20: ; preds = %39, %15
%21 = load i32, i32* %6
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %40
24: ; preds = %20
%25 = load i32, i32* %6
store i32 %25, i32* %7
store i32 0, i32* %9
br label %26
26: ; preds = %36, %24
%27 = load i32, i32* %9
%28 = icmp slt i32 %27, 4
br i1 %28, label %29, label %39
29: ; preds = %26
%30 = load i32, i32* %7
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [4 x i32], [4 x i32]* %5, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = call i32 @int_append(i32 %30, i32 %34)
store i32 %35, i32* %7
br label %36
36: ; preds = %29
%37 = load i32, i32* %9
%38 = add nsw i32 %37, 1
store i32 %38, i32* %9
br label %26
39: ; preds = %26
br label %20
40: ; preds = %20
br label %41
41: ; preds = %40
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %12
44: ; preds = %12
%45 = load i32, i32* %2
ret i32 %45
}

LLVM IR (-O2):
define i32 @SRTHP(i32 %0) {
%2 = icmp sgt i32 %0, 2
br i1 %2, label %3, label %8
3: ; preds = %1, %3
%4 = tail call i32 @int_append(i32 2, i32 1)
%5 = tail call i32 @int_append(i32 %4, i32 2)
%6 = tail call i32 @int_append(i32 %5, i32 3)
%7 = tail call i32 @int_append(i32 %6, i32 7)
br label %3
8: ; preds = %1
ret i32 undef
}