#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 */
char const UpcComputeCheckDigit(char const *, int);
int ValidateUPC(const char *upc, int fullDigitCount) {
  if (!upc) {
    return 0;
  }
  if (fullDigitCount < 1) {
    return 0;
  }
  return upc[fullDigitCount - 1] ==
         UpcComputeCheckDigit(upc, fullDigitCount - 1);
}


x86 assembly (clang, -O0):
<ValidateUPC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1136 <ValidateUPC+0x26>
movl   $0x0,-0x4(%rbp)
jmp    1184 <ValidateUPC+0x74>
cmpl   $0x1,-0x14(%rbp)
jge    114c <ValidateUPC+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    1184 <ValidateUPC+0x74>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
call   1030 <UpcComputeCheckDigit@plt>
mov    %al,%cl
mov    -0x18(%rbp),%eax
movsbl %cl,%ecx
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ValidateUPC>:
xor    %eax,%eax
test   %rdi,%rdi
je     1131 <ValidateUPC+0x21>
test   %esi,%esi
jle    1131 <ValidateUPC+0x21>
push   %rbx
add    $0xffffffff,%esi
mov    (%rdi,%rsi,1),%bl
call   1030 <UpcComputeCheckDigit@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %cl,%bl
sete   %al
pop    %rbx
ret

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

LLVM IR (-O2):
define i32 @ValidateUPC(i8* %0, i32 %1) {
%3 = icmp eq i8* %0, null
%4 = icmp slt i32 %1, 1
%5 = or i1 %3, %4
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = add nsw i32 %1, -1
%8 = zext i32 %7 to i64
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = load i8, i8* %9
%11 = tail call signext i8 @UpcComputeCheckDigit(i8* %0, i32 %7)
%12 = icmp eq i8 %10, %11
%13 = zext i1 %12 to i32
br label %14
14: ; preds = %2, %6
%15 = phi i32 [ %13, %6 ], [ 0, %2 ]
ret i32 %15
}