#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 */
int sscanf(char *, char *, unsigned int *, int *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *get_mi_field(char *str, char *tag, int field_len, unsigned *value,
                   unsigned *has_value) {
  int i, j;
  i = strlen(tag);
  if (strncmp(str, tag, i))
    return NULL;
  str += i;
  if (*str == '*') {
    str++;
    *value = 0;
    *has_value = 0;
  } else {
    i = sscanf(str, "%8x%n", value, &j);
    if (i < 1)
      return NULL;
    *has_value = 1;
    str += j;
  }
  return str;
}


x86 assembly (clang, -O0):
<get_mi_field>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     117e <get_mi_field+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    1219 <get_mi_field+0xe9>
mov    -0x34(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2a,%eax
jne    11c4 <get_mi_field+0x94>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movl   $0x0,(%rax)
jmp    1211 <get_mi_field+0xe1>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xe2d(%rip),%rsi
lea    -0x38(%rbp),%rcx
call   1050 <sscanf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x1,-0x34(%rbp)
jge    11f6 <get_mi_field+0xc6>
movq   $0x0,-0x8(%rbp)
jmp    1219 <get_mi_field+0xe9>
mov    -0x30(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x38(%rbp),%ecx
mov    -0x10(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_mi_field>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %rcx,%r15
mov    %rsi,%rbx
mov    %rdi,%r13
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     1168 <get_mi_field+0x38>
xor    %r12d,%r12d
jmp    11b5 <get_mi_field+0x85>
movslq %ebp,%rax
lea    (%rax,%r13,1),%r12
cmpb   $0x2a,0x0(%r13,%rax,1)
jne    118b <get_mi_field+0x5b>
add    $0x1,%r12
movl   $0x0,(%r15)
movl   $0x0,(%r14)
jmp    11b5 <get_mi_field+0x85>
lea    0xe6e(%rip),%rsi
lea    0x4(%rsp),%rcx
mov    %r12,%rdi
mov    %r15,%rdx
call   1050 <sscanf@plt>
test   %eax,%eax
jle    1163 <get_mi_field+0x33>
movl   $0x1,(%r14)
movslq 0x4(%rsp),%rax
add    %rax,%r12
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [6 x i8] c"%8x%n\00"
define i8* @get_mi_field(i8* %0, i8* %1, i32 %2, i32* %3, i32* nocapture writeonly %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = tail call i32 @strlen(i8* %1)
%9 = tail call i64 @strncmp(i8* %0, i8* %1, i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %5
%12 = sext i32 %8 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 42
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = getelementptr inbounds i8, i8* %13, i64 1
store i32 0, i32* %3
store i32 0, i32* %4
br label %25
18: ; preds = %11
%19 = call i32 @sscanf(i8* %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %6)
%20 = icmp slt i32 %19, 1
br i1 %20, label %25, label %21
21: ; preds = %18
store i32 1, i32* %4
%22 = load i32, i32* %6
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %13, i64 %23
br label %25
25: ; preds = %16, %21, %18, %5
%26 = phi i8* [ null, %5 ], [ null, %18 ], [ %17, %16 ], [ %24, %21 ]
ret i8* %26
}