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

/* Variables and functions */
int axt_recv(int, unsigned char *, int);
unsigned int axt_align(int sd) {
  unsigned char buf[4];
  int foundmagic = 0;
  int i = 0;
  int n = 0;
  while (!foundmagic) {
    n = axt_recv(sd, buf, sizeof(buf));
    if ((buf[0] == 0xaf) && (buf[1] == 0xfe) && (buf[2] == 0xc0) &&
        (buf[3] == 0xc0))
      foundmagic = 1;
    i += n;
  }
  return i - 4;
}


x86 assembly (clang, -O0):
<axt_align>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1146 <axt_align+0x36>
jmp    11ab <axt_align+0x9b>
mov    -0x4(%rbp),%edi
lea    -0x8(%rbp),%rsi
mov    $0x4,%edx
call   1030 <axt_recv@plt>
mov    %eax,-0x14(%rbp)
movzbl -0x8(%rbp),%eax
cmp    $0xaf,%eax
jne    119d <axt_align+0x8d>
movzbl -0x7(%rbp),%eax
cmp    $0xfe,%eax
jne    119d <axt_align+0x8d>
movzbl -0x6(%rbp),%eax
cmp    $0xc0,%eax
jne    119d <axt_align+0x8d>
movzbl -0x5(%rbp),%eax
cmp    $0xc0,%eax
jne    119d <axt_align+0x8d>
movl   $0x1,-0xc(%rbp)
mov    -0x14(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <axt_align+0x20>
mov    -0x10(%rbp),%eax
sub    $0x4,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<axt_align>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %ebx,%ebx
lea    0xc(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <axt_recv@plt>
movd   0xc(%rsp),%xmm0
movd   %xmm0,%ecx
add    %eax,%ebx
cmp    $0xc0c0feaf,%ecx
jne    1130 <axt_align+0x20>
add    $0xfffffffc,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @axt_align(i32 %0) {
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %4
store i32 0, i32* %5
store i32 0, i32* %6
br label %7
7: ; preds = %35, %1
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 0
%10 = xor i1 %9, true
br i1 %10, label %11, label %39
11: ; preds = %7
%12 = load i32, i32* %2
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%14 = call i32 @axt_recv(i32 %12, i8* %13, i32 4)
store i32 %14, i32* %6
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 0
%16 = load i8, i8* %15
%17 = zext i8 %16 to i32
%18 = icmp eq i32 %17, 175
br i1 %18, label %19, label %35
19: ; preds = %11
%20 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = icmp eq i32 %22, 254
br i1 %23, label %24, label %35
24: ; preds = %19
%25 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 2
%26 = load i8, i8* %25
%27 = zext i8 %26 to i32
%28 = icmp eq i32 %27, 192
br i1 %28, label %29, label %35
29: ; preds = %24
%30 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 3
%31 = load i8, i8* %30
%32 = zext i8 %31 to i32
%33 = icmp eq i32 %32, 192
br i1 %33, label %34, label %35
34: ; preds = %29
store i32 1, i32* %4
br label %35
35: ; preds = %34, %29, %24, %19, %11
%36 = load i32, i32* %6
%37 = load i32, i32* %5
%38 = add nsw i32 %37, %36
store i32 %38, i32* %5
br label %7
39: ; preds = %7
%40 = load i32, i32* %5
%41 = sub nsw i32 %40, 4
ret i32 %41
}

LLVM IR (-O2):
define i32 @axt_align(i32 %0) {
%2 = alloca <4 x i8>
%3 = getelementptr inbounds <4 x i8>, <4 x i8>* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %11, %4 ]
%6 = call i32 @axt_recv(i32 %0, i8* %3, i32 4)
%7 = load <4 x i8>, <4 x i8>* %2
%8 = freeze <4 x i8> %7
%9 = bitcast <4 x i8> %8 to i32
%10 = icmp eq i32 %9, -1061093713
%11 = add nsw i32 %6, %5
br i1 %10, label %12, label %4
12: ; preds = %4
%13 = add nsw i32 %11, -4
ret i32 %13
}