#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_HEXAGON_S4_extract(int, int, int);
int foo(int x) {
  return __builtin_HEXAGON_S4_extract(x, 33, -1) +
         __builtin_HEXAGON_S4_extract(x, 3, 91) +
         __builtin_HEXAGON_S4_extract(x, -1, 35) +
         __builtin_HEXAGON_S4_extract(x, 0, 31) +
         __builtin_HEXAGON_S4_extract(x, 31, 0);
}


x86 assembly (clang, -O0):
<foo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x21,%esi
mov    $0xffffffff,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x3,%esi
mov    $0x5b,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xffffffff,%esi
mov    $0x23,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
xor    %esi,%esi
mov    $0x1f,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ecx
mov    -0xc(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x1f,%esi
xor    %edx,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ecx
mov    -0x8(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<foo>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r15d
mov    $0x21,%esi
mov    $0xffffffff,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%r14d
mov    %r15d,%edi
mov    $0x3,%esi
mov    $0x5b,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ebp
add    %r14d,%ebp
mov    %r15d,%edi
mov    $0xffffffff,%esi
mov    $0x23,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ebx
add    %ebp,%ebx
mov    %r15d,%edi
xor    %esi,%esi
mov    $0x1f,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
mov    %eax,%ebp
add    %ebx,%ebp
mov    %r15d,%edi
mov    $0x1f,%esi
xor    %edx,%edx
call   1030 <__builtin_HEXAGON_S4_extract@plt>
add    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @foo(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @__builtin_HEXAGON_S4_extract(i32 %3, i32 33, i32 -1)
%5 = load i32, i32* %2
%6 = call i32 @__builtin_HEXAGON_S4_extract(i32 %5, i32 3, i32 91)
%7 = add nsw i32 %4, %6
%8 = load i32, i32* %2
%9 = call i32 @__builtin_HEXAGON_S4_extract(i32 %8, i32 -1, i32 35)
%10 = add nsw i32 %7, %9
%11 = load i32, i32* %2
%12 = call i32 @__builtin_HEXAGON_S4_extract(i32 %11, i32 0, i32 31)
%13 = add nsw i32 %10, %12
%14 = load i32, i32* %2
%15 = call i32 @__builtin_HEXAGON_S4_extract(i32 %14, i32 31, i32 0)
%16 = add nsw i32 %13, %15
ret i32 %16
}

LLVM IR (-O2):
define i32 @foo(i32 %0) {
%2 = tail call i32 @__builtin_HEXAGON_S4_extract(i32 %0, i32 33, i32 -1)
%3 = tail call i32 @__builtin_HEXAGON_S4_extract(i32 %0, i32 3, i32 91)
%4 = add nsw i32 %3, %2
%5 = tail call i32 @__builtin_HEXAGON_S4_extract(i32 %0, i32 -1, i32 35)
%6 = add nsw i32 %4, %5
%7 = tail call i32 @__builtin_HEXAGON_S4_extract(i32 %0, i32 0, i32 31)
%8 = add nsw i32 %6, %7
%9 = tail call i32 @__builtin_HEXAGON_S4_extract(i32 %0, i32 31, i32 0)
%10 = add nsw i32 %8, %9
ret i32 %10
}