#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 */
struct timespec {
  long tv_sec;
  long tv_nsec;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int __syscall(int, int /*<<< orphan*/, long *);
int __syscall_ret(int);
int syscall(int, int /*<<< orphan*/, struct timespec *);
int sched_rr_get_interval(pid_t pid, struct timespec *ts) {
  if (161 != 423) {
    long ts32[2];
    int r = __syscall(161, pid, ts32);
    if (!r) {
      ts->tv_sec = ts32[0];
      ts->tv_nsec = ts32[1];
    }
    return __syscall_ret(r);
  }
  return syscall(161, pid, ts);
}


x86 assembly (clang, -O0):
<sched_rr_get_interval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%esi
lea    -0x20(%rbp),%rdx
mov    $0xa1,%edi
call   1030 <__syscall@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1164 <sched_rr_get_interval+0x44>
mov    -0x20(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x24(%rbp),%edi
call   1040 <__syscall_ret@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sched_rr_get_interval>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%esi
mov    %rsp,%rdx
mov    $0xa1,%edi
call   1030 <__syscall@plt>
test   %eax,%eax
jne    1142 <sched_rr_get_interval+0x22>
movaps (%rsp),%xmm0
movups %xmm0,(%rbx)
mov    %eax,%edi
call   1040 <__syscall_ret@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define i32 @sched_rr_get_interval(i32 %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca %struct.timespec*
%5 = alloca [2 x i64]
%6 = alloca i32
store i32 %0, i32* %3
store %struct.timespec* %1, %struct.timespec** %4
%7 = load i32, i32* %3
%8 = getelementptr inbounds [2 x i64], [2 x i64]* %5, i64 0, i64 0
%9 = call i32 @__syscall(i32 161, i32 %7, i64* %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %21, label %12
12: ; preds = %2
%13 = getelementptr inbounds [2 x i64], [2 x i64]* %5, i64 0, i64 0
%14 = load i64, i64* %13
%15 = load %struct.timespec*, %struct.timespec** %4
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 0
store i64 %14, i64* %16
%17 = getelementptr inbounds [2 x i64], [2 x i64]* %5, i64 0, i64 1
%18 = load i64, i64* %17
%19 = load %struct.timespec*, %struct.timespec** %4
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
store i64 %18, i64* %20
br label %21
21: ; preds = %12, %2
%22 = load i32, i32* %6
%23 = call i32 @__syscall_ret(i32 %22)
ret i32 %23
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define i32 @sched_rr_get_interval(i32 %0, %struct.timespec* nocapture writeonly %1) {
%3 = alloca <2 x i64>
%4 = bitcast <2 x i64>* %3 to i8*
%5 = getelementptr inbounds <2 x i64>, <2 x i64>* %3, i64 0, i64 0
%6 = call i32 @__syscall(i32 161, i32 %0, i64* %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load <2 x i64>, <2 x i64>* %3
%10 = bitcast %struct.timespec* %1 to <2 x i64>*
store <2 x i64> %9, <2 x i64>* %10
br label %11
11: ; preds = %8, %2
%12 = call i32 @__syscall_ret(i32 %6)
ret i32 %12
}