#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 int /*<<< orphan*/ sp;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, char const *, size_t, size_t, char *,
                          char const *, size_t, char *, char *, size_t);
size_t scan(char const *, size_t, char *);
size_t strlen(char *);
scalar_t__ strncmp(char const *, char *, size_t);
void _do_scan(const char *str, size_t str_len, size_t scn_len, const char *exp,
              size_t exp_len) {
  char res[32], sp[32];
  size_t res_len, inp_len;
  inp_len = scan(str, str_len, res);
  res_len = strlen(res);
  memset(sp, ' ', sizeof(sp));
  sp[15 - str_len] = '\0';
  printf("[%s](%2d/%2d)%s: %8s(%d) %s %8s(%d)\n", str, inp_len, scn_len, sp,
         exp, exp_len,
         inp_len != scn_len || exp_len != res_len || strncmp(exp, res, exp_len)
             ? "!="
             : "==",
         res, res_len);
}


x86 assembly (clang, -O0):
<_do_scan>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xd8,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1070 <scan@plt>
mov    %rax,-0x80(%rbp)
lea    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x20,%edx
mov    %edx,%esi
call   1060 <memset@plt>
mov    $0xf,%eax
sub    -0x18(%rbp),%rax
movb   $0x0,-0x70(%rbp,%rax,1)
mov    -0x10(%rbp),%rax
mov    %rax,-0xb8(%rbp)
mov    -0x80(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x70(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x80(%rbp),%rcx
mov    $0x1,%al
cmp    -0x20(%rbp),%rcx
mov    %al,-0x81(%rbp)
jne    123c <_do_scan+0xec>
mov    -0x30(%rbp),%rcx
mov    $0x1,%al
cmp    -0x78(%rbp),%rcx
mov    %al,-0x81(%rbp)
jne    123c <_do_scan+0xec>
mov    -0x28(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x81(%rbp)
mov    -0x90(%rbp),%rbx
mov    -0x98(%rbp),%r9
mov    -0xa0(%rbp),%r8
mov    -0xa8(%rbp),%rcx
mov    -0xb0(%rbp),%rdx
mov    -0xb8(%rbp),%rsi
mov    -0x81(%rbp),%dil
lea    0xdb4(%rip),%r11
lea    0xdaa(%rip),%rax
test   $0x1,%dil
cmovne %rax,%r11
lea    -0x50(%rbp),%r10
mov    -0x78(%rbp),%rax
lea    0xd6e(%rip),%rdi
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1050 <printf@plt>
add    $0xd8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<_do_scan>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %r8,%r13
mov    %rcx,(%rsp)
mov    %rdx,%rbp
mov    %rsi,%r14
lea    0x10(%rsp),%rbx
mov    %rdi,0x8(%rsp)
mov    %rbx,%rdx
call   1070 <scan@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbx
lea    0x30(%rsp),%r12
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
sub    %r14,%r12
movb   $0x0,0xf(%r12)
lea    0xe73(%rip),%rax
cmp    %rbp,%r15
jne    11ea <_do_scan+0x9a>
mov    %rbx,%r14
cmp    %r13,%rbx
mov    (%rsp),%rbx
jne    11f1 <_do_scan+0xa1>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
mov    %r13,%rdx
call   1030 <strncmp@plt>
test   %rax,%rax
lea    0xe4b(%rip),%rcx
lea    0xe41(%rip),%rax
cmove  %rcx,%rax
jmp    11f1 <_do_scan+0xa1>
mov    %rbx,%r14
mov    (%rsp),%rbx
lea    0xe08(%rip),%rdi
lea    0x30(%rsp),%r8
mov    0x8(%rsp),%rsi
mov    %r15,%rdx
mov    %rbp,%rcx
mov    %rbx,%r9
push   %r14
lea    0x18(%rsp),%rbp
push   %rbp
push   %rax
push   %r13
call   1050 <printf@plt>
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [37 x i8] c"[%s](%2d/%2d)%s: %8s(%d) %s %8s(%d)\0A\00"
@.str.1 = [3 x i8] c"!=\00"
@.str.2 = [3 x i8] c"==\00"
define void @_do_scan(i8* %0, i64 %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i64
%11 = alloca [32 x i8]
%12 = alloca [32 x i8]
%13 = alloca i64
%14 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i64 %2, i64* %8
store i8* %3, i8** %9
store i64 %4, i64* %10
%15 = load i8*, i8** %6
%16 = load i64, i64* %7
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%18 = call i64 @scan(i8* %15, i64 %16, i8* %17)
store i64 %18, i64* %14
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%20 = call i64 @strlen(i8* %19)
store i64 %20, i64* %13
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%22 = call i32 @memset(i8* %21, i8 signext 32, i32 32)
%23 = load i64, i64* %7
%24 = sub i64 15, %23
%25 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 %24
store i8 0, i8* %25
%26 = load i8*, i8** %6
%27 = load i64, i64* %14
%28 = load i64, i64* %8
%29 = getelementptr inbounds [32 x i8], [32 x i8]* %12, i64 0, i64 0
%30 = load i8*, i8** %9
%31 = load i64, i64* %10
%32 = load i64, i64* %14
%33 = load i64, i64* %8
%34 = icmp ne i64 %32, %33
br i1 %34, label %45, label %35
35: ; preds = %5
%36 = load i64, i64* %10
%37 = load i64, i64* %13
%38 = icmp ne i64 %36, %37
br i1 %38, label %45, label %39
39: ; preds = %35
%40 = load i8*, i8** %9
%41 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%42 = load i64, i64* %10
%43 = call i64 @strncmp(i8* %40, i8* %41, i64 %42)
%44 = icmp ne i64 %43, 0
br label %45
45: ; preds = %39, %35, %5
%46 = phi i1 [ true, %35 ], [ true, %5 ], [ %44, %39 ]
%47 = zext i1 %46 to i64
%48 = select i1 %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
%49 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%50 = load i64, i64* %13
%51 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %26, i64 %27, i64 %28, i8* %29, i8* %30, i64 %31, i8* %48, i8* %49, i64 %50)
ret void
}

LLVM IR (-O2):
@.str = [37 x i8] c"[%s](%2d/%2d)%s: %8s(%d) %s %8s(%d)\0A\00"
@.str.1 = [3 x i8] c"!=\00"
@.str.2 = [3 x i8] c"==\00"
define void @_do_scan(i8* %0, i64 %1, i64 %2, i8* %3, i64 %4) {
%6 = alloca [32 x i8]
%7 = alloca [32 x i8]
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%10 = call i64 @scan(i8* %0, i64 %1, i8* %8)
%11 = call i64 @strlen(i8* %8)
%12 = call i32 @memset(i8* %9, i8 signext 32, i32 32)
%13 = sub i64 15, %1
%14 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 %13
store i8 0, i8* %14
%15 = icmp eq i64 %10, %2
%16 = icmp eq i64 %11, %4
%17 = select i1 %15, i1 %16, i1 false
br i1 %17, label %18, label %22
18: ; preds = %5
%19 = call i64 @strncmp(i8* %3, i8* %8, i64 %4)
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
br label %22
22: ; preds = %18, %5
%23 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %5 ], [ %21, %18 ]
%24 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %0, i64 %10, i64 %2, i8* %9, i8* %3, i64 %4, i8* %23, i8* %8, i64 %11)
ret void
}