#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 __builtin_ptx_read_gridid();
int __builtin_ptx_read_laneid();
int __builtin_ptx_read_nsmid();
int __builtin_ptx_read_nwarpid();
int __builtin_ptx_read_smid();
int __builtin_ptx_read_warpid();
int read_ids() {
  int a = __builtin_ptx_read_laneid();
  int b = __builtin_ptx_read_warpid();
  int c = __builtin_ptx_read_nwarpid();
  int d = __builtin_ptx_read_smid();
  int e = __builtin_ptx_read_nsmid();
  int f = __builtin_ptx_read_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   1040 <__builtin_ptx_read_laneid@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1050 <__builtin_ptx_read_warpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <__builtin_ptx_read_nwarpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1070 <__builtin_ptx_read_smid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1080 <__builtin_ptx_read_nsmid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <__builtin_ptx_read_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   1040 <__builtin_ptx_read_laneid@plt>
mov    %eax,%r14d
xor    %eax,%eax
call   1050 <__builtin_ptx_read_warpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <__builtin_ptx_read_nwarpid@plt>
mov    %eax,%r15d
xor    %eax,%eax
call   1070 <__builtin_ptx_read_smid@plt>
mov    %eax,%r12d
xor    %eax,%eax
call   1080 <__builtin_ptx_read_nsmid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <__builtin_ptx_read_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 (...) @__builtin_ptx_read_laneid()
store i32 %7, i32* %1
%8 = call i32 (...) @__builtin_ptx_read_warpid()
store i32 %8, i32* %2
%9 = call i32 (...) @__builtin_ptx_read_nwarpid()
store i32 %9, i32* %3
%10 = call i32 (...) @__builtin_ptx_read_smid()
store i32 %10, i32* %4
%11 = call i32 (...) @__builtin_ptx_read_nsmid()
store i32 %11, i32* %5
%12 = call i32 (...) @__builtin_ptx_read_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 (...) @__builtin_ptx_read_laneid()
%2 = tail call i32 (...) @__builtin_ptx_read_warpid()
%3 = tail call i32 (...) @__builtin_ptx_read_nwarpid()
%4 = tail call i32 (...) @__builtin_ptx_read_smid()
%5 = tail call i32 (...) @__builtin_ptx_read_nsmid()
%6 = tail call i32 (...) @__builtin_ptx_read_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
}