#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*/ va_list;

/* Variables and functions */
scalar_t__ my_parse_loop(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ my_putchar(char);
int my_parse_format(const char *fmt, va_list *list) {
  int i;
  if (fmt == NULL)
    return (-1);
  i = 0;
  if (fmt[1] == '%') {
    my_putchar('%');
    ++i;
  } else
    i += my_parse_loop(fmt, list);
  return (i);
}


x86 assembly (clang, -O0):
<my_parse_format>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1147 <my_parse_format+0x27>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <my_parse_format+0x77>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x25,%eax
jne    1177 <my_parse_format+0x57>
mov    $0x25,%edi
call   1040 <my_putchar@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1191 <my_parse_format+0x71>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <my_parse_loop@plt>
mov    %rax,%rcx
movslq -0x1c(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_parse_format>:
push   %rax
test   %rdi,%rdi
je     113d <my_parse_format+0x1d>
cmpb   $0x25,0x1(%rdi)
jne    1144 <my_parse_format+0x24>
mov    $0x25,%edi
call   1040 <my_putchar@plt>
mov    $0x1,%eax
pop    %rcx
ret
mov    $0xffffffff,%eax
pop    %rcx
ret
call   1030 <my_parse_loop@plt>
pop    %rcx
ret

LLVM IR (-O0):
define i32 @my_parse_format(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %30
10: ; preds = %2
store i32 0, i32* %6
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 1
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 37
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = call i32 @my_putchar(i8 signext 37)
%18 = load i32, i32* %6
%19 = add nsw i32 %18, 1
store i32 %19, i32* %6
br label %28
20: ; preds = %10
%21 = load i8*, i8** %4
%22 = load i32*, i32** %5
%23 = call i64 @my_parse_loop(i8* %21, i32* %22)
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = add nsw i64 %25, %23
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
br label %28
28: ; preds = %20, %16
%29 = load i32, i32* %6
store i32 %29, i32* %3
br label %30
30: ; preds = %28, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
define i32 @my_parse_format(i8* %0, i32* %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8, i8* %0, i64 1
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 37
br i1 %7, label %8, label %10
8: ; preds = %4
%9 = tail call i32 @my_putchar(i8 signext 37)
br label %13
10: ; preds = %4
%11 = tail call i64 @my_parse_loop(i8* %0, i32* %1)
%12 = trunc i64 %11 to i32
br label %13
13: ; preds = %8, %10, %2
%14 = phi i32 [ -1, %2 ], [ 1, %8 ], [ %12, %10 ]
ret i32 %14
}