#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ sscanf(char const *, char *, unsigned int *, unsigned int *);
int /*<<< orphan*/ stderr;
int get_chunk_size(char const *str, unsigned int *size,
                   unsigned int *consumed) {
  if (EOF == sscanf(str, "%x\r\n%n", size, consumed)) {
    fprintf(stderr, "cannot find chunk size\n");
    return -1;
  }
  if (!consumed) {
    fprintf(stderr, "chunk size is wierd\n");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_chunk_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xeab(%rip),%rsi
call   1040 <sscanf@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jne    118b <get_chunk_size+0x6b>
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0xe8d(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <get_chunk_size+0x9e>
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <get_chunk_size+0x97>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <get_chunk_size+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_chunk_size>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%rdx
mov    0x2eb7(%rip),%rax
mov    (%rax),%r14
lea    0xec5(%rip),%rsi
mov    %rbx,%rcx
call   1040 <sscanf@plt>
cmp    %rax,%r14
jne    1151 <get_chunk_size+0x31>
lea    0xeb8(%rip),%rsi
jmp    115f <get_chunk_size+0x3f>
xor    %eax,%eax
test   %rbx,%rbx
jne    1172 <get_chunk_size+0x52>
lea    0xec0(%rip),%rsi
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EOF = global i64 0
@.str = [7 x i8] c"%x\0D\0A%n\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"cannot find chunk size\0A\00"
@.str.2 = [21 x i8] c"chunk size is wierd\0A\00"
define i32 @get_chunk_size(i8* %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32*
store i8* %0, i8** %5
store i32* %1, i32** %6
store i32* %2, i32** %7
%8 = load i64, i64* @EOF
%9 = load i8*, i8** %5
%10 = load i32*, i32** %6
%11 = load i32*, i32** %7
%12 = call i64 @sscanf(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %10, i32* %11)
%13 = icmp eq i64 %8, %12
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %24
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = icmp ne i32* %18, null
br i1 %19, label %23, label %20
20: ; preds = %17
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %4
br label %24
23: ; preds = %17
store i32 0, i32* %4
br label %24
24: ; preds = %23, %20, %14
%25 = load i32, i32* %4
ret i32 %25
}

LLVM IR (-O2):
@EOF = global i64 0
@.str = [7 x i8] c"%x\0D\0A%n\00"
@stderr = global i32 0
@.str.1 = [24 x i8] c"cannot find chunk size\0A\00"
@.str.2 = [21 x i8] c"chunk size is wierd\0A\00"
define i32 @get_chunk_size(i8* %0, i32* %1, i32* %2) {
%4 = load i64, i64* @EOF
%5 = tail call i64 @sscanf(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%6 = icmp eq i64 %4, %5
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = icmp eq i32* %2, null
br i1 %8, label %9, label %13
9: ; preds = %7, %3
%10 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), %7 ]
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* %10)
br label %13
13: ; preds = %9, %7
%14 = phi i32 [ 0, %7 ], [ -1, %9 ]
ret i32 %14
}