#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 __nvvm_read_ptx_sreg_gridid();
int __nvvm_read_ptx_sreg_laneid();
int __nvvm_read_ptx_sreg_nsmid();
int __nvvm_read_ptx_sreg_nwarpid();
int __nvvm_read_ptx_sreg_smid();
int __nvvm_read_ptx_sreg_warpid();
__attribute__((device)) int read_ids() {
  int a = __nvvm_read_ptx_sreg_laneid();
  int b = __nvvm_read_ptx_sreg_warpid();
  int c = __nvvm_read_ptx_sreg_nwarpid();
  int d = __nvvm_read_ptx_sreg_smid();
  int e = __nvvm_read_ptx_sreg_nsmid();
  int f = __nvvm_read_ptx_sreg_gridid();
  return a + b + c + d + e + f;
}


x86 assembly (clang, -O0):
<read_ids>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <__nvvm_read_ptx_sreg_laneid@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <__nvvm_read_ptx_sreg_warpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1070 <__nvvm_read_ptx_sreg_nwarpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1040 <__nvvm_read_ptx_sreg_smid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <__nvvm_read_ptx_sreg_nsmid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <__nvvm_read_ptx_sreg_gridid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
add    -0x10(%rbp),%eax
add    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ids>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %eax,%eax
call   1050 <__nvvm_read_ptx_sreg_laneid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1030 <__nvvm_read_ptx_sreg_warpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <__nvvm_read_ptx_sreg_nwarpid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1040 <__nvvm_read_ptx_sreg_smid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1080 <__nvvm_read_ptx_sreg_nsmid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <__nvvm_read_ptx_sreg_gridid@plt>
add    %r14d,%ebp
add    %r15d,%ebp
add    %r12d,%ebp
add    %ebx,%ebp
add    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_ids() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = call i32 (...) @__nvvm_read_ptx_sreg_laneid()
store i32 %7, i32* %1
%8 = call i32 (...) @__nvvm_read_ptx_sreg_warpid()
store i32 %8, i32* %2
%9 = call i32 (...) @__nvvm_read_ptx_sreg_nwarpid()
store i32 %9, i32* %3
%10 = call i32 (...) @__nvvm_read_ptx_sreg_smid()
store i32 %10, i32* %4
%11 = call i32 (...) @__nvvm_read_ptx_sreg_nsmid()
store i32 %11, i32* %5
%12 = call i32 (...) @__nvvm_read_ptx_sreg_gridid()
store i32 %12, i32* %6
%13 = load i32, i32* %1
%14 = load i32, i32* %2
%15 = add nsw i32 %13, %14
%16 = load i32, i32* %3
%17 = add nsw i32 %15, %16
%18 = load i32, i32* %4
%19 = add nsw i32 %17, %18
%20 = load i32, i32* %5
%21 = add nsw i32 %19, %20
%22 = load i32, i32* %6
%23 = add nsw i32 %21, %22
ret i32 %23
}

LLVM IR (-O2):
define i32 @read_ids() {
%1 = tail call i32 (...) @__nvvm_read_ptx_sreg_laneid()
%2 = tail call i32 (...) @__nvvm_read_ptx_sreg_warpid()
%3 = tail call i32 (...) @__nvvm_read_ptx_sreg_nwarpid()
%4 = tail call i32 (...) @__nvvm_read_ptx_sreg_smid()
%5 = tail call i32 (...) @__nvvm_read_ptx_sreg_nsmid()
%6 = tail call i32 (...) @__nvvm_read_ptx_sreg_gridid()
%7 = add nsw i32 %2, %1
%8 = add nsw i32 %7, %3
%9 = add nsw i32 %8, %4
%10 = add nsw i32 %9, %5
%11 = add nsw i32 %10, %6
ret i32 %11
}