#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 /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ updateValueUtil(int *, int /*<<< orphan*/, int, int, int,
                                   int /*<<< orphan*/);
void updateValue(int arr[], int *st, int n, int i, int new_val) {
  if (i < 0 || i > n - 1) {
    printf("Invalid Input");
    return;
  }
  int diff = new_val - arr[i];
  arr[i] = new_val;
  updateValueUtil(st, 0, n - 1, i, diff, 0);
}


x86 assembly (clang, -O0):
<updateValue>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     1155 <updateValue+0x35>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    1166 <updateValue+0x46>
lea    0xea4(%rip),%rdi
call   1040 <printf@plt>
jmp    11a1 <updateValue+0x81>
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%rcx
movslq -0x18(%rbp),%rdx
sub    (%rcx,%rdx,4),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%r8d
xor    %r9d,%r9d
mov    %r9d,%esi
call   1030 <updateValueUtil@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<updateValue>:
test   %ecx,%ecx
js     1149 <updateValue+0x29>
cmp    %ecx,%edx
jle    1149 <updateValue+0x29>
mov    %ecx,%r9d
mov    %r8d,%eax
sub    (%rdi,%r9,4),%eax
add    $0xffffffff,%edx
mov    %r8d,(%rdi,%r9,4)
mov    %rsi,%rdi
xor    %esi,%esi
mov    %eax,%r8d
xor    %r9d,%r9d
jmp    1030 <updateValueUtil@plt>
lea    0xeb0(%rip),%rdi
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Invalid Input\00"
define void @updateValue(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %5
%15 = load i32, i32* %9
%16 = load i32, i32* %8
%17 = sub nsw i32 %16, 1
%18 = icmp sgt i32 %15, %17
br i1 %18, label %19, label %21
19: ; preds = %14, %5
%20 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %40
21: ; preds = %14
%22 = load i32, i32* %10
%23 = load i32*, i32** %6
%24 = load i32, i32* %9
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i32, i32* %23, i64 %25
%27 = load i32, i32* %26
%28 = sub nsw i32 %22, %27
store i32 %28, i32* %11
%29 = load i32, i32* %10
%30 = load i32*, i32** %6
%31 = load i32, i32* %9
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
store i32 %29, i32* %33
%34 = load i32*, i32** %7
%35 = load i32, i32* %8
%36 = sub nsw i32 %35, 1
%37 = load i32, i32* %9
%38 = load i32, i32* %11
%39 = call i32 @updateValueUtil(i32* %34, i32 0, i32 %36, i32 %37, i32 %38, i32 0)
br label %40
40: ; preds = %21, %19
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Invalid Input\00"
define void @updateValue(i32* nocapture %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp sgt i32 %3, -1
%7 = icmp sgt i32 %2, %3
%8 = and i1 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %5
%10 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %18
11: ; preds = %5
%12 = add nsw i32 %2, -1
%13 = zext i32 %3 to i64
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = sub nsw i32 %4, %15
store i32 %4, i32* %14
%17 = tail call i32 @updateValueUtil(i32* %1, i32 0, i32 %12, i32 %3, i32 %16, i32 0)
br label %18
18: ; preds = %11, %9
ret void
}