#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 atoi(char *);
int /*<<< orphan*/ dprintf(int, char *, int, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int parse_curl_progress_bar(int fd, const char *str, size_t len) {
  char tmp[8] = {61};
  int percent;
  memcpy(&tmp[0], str + len - 6, 6);
  if (tmp[3] == ',' && tmp[5] == '%') {
    tmp[3] = '\0';
    percent = atoi(tmp);
    dprintf(fd, "%d\n# %d%%\n", percent, percent);
  }
  return 0;
}


x86 assembly (clang, -O0):
<parse_curl_progress_bar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xeb6(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    -0x18(%rbp),%rsi
add    $0xfffffffffffffffa,%rsi
mov    $0x6,%edx
call   1040 <memcpy@plt>
movsbl -0x1d(%rbp),%eax
cmp    $0x2c,%eax
jne    11a7 <parse_curl_progress_bar+0x77>
movsbl -0x1b(%rbp),%eax
cmp    $0x25,%eax
jne    11a7 <parse_curl_progress_bar+0x77>
movb   $0x0,-0x1d(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x24(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    -0x24(%rbp),%ecx
lea    0xe66(%rip),%rsi
call   1030 <dprintf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_curl_progress_bar>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movq   $0x3d,0x8(%rsp)
add    %rdx,%rsi
add    $0xfffffffffffffffa,%rsi
lea    0x8(%rsp),%rdi
mov    $0x6,%edx
call   1040 <memcpy@plt>
cmpb   $0x2c,0xb(%rsp)
jne    1185 <parse_curl_progress_bar+0x55>
cmpb   $0x25,0xd(%rsp)
jne    1185 <parse_curl_progress_bar+0x55>
movb   $0x0,0xb(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <atoi@plt>
lea    0xe86(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %eax,%ecx
call   1030 <dprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.parse_curl_progress_bar.tmp = [8 x i8] c"=\00\00\00\00\00\00\00"
@.str = [11 x i8] c"%d\0A# %d%%\0A\00"
define i32 @parse_curl_progress_bar(i32 %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca [8 x i8]
%8 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%9 = bitcast [8 x i8]* %7 to i8*
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%11 = load i8*, i8** %5
%12 = load i64, i64* %6
%13 = getelementptr inbounds i8, i8* %11, i64 %12
%14 = getelementptr inbounds i8, i8* %13, i64 -6
%15 = call i32 @memcpy(i8* %10, i8* %14, i32 6)
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 3
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 44
br i1 %19, label %20, label %33
20: ; preds = %3
%21 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 5
%22 = load i8, i8* %21
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 37
br i1 %24, label %25, label %33
25: ; preds = %20
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 3
store i8 0, i8* %26
%27 = getelementptr inbounds [8 x i8], [8 x i8]* %7, i64 0, i64 0
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %8
%29 = load i32, i32* %4
%30 = load i32, i32* %8
%31 = load i32, i32* %8
%32 = call i32 @dprintf(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %31)
br label %33
33: ; preds = %25, %20, %3
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"%d\0A# %d%%\0A\00"
define i32 @parse_curl_progress_bar(i32 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to [8 x i8]*
%6 = bitcast i64* %4 to i8*
store i64 61, i64* %4
%7 = getelementptr inbounds i8, i8* %1, i64 %2
%8 = getelementptr inbounds i8, i8* %7, i64 -6
%9 = call i32 @memcpy(i8* %6, i8* %8, i32 6)
%10 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 3
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 44
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 5
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 37
%16 = select i1 %12, i1 %15, i1 false
br i1 %16, label %17, label %20
17: ; preds = %3
store i8 0, i8* %10
%18 = call i32 @atoi(i8* %6)
%19 = call i32 @dprintf(i32 %0, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %18, i32 %18)
br label %20
20: ; preds = %17, %3
ret i32 0
}