#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*/ sprintf(char *, char *, char);
int /*<<< orphan*/ strcat(char *, char *);
char *strchr(char *, char);
scalar_t__ strlen(char *);
int str_hdcp(char *str) {
  int i, j;
  char status[9] = "";
  char tempchar[2];
  char *hdcp_stat;
  hdcp_stat = strchr(str, '=');
  i = hdcp_stat - str;
  for (j = (i + 1); j < (int)strlen(str); j++) {
    sprintf(tempchar, "%c", str[j]);
    strcat(status, tempchar);
  }
  i = atoi(status);
  return i;
}


x86 assembly (clang, -O0):
<str_hdcp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x19(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jge    11f9 <str_hdcp+0x99>
lea    -0x1b(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    0xe2b(%rip),%rsi
movsbl (%rax,%rcx,1),%edx
call   1080 <sprintf@plt>
lea    -0x19(%rbp),%rdi
lea    -0x1b(%rbp),%rsi
call   1070 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a5 <str_hdcp+0x45>
lea    -0x19(%rbp),%rdi
call   1060 <atoi@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_hdcp>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r12
movb   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    $0x3d,%esi
call   1040 <strchr@plt>
mov    %rax,%r14
sub    %r12d,%r14d
add    $0x1,%r14d
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    %eax,%r14d
jge    11bc <str_hdcp+0x7c>
movslq %r14d,%rbx
lea    0x8(%rsp),%r14
lea    0x6(%rsp),%r15
nopw   0x0(%rax,%rax,1)
movzbl (%r12,%rbx,1),%eax
mov    %al,0x6(%rsp)
movb   $0x0,0x7(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <strcat@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1190 <str_hdcp+0x50>
lea    0x8(%rsp),%rdi
call   1050 <atoi@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define i32 @str_hdcp(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [9 x i8]
%6 = alloca [2 x i8]
%7 = alloca i8*
store i8* %0, i8** %2
%8 = bitcast [9 x i8]* %5 to i8*
%9 = load i8*, i8** %2
%10 = call i8* @strchr(i8* %9, i8 signext 61)
store i8* %10, i8** %7
%11 = load i8*, i8** %7
%12 = load i8*, i8** %2
%13 = ptrtoint i8* %11 to i64
%14 = ptrtoint i8* %12 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %19
19: ; preds = %36, %1
%20 = load i32, i32* %4
%21 = load i8*, i8** %2
%22 = call i64 @strlen(i8* %21)
%23 = trunc i64 %22 to i32
%24 = icmp slt i32 %20, %23
br i1 %24, label %25, label %39
25: ; preds = %19
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%27 = load i8*, i8** %2
%28 = load i32, i32* %4
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %31)
%33 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%34 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%35 = call i32 @strcat(i8* %33, i8* %34)
br label %36
36: ; preds = %25
%37 = load i32, i32* %4
%38 = add nsw i32 %37, 1
store i32 %38, i32* %4
br label %19
39: ; preds = %19
%40 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 0
%41 = call i32 @atoi(i8* %40)
store i32 %41, i32* %3
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @str_hdcp(i8* %0) {
%2 = alloca [9 x i8]
%3 = alloca [2 x i8]
%4 = getelementptr inbounds [9 x i8], [9 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%6 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 61)
%7 = ptrtoint i8* %6 to i64
%8 = ptrtoint i8* %0 to i64
%9 = sub i64 %7, %8
%10 = trunc i64 %9 to i32
%11 = add i32 %10, 1
%12 = call i64 @strlen(i8* dereferenceable(1) %0)
%13 = trunc i64 %12 to i32
%14 = icmp slt i32 %11, %13
br i1 %14, label %15, label %28
15: ; preds = %1
%16 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 1
%17 = sext i32 %11 to i64
br label %18
18: ; preds = %15, %18
%19 = phi i64 [ %17, %15 ], [ %23, %18 ]
%20 = getelementptr inbounds i8, i8* %0, i64 %19
%21 = load i8, i8* %20
store i8 %21, i8* %5
store i8 0, i8* %16
%22 = call i32 @strcat(i8* %4, i8* %5)
%23 = add nsw i64 %19, 1
%24 = call i64 @strlen(i8* dereferenceable(1) %0)
%25 = shl i64 %24, 32
%26 = ashr exact i64 %25, 32
%27 = icmp slt i64 %23, %26
br i1 %27, label %18, label %28
28: ; preds = %18, %1
%29 = call i32 @atoi(i8* %4)
ret i32 %29
}