#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__ uint64_t;

/* Variables and functions */
int sscanf(char *, char *, unsigned long long *);
int strlen(char *);
int read_128(char *s, uint64_t *v) {
  int l, t;
  char save;
  l = strlen(s);
  if (l > 32)
    return 0;
  if (l > 16) {
    if (sscanf(s + (l - 16), "%llx", (long long unsigned int *)&(v[1])) == 0)
      return 0;
    save = s[l - 16];
    s[l - 16] = '\0';
    t = sscanf(s, "%llx", (long long unsigned int *)&(v[0]));
    s[l - 16] = save;
    return t;
  } else {
    v[0] = 0;
    return sscanf(s, "%llx", (long long unsigned int *)&(v[1]));
  }
  return 1;
}


x86 assembly (clang, -O0):
<read_128>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x20,-0x1c(%rbp)
jle    1152 <read_128+0x32>
movl   $0x0,-0x4(%rbp)
jmp    1213 <read_128+0xf3>
cmpl   $0x10,-0x1c(%rbp)
jle    11ed <read_128+0xcd>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%eax
sub    $0x10,%eax
cltq
add    %rax,%rdi
mov    -0x18(%rbp),%rdx
add    $0x8,%rdx
lea    0xe86(%rip),%rsi
call   1040 <sscanf@plt>
cmp    $0x0,%eax
jne    1194 <read_128+0x74>
movl   $0x0,-0x4(%rbp)
jmp    1213 <read_128+0xf3>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x10,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x21(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x10,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x20(%rbp)
mov    -0x21(%rbp),%dl
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x10,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1213 <read_128+0xf3>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
add    $0x8,%rdx
lea    0xdf5(%rip),%rsi
call   1040 <sscanf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_128>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <strlen@plt>
cmp    $0x20,%eax
jle    113b <read_128+0x1b>
xor    %eax,%eax
jmp    117a <read_128+0x5a>
mov    %eax,%ebx
cmp    $0x11,%eax
jl     1185 <read_128+0x65>
add    $0xfffffff0,%ebx
add    %r15,%rbx
lea    0x8(%r14),%rdx
lea    0xead(%rip),%rsi
mov    %rbx,%rdi
call   1040 <sscanf@plt>
test   %eax,%eax
je     1137 <read_128+0x17>
mov    (%rbx),%bpl
movb   $0x0,(%rbx)
lea    0xe94(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
call   1040 <sscanf@plt>
mov    %bpl,(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movq   $0x0,(%r14)
add    $0x8,%r14
lea    0xe69(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sscanf@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%llx\00"
define i32 @read_128(i8* %0, i64* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8
store i8* %0, i8** %4
store i64* %1, i64** %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 32
br i1 %12, label %13, label %14
13: ; preds = %2
store i32 0, i32* %3
br label %58
14: ; preds = %2
%15 = load i32, i32* %6
%16 = icmp sgt i32 %15, 16
br i1 %16, label %17, label %51
17: ; preds = %14
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = sub nsw i32 %19, 16
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i64*, i64** %5
%24 = getelementptr inbounds i64, i64* %23, i64 1
%25 = call i32 @sscanf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %17
store i32 0, i32* %3
br label %58
28: ; preds = %17
%29 = load i8*, i8** %4
%30 = load i32, i32* %6
%31 = sub nsw i32 %30, 16
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
%34 = load i8, i8* %33
store i8 %34, i8* %8
%35 = load i8*, i8** %4
%36 = load i32, i32* %6
%37 = sub nsw i32 %36, 16
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %35, i64 %38
store i8 0, i8* %39
%40 = load i8*, i8** %4
%41 = load i64*, i64** %5
%42 = getelementptr inbounds i64, i64* %41, i64 0
%43 = call i32 @sscanf(i8* %40, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %42)
store i32 %43, i32* %7
%44 = load i8, i8* %8
%45 = load i8*, i8** %4
%46 = load i32, i32* %6
%47 = sub nsw i32 %46, 16
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8 %44, i8* %49
%50 = load i32, i32* %7
store i32 %50, i32* %3
br label %58
51: ; preds = %14
%52 = load i64*, i64** %5
%53 = getelementptr inbounds i64, i64* %52, i64 0
store i64 0, i64* %53
%54 = load i8*, i8** %4
%55 = load i64*, i64** %5
%56 = getelementptr inbounds i64, i64* %55, i64 1
%57 = call i32 @sscanf(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %56)
store i32 %57, i32* %3
br label %58
58: ; preds = %51, %28, %27, %13
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@.str = [5 x i8] c"%llx\00"
define i32 @read_128(i8* %0, i64* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = icmp sgt i32 %3, 32
br i1 %4, label %20, label %5
5: ; preds = %2
%6 = icmp sgt i32 %3, 16
br i1 %6, label %7, label %17
7: ; preds = %5
%8 = add nsw i32 %3, -16
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = getelementptr inbounds i64, i64* %1, i64 1
%12 = tail call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %7
%15 = load i8, i8* %10
store i8 0, i8* %10
%16 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %1)
store i8 %15, i8* %10
br label %20
17: ; preds = %5
store i64 0, i64* %1
%18 = getelementptr inbounds i64, i64* %1, i64 1
%19 = tail call i32 @sscanf(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64* %18)
br label %20
20: ; preds = %7, %2, %17, %14
%21 = phi i32 [ %16, %14 ], [ %19, %17 ], [ 0, %2 ], [ 0, %7 ]
ret i32 %21
}