#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 */
unsigned long get_dscr();
unsigned long get_dscr_usr();
int /*<<< orphan*/ printf(char *, int, unsigned long, unsigned long);
int sched_getcpu();
int test_thread_dscr(unsigned long val) {
  unsigned long cur_dscr, cur_dscr_usr;
  cur_dscr = get_dscr();
  cur_dscr_usr = get_dscr_usr();
  if (val != cur_dscr) {
    printf("[cpu %d] Kernel DSCR should be %ld but is %ld\n", sched_getcpu(),
           val, cur_dscr);
    return 1;
  }
  if (val != cur_dscr_usr) {
    printf("[cpu %d] User DSCR should be %ld but is %ld\n", sched_getcpu(), val,
           cur_dscr_usr);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_thread_dscr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1050 <get_dscr@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <get_dscr_usr@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1199 <test_thread_dscr+0x59>
mov    $0x0,%al
call   1060 <sched_getcpu@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <test_thread_dscr+0x97>
mov    -0x10(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11d0 <test_thread_dscr+0x90>
mov    $0x0,%al
call   1060 <sched_getcpu@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11d7 <test_thread_dscr+0x97>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_thread_dscr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <get_dscr@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <get_dscr_usr@plt>
cmp    %r14,%rbx
jne    1182 <test_thread_dscr+0x42>
mov    %rax,%r15
cmp    %r14,%rax
je     11a2 <test_thread_dscr+0x62>
xor    %eax,%eax
call   1060 <sched_getcpu@plt>
lea    0xeb7(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %r15,%rcx
jmp    1198 <test_thread_dscr+0x58>
xor    %eax,%eax
call   1060 <sched_getcpu@plt>
lea    0xe70(%rip),%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1030 <printf@plt>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [47 x i8] c"[cpu %d] Kernel DSCR should be %ld but is %ld\0A\00"
@.str.1 = [45 x i8] c"[cpu %d] User DSCR should be %ld but is %ld\0A\00"
define i32 @test_thread_dscr(i64 %0) {
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
%6 = call i64 (...) @get_dscr()
store i64 %6, i64* %4
%7 = call i64 (...) @get_dscr_usr()
store i64 %7, i64* %5
%8 = load i64, i64* %3
%9 = load i64, i64* %4
%10 = icmp ne i64 %8, %9
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = call i32 (...) @sched_getcpu()
%13 = load i64, i64* %3
%14 = load i64, i64* %4
%15 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %12, i64 %13, i64 %14)
store i32 1, i32* %2
br label %26
16: ; preds = %1
%17 = load i64, i64* %3
%18 = load i64, i64* %5
%19 = icmp ne i64 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = call i32 (...) @sched_getcpu()
%22 = load i64, i64* %3
%23 = load i64, i64* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %21, i64 %22, i64 %23)
store i32 1, i32* %2
br label %26
25: ; preds = %16
store i32 0, i32* %2
br label %26
26: ; preds = %25, %20, %11
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [47 x i8] c"[cpu %d] Kernel DSCR should be %ld but is %ld\0A\00"
@.str.1 = [45 x i8] c"[cpu %d] User DSCR should be %ld but is %ld\0A\00"
define i32 @test_thread_dscr(i64 %0) {
%2 = tail call i64 (...) @get_dscr()
%3 = tail call i64 (...) @get_dscr_usr()
%4 = icmp eq i64 %2, %0
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = tail call i32 (...) @sched_getcpu()
%7 = tail call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i32 %6, i64 %0, i64 %2)
br label %13
8: ; preds = %1
%9 = icmp eq i64 %3, %0
br i1 %9, label %13, label %10
10: ; preds = %8
%11 = tail call i32 (...) @sched_getcpu()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %11, i64 %0, i64 %3)
br label %13
13: ; preds = %8, %10, %5
%14 = phi i32 [ 1, %5 ], [ 1, %10 ], [ 0, %8 ]
ret i32 %14
}