#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 determine_logical_expression(char *, int *);
unsigned short getUShort(char *);
int handleIf(char *assembled, int currentPoint) {
  int conditionalResult =
      determine_logical_expression(assembled, &currentPoint);
  if (conditionalResult)
    return currentPoint + sizeof(unsigned short);
  unsigned short blockLen = getUShort(&assembled[currentPoint]);
  return currentPoint + sizeof(unsigned short) + blockLen;
}


x86 assembly (clang, -O0):
<handleIf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <determine_logical_expression@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1159 <handleIf+0x39>
movslq -0x14(%rbp),%rax
add    $0x2,%rax
mov    %eax,-0x4(%rbp)
jmp    117f <handleIf+0x5f>
mov    -0x10(%rbp),%rdi
movslq -0x14(%rbp),%rax
add    %rax,%rdi
call   1030 <getUShort@plt>
mov    %ax,-0x1a(%rbp)
movslq -0x14(%rbp),%rax
add    $0x2,%rax
movzwl -0x1a(%rbp),%ecx
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handleIf>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %esi,0xc(%rsp)
lea    0xc(%rsp),%rsi
call   1040 <determine_logical_expression@plt>
mov    %eax,%ecx
movslq 0xc(%rsp),%rax
test   %ecx,%ecx
je     1146 <handleIf+0x26>
add    $0x2,%eax
jmp    115d <handleIf+0x3d>
add    %rax,%rbx
mov    %rbx,%rdi
call   1030 <getUShort@plt>
mov    0xc(%rsp),%ecx
movzwl %ax,%eax
add    %ecx,%eax
add    $0x2,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @handleIf(i8* %0, i32 %1) {
%3 = alloca i32
store i32 %1, i32* %3
%4 = call i32 @determine_logical_expression(i8* %0, i32* %3)
%5 = icmp eq i32 %4, 0
%6 = load i32, i32* %3
br i1 %5, label %9, label %7
7: ; preds = %2
%8 = add i32 %6, 2
br label %17
9: ; preds = %2
%10 = sext i32 %6 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = call zeroext i16 @getUShort(i8* %11)
%13 = load i32, i32* %3
%14 = add i32 %13, 2
%15 = zext i16 %12 to i32
%16 = add i32 %14, %15
br label %17
17: ; preds = %9, %7
%18 = phi i32 [ %8, %7 ], [ %16, %9 ]
ret i32 %18
}