#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 /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
const char *reg(int R) {
  static char buffer[4][10];
  static int timer = 0;
  char *bp = buffer[timer];
  if (++timer == 4)
    timer = 0;
  switch (R) {
  case 1:
    strcpy(bp, "$PC");
    break;
  case 2:
    strcpy(bp, "$DPC");
    break;
  default:
    sprintf(bp, "$%d", R);
    break;
  }
  return bp;
}


x86 assembly (clang, -O0):
<reg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq 0x2f36(%rip),%rcx
lea    0x2f07(%rip),%rax
imul   $0xa,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    0x2f1e(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2f15(%rip)
cmp    $0x4,%eax
jne    1166 <reg+0x46>
movl   $0x0,0x2f02(%rip)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x1,%eax
je     118b <reg+0x6b>
jmp    117a <reg+0x5a>
mov    -0x14(%rbp),%eax
sub    $0x2,%eax
je     11a0 <reg+0x80>
jmp    11b5 <reg+0x95>
mov    -0x10(%rbp),%rdi
lea    0xe6a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c8 <reg+0xa8>
mov    -0x10(%rbp),%rdi
lea    0xe59(%rip),%rsi
call   1030 <strcpy@plt>
jmp    11c8 <reg+0xa8>
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe46(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<reg>:
push   %rbx
movslq 0x2f40(%rip),%rax
lea    (%rax,%rax,4),%rcx
lea    0x2f0d(%rip),%rsi
lea    (%rsi,%rcx,2),%rbx
add    $0x1,%eax
xor    %ecx,%ecx
cmp    $0x4,%eax
cmovne %eax,%ecx
mov    %ecx,0x2f20(%rip)
cmp    $0x2,%edi
je     115d <reg+0x3d>
mov    %edi,%edx
cmp    $0x1,%edi
jne    116e <reg+0x4e>
lea    0xea5(%rip),%rsi
jmp    1164 <reg+0x44>
lea    0xea0(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
jmp    117d <reg+0x5d>
lea    0xe94(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@reg.buffer = internal global [4 x [10 x i8]] zeroinitializer
@reg.timer = internal global i32 0
@.str = [4 x i8] c"$PC\00"
@.str.1 = [5 x i8] c"$DPC\00"
@.str.2 = [4 x i8] c"$%d\00"
define i8* @reg(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
%4 = load i32, i32* @reg.timer
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [4 x [10 x i8]], [4 x [10 x i8]]* @reg.buffer, i64 0, i64 %5
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
store i8* %7, i8** %3
%8 = load i32, i32* @reg.timer
%9 = add nsw i32 %8, 1
store i32 %9, i32* @reg.timer
%10 = icmp eq i32 %9, 4
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* @reg.timer
br label %12
12: ; preds = %11, %1
%13 = load i32, i32* %2
switch i32 %13, label %20 [
i32 1, label %14
i32 2, label %17
]
14: ; preds = %12
%15 = load i8*, i8** %3
%16 = call i32 @strcpy(i8* %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %24
17: ; preds = %12
%18 = load i8*, i8** %3
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %12
%21 = load i8*, i8** %3
%22 = load i32, i32* %2
%23 = call i32 @sprintf(i8* %21, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %22)
br label %24
24: ; preds = %20, %17, %14
%25 = load i8*, i8** %3
ret i8* %25
}

LLVM IR (-O2):
@reg.buffer = internal global [4 x [10 x i8]] zeroinitializer
@reg.timer = internal unnamed_addr global i32 0
@.str = [4 x i8] c"$PC\00"
@.str.1 = [5 x i8] c"$DPC\00"
@.str.2 = [4 x i8] c"$%d\00"
define i8* @reg(i32 %0) {
%2 = load i32, i32* @reg.timer
%3 = sext i32 %2 to i64
%4 = getelementptr inbounds [4 x [10 x i8]], [4 x [10 x i8]]* @reg.buffer, i64 0, i64 %3, i64 0
%5 = add nsw i32 %2, 1
%6 = icmp eq i32 %5, 4
%7 = select i1 %6, i32 0, i32 %5
store i32 %7, i32* @reg.timer
switch i32 %0, label %12 [
i32 1, label %8
i32 2, label %10
]
8: ; preds = %1
%9 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %14
10: ; preds = %1
%11 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %14
12: ; preds = %1
%13 = tail call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %14
14: ; preds = %12, %10, %8
ret i8* %4
}