#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 scalar_t__ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ sscanf(char const *, char *, scalar_t__ *);
uint8_t checksum(const char *line, int size) {
  int i;
  uint8_t byte, res = 0;
  for (i = 0; i < size; i += 2) {
    byte = 0;
    sscanf(line + i, "%02hhx", &byte);
    res += byte;
  }
  return 0x100 - res;
}


x86 assembly (clang, -O0):
<checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1177 <checksum+0x67>
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x10(%rbp),%rax
add    %rax,%rdi
lea    0xeac(%rip),%rsi
lea    -0x18(%rbp),%rdx
call   1030 <sscanf@plt>
mov    -0x18(%rbp),%rax
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <checksum+0x1e>
mov    $0x100,%eax
sub    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checksum>:
test   %esi,%esi
jle    117b <checksum+0x6b>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r13d
mov    %rdi,%r14
xor    %ebx,%ebx
lea    0xed2(%rip),%r15
mov    %rsp,%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movq   $0x0,(%rsp)
lea    (%r14,%rbx,1),%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <sscanf@plt>
add    (%rsp),%rbp
add    $0x2,%rbx
cmp    %r13d,%ebx
jl     1140 <checksum+0x30>
mov    $0x100,%eax
sub    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x100,%eax
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%02hhx\00"
define i64 @checksum(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
store i32 %1, i32* %4
store i64 0, i64* %7
store i32 0, i32* %5
br label %8
8: ; preds = %21, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %24
12: ; preds = %8
store i64 0, i64* %6
%13 = load i8*, i8** %3
%14 = load i32, i32* %5
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64* %6)
%18 = load i64, i64* %6
%19 = load i64, i64* %7
%20 = add nsw i64 %19, %18
store i64 %20, i64* %7
br label %21
21: ; preds = %12
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 2
store i32 %23, i32* %5
br label %8
24: ; preds = %8
%25 = load i64, i64* %7
%26 = sub nsw i64 256, %25
ret i64 %26
}

LLVM IR (-O2):
@.str = [7 x i8] c"%02hhx\00"
define i64 @checksum(i8* nocapture %0, i32 %1) {
%3 = alloca i64
%4 = bitcast i64* %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %2, %6
%7 = phi i64 [ %13, %6 ], [ 0, %2 ]
%8 = phi i64 [ %12, %6 ], [ 0, %2 ]
store i64 0, i64* %3
%9 = getelementptr inbounds i8, i8* %0, i64 %7
%10 = call i32 @sscanf(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64* %3)
%11 = load i64, i64* %3
%12 = add nsw i64 %11, %8
%13 = add nuw i64 %7, 2
%14 = trunc i64 %13 to i32
%15 = icmp slt i32 %14, %1
br i1 %15, label %6, label %16
16: ; preds = %6
%17 = sub i64 256, %12
br label %18
18: ; preds = %16, %2
%19 = phi i64 [ 256, %2 ], [ %17, %16 ]
ret i64 %19
}