#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 /*<<< orphan*/ clearCarryflag(char *);
char getCarryflag(char *);
int /*<<< orphan*/ setCarryflag(char *);
void op_alu_ror(char regina[], char reginb[], char regouta[], char flags[]) {
  char old_carry = getCarryflag(flags);
  regouta[8 - 1] == '1' ? setCarryflag(flags) : clearCarryflag(flags);
  int i;
  for (i = 8 - 1; i > 0; i--)
    regouta[i] = regouta[i - 1];
  regouta[0] = old_carry;
}


x86 assembly (clang, -O0):
<op_alu_ror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <getCarryflag@plt>
mov    %al,-0x21(%rbp)
mov    -0x18(%rbp),%rax
movsbl 0x7(%rax),%eax
cmp    $0x31,%eax
jne    1173 <op_alu_ror+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <setCarryflag@plt>
jmp    117c <op_alu_ror+0x4c>
mov    -0x20(%rbp),%rdi
call   1050 <clearCarryflag@plt>
movl   $0x7,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jle    11b6 <op_alu_ror+0x86>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x28(%rbp)
jmp    1183 <op_alu_ror+0x53>
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<op_alu_ror>:
push   %rbp
push   %r14
push   %rbx
mov    %rcx,%rbp
mov    %rdx,%rbx
mov    %rcx,%rdi
call   1040 <getCarryflag@plt>
mov    %eax,%r14d
cmpb   $0x31,0x7(%rbx)
jne    1155 <op_alu_ror+0x25>
mov    %rbp,%rdi
call   1030 <setCarryflag@plt>
jmp    115d <op_alu_ror+0x2d>
mov    %rbp,%rdi
call   1050 <clearCarryflag@plt>
movzwl 0x4(%rbx),%eax
mov    (%rbx),%ecx
mov    %ecx,0x1(%rbx)
mov    0x6(%rbx),%cl
mov    %ax,0x5(%rbx)
mov    %cl,0x7(%rbx)
mov    %r14b,(%rbx)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @op_alu_ror(i8* %0, i8* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%11 = load i8*, i8** %8
%12 = call signext i8 @getCarryflag(i8* %11)
store i8 %12, i8* %9
%13 = load i8*, i8** %7
%14 = getelementptr inbounds i8, i8* %13, i64 7
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp eq i32 %16, 49
br i1 %17, label %18, label %21
18: ; preds = %4
%19 = load i8*, i8** %8
%20 = call i32 @setCarryflag(i8* %19)
br label %24
21: ; preds = %4
%22 = load i8*, i8** %8
%23 = call i32 @clearCarryflag(i8* %22)
br label %24
24: ; preds = %21, %18
%25 = phi i32 [ %20, %18 ], [ %23, %21 ]
store i32 7, i32* %10
br label %26
26: ; preds = %40, %24
%27 = load i32, i32* %10
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %43
29: ; preds = %26
%30 = load i8*, i8** %7
%31 = load i32, i32* %10
%32 = sub nsw i32 %31, 1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = load i8, i8* %34
%36 = load i8*, i8** %7
%37 = load i32, i32* %10
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 %35, i8* %39
br label %40
40: ; preds = %29
%41 = load i32, i32* %10
%42 = add nsw i32 %41, -1
store i32 %42, i32* %10
br label %26
43: ; preds = %26
%44 = load i8, i8* %9
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 0
store i8 %44, i8* %46
ret void
}

LLVM IR (-O2):
define void @op_alu_ror(i8* nocapture readnone %0, i8* nocapture readnone %1, i8* nocapture %2, i8* %3) {
%5 = tail call signext i8 @getCarryflag(i8* %3)
%6 = getelementptr inbounds i8, i8* %2, i64 7
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 49
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call i32 @setCarryflag(i8* %3)
br label %13
11: ; preds = %4
%12 = tail call i32 @clearCarryflag(i8* %3)
br label %13
13: ; preds = %11, %9
%14 = getelementptr i8, i8* %2, i64 1
store i8 %5, i8* %2
ret void
}