#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 */
typedef int /*<<< orphan*/ uint8_t;
typedef int /*<<< orphan*/ uint64_t;

/* Variables and functions */
int sdnv_decode(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sdnv_encode(int /*<<< orphan*/, int /*<<< orphan*/ *);
int sdnv_encoding_len(int /*<<< orphan*/);
int bundle_raw_set_proc_flags(uint8_t *primary_raw, uint64_t new_flags) {
  int off = 0, ret = 0, old_flags_l = 0, new_flags_l = 0;
  uint64_t old_flags = 0;
  off++;
  old_flags_l = sdnv_decode(primary_raw + off, &old_flags);
  new_flags_l = sdnv_encoding_len(new_flags);
  if (old_flags_l == new_flags_l) {
    sdnv_encode(new_flags, primary_raw + off);
  } else {
    ret = 1;
  }
  return ret;
}


x86 assembly (clang, -O0):
<bundle_raw_set_proc_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x20(%rbp),%rsi
call   1050 <sdnv_decode@plt>
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <sdnv_encoding_len@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b9 <bundle_raw_set_proc_flags+0x89>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1040 <sdnv_encode@plt>
jmp    11c0 <bundle_raw_set_proc_flags+0x90>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bundle_raw_set_proc_flags>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
add    $0x4,%rbx
lea    0xc(%rsp),%rsi
mov    %rbx,%rdi
call   1050 <sdnv_decode@plt>
mov    %eax,%ebp
mov    %r14d,%edi
call   1030 <sdnv_encoding_len@plt>
mov    %eax,%ecx
mov    $0x1,%eax
cmp    %ecx,%ebp
jne    1179 <bundle_raw_set_proc_flags+0x49>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <sdnv_encode@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @bundle_raw_set_proc_flags(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 1
store i32 %11, i32* %5
%12 = load i32*, i32** %3
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = call i32 @sdnv_decode(i32* %15, i32* %9)
store i32 %16, i32* %7
%17 = load i32, i32* %4
%18 = call i32 @sdnv_encoding_len(i32 %17)
store i32 %18, i32* %8
%19 = load i32, i32* %7
%20 = load i32, i32* %8
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %29
22: ; preds = %2
%23 = load i32, i32* %4
%24 = load i32*, i32** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = call i32 @sdnv_encode(i32 %23, i32* %27)
br label %30
29: ; preds = %2
store i32 1, i32* %6
br label %30
30: ; preds = %29, %22
%31 = load i32, i32* %6
ret i32 %31
}

LLVM IR (-O2):
define i32 @bundle_raw_set_proc_flags(i32* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%5 = getelementptr inbounds i32, i32* %0, i64 1
%6 = call i32 @sdnv_decode(i32* %5, i32* %3)
%7 = call i32 @sdnv_encoding_len(i32 %1)
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 @sdnv_encode(i32 %1, i32* %5)
br label %11
11: ; preds = %2, %9
%12 = phi i32 [ 0, %9 ], [ 1, %2 ]
ret i32 %12
}