#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*/ check(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ dbg_cpu0_read_ctrl(int /*<<< orphan*/, unsigned char *);
int /*<<< orphan*/ dbg_cpu0_write_ctrl(int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int stall_cpus(void) {
  unsigned char stalled;
  printf("Stall or1k - ");
  check("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/csturton/wirepatch/refs/heads/master/ddr2/"
        "cores/adv_debug_sys/Software/adv_jtag_bridge/or32_selftest.c",
        124, (dbg_cpu0_write_ctrl(0, 0x01)));
  check("/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/csturton/wirepatch/refs/heads/master/ddr2/"
        "cores/adv_debug_sys/Software/adv_jtag_bridge/or32_selftest.c",
        135, (dbg_cpu0_read_ctrl(0, &stalled)));
  if (!(stalled & 0x1)) {
    printf("or1k is not stalled!\n");
    return 0x0800;
  }
  printf("CPU(s) stalled.\n");
  return 0x0;
}


x86 assembly (clang, -O0):
<stall_cpus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1050 <dbg_cpu0_write_ctrl@plt>
mov    %eax,%edx
lea    0xea5(%rip),%rdi
mov    $0x7c,%esi
call   1060 <check@plt>
xor    %edi,%edi
lea    -0x5(%rbp),%rsi
call   1030 <dbg_cpu0_read_ctrl@plt>
mov    %eax,%edx
lea    0xe87(%rip),%rdi
mov    $0x87,%esi
call   1060 <check@plt>
movzbl -0x5(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    11b9 <stall_cpus+0x79>
lea    0xf27(%rip),%rdi
call   1040 <printf@plt>
movl   $0x800,-0x4(%rbp)
jmp    11cc <stall_cpus+0x8c>
lea    0xf25(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stall_cpus>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
mov    $0x1,%esi
call   1060 <dbg_cpu0_write_ctrl@plt>
lea    0xe9a(%rip),%rbx
mov    %rbx,%rdi
mov    $0x7c,%esi
mov    %eax,%edx
call   1070 <check@plt>
lea    0xf(%rsp),%rsi
xor    %edi,%edi
call   1030 <dbg_cpu0_read_ctrl@plt>
mov    %rbx,%rdi
mov    $0x87,%esi
mov    %eax,%edx
call   1070 <check@plt>
movzbl 0xf(%rsp),%ebx
and    $0x1,%ebx
lea    0xf22(%rip),%rax
lea    0xf30(%rip),%rdi
cmove  %rax,%rdi
xor    $0x1,%ebx
shl    $0xb,%ebx
call   1040 <puts@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Stall or1k - \00"
@.str.1 = [193 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/csturton/wirepatch/refs/heads/master/ddr2/cores/adv_debug_sys/Software/adv_jtag_bridge/or32_selftest.c\00"
@.str.2 = [22 x i8] c"or1k is not stalled!\0A\00"
@.str.3 = [17 x i8] c"CPU(s) stalled.\0A\00"
define i32 @stall_cpus() {
%1 = alloca i32
%2 = alloca i8
%3 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @dbg_cpu0_write_ctrl(i32 0, i32 1)
%5 = call i32 @check(i8* getelementptr inbounds ([193 x i8], [193 x i8]* @.str.1, i64 0, i64 0), i32 124, i32 %4)
%6 = call i32 @dbg_cpu0_read_ctrl(i32 0, i8* %2)
%7 = call i32 @check(i8* getelementptr inbounds ([193 x i8], [193 x i8]* @.str.1, i64 0, i64 0), i32 135, i32 %6)
%8 = load i8, i8* %2
%9 = zext i8 %8 to i32
%10 = and i32 %9, 1
%11 = icmp ne i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 2048, i32* %1
br label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %16
16: ; preds = %14, %12
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [14 x i8] c"Stall or1k - \00"
@.str.1 = [193 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/csturton/wirepatch/refs/heads/master/ddr2/cores/adv_debug_sys/Software/adv_jtag_bridge/or32_selftest.c\00"
@str = [21 x i8] c"or1k is not stalled!\00"
@str.4 = [16 x i8] c"CPU(s) stalled.\00"
define i32 @stall_cpus() {
%1 = alloca i8
%2 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @dbg_cpu0_write_ctrl(i32 0, i32 1)
%4 = tail call i32 @check(i8* getelementptr inbounds ([193 x i8], [193 x i8]* @.str.1, i64 0, i64 0), i32 124, i32 %3)
%5 = call i32 @dbg_cpu0_read_ctrl(i32 0, i8* %1)
%6 = call i32 @check(i8* getelementptr inbounds ([193 x i8], [193 x i8]* @.str.1, i64 0, i64 0), i32 135, i32 %5)
%7 = load i8, i8* %1
%8 = and i8 %7, 1
%9 = icmp eq i8 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @str.4, i64 0, i64 0)
%11 = zext i8 %8 to i32
%12 = shl nuw nsw i32 %11, 11
%13 = xor i32 %12, 2048
%14 = call i32 @puts(i8* dereferenceable(1) %10)
ret i32 %13
}