#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*/ read_serial_byte(int, unsigned char *, int);
bool read_serial_long(int serial_fd, unsigned int *out, int timeout) {
  unsigned int result = 0;
  unsigned char ch;
  int i;
  for (i = 0; i < 4; i++) {
    if (!read_serial_byte(serial_fd, &ch, timeout))
      return false;
    result = (result >> 8) | ((unsigned int)ch << 24);
  }
  *out = result;
  return true;
}


x86 assembly (clang, -O0):
<read_serial_long>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0x4,-0x20(%rbp)
jge    117e <read_serial_long+0x6e>
mov    -0x8(%rbp),%edi
mov    -0x14(%rbp),%edx
lea    -0x19(%rbp),%rsi
call   1030 <read_serial_byte@plt>
cmp    $0x0,%eax
jne    115e <read_serial_long+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    118e <read_serial_long+0x7e>
mov    -0x18(%rbp),%eax
shr    $0x8,%eax
movzbl -0x19(%rbp),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1130 <read_serial_long+0x20>
mov    -0x18(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_serial_long>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %edi,%ebp
lea    0xf(%rsp),%rsi
call   1030 <read_serial_byte@plt>
xor    %r15d,%r15d
test   %eax,%eax
je     11a8 <read_serial_long+0x98>
movzbl 0xf(%rsp),%r12d
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <read_serial_byte@plt>
test   %eax,%eax
je     11a8 <read_serial_long+0x98>
movzbl 0xf(%rsp),%r13d
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <read_serial_byte@plt>
test   %eax,%eax
je     11a8 <read_serial_long+0x98>
mov    %r14,0x10(%rsp)
movzbl 0xf(%rsp),%r14d
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    %ebx,%edx
call   1030 <read_serial_byte@plt>
test   %eax,%eax
je     11a8 <read_serial_long+0x98>
shl    $0x18,%r12d
shld   $0x18,%r12d,%r13d
shld   $0x18,%r13d,%r14d
movzbl 0xf(%rsp),%eax
shld   $0x18,%r14d,%eax
mov    0x10(%rsp),%rcx
mov    %eax,(%rcx)
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_serial_long(i32 %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 0, i32* %8
store i32 0, i32* %10
br label %11
11: ; preds = %27, %3
%12 = load i32, i32* %10
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %30
14: ; preds = %11
%15 = load i32, i32* %5
%16 = load i32, i32* %7
%17 = call i32 @read_serial_byte(i32 %15, i8* %9, i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %14
store i32 0, i32* %4
br label %33
20: ; preds = %14
%21 = load i32, i32* %8
%22 = lshr i32 %21, 8
%23 = load i8, i8* %9
%24 = zext i8 %23 to i32
%25 = shl i32 %24, 24
%26 = or i32 %22, %25
store i32 %26, i32* %8
br label %27
27: ; preds = %20
%28 = load i32, i32* %10
%29 = add nsw i32 %28, 1
store i32 %29, i32* %10
br label %11
30: ; preds = %11
%31 = load i32, i32* %8
%32 = load i32*, i32** %6
store i32 %31, i32* %32
store i32 1, i32* %4
br label %33
33: ; preds = %30, %19
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
define i32 @read_serial_long(i32 %0, i32* nocapture writeonly %1, i32 %2) {
%4 = alloca i8
%5 = call i32 @read_serial_byte(i32 %0, i8* %4, i32 %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %29, label %7
7: ; preds = %3
%8 = load i8, i8* %4
%9 = call i32 @read_serial_byte(i32 %0, i8* %4, i32 %2)
%10 = icmp eq i32 %9, 0
br i1 %10, label %29, label %11
11: ; preds = %7
%12 = load i8, i8* %4
%13 = call i32 @read_serial_byte(i32 %0, i8* %4, i32 %2)
%14 = icmp eq i32 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %11
%16 = load i8, i8* %4
%17 = call i32 @read_serial_byte(i32 %0, i8* %4, i32 %2)
%18 = icmp eq i32 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %15
%20 = zext i8 %16 to i32
%21 = zext i8 %12 to i32
%22 = zext i8 %8 to i32
%23 = shl nuw i32 %22, 24
%24 = call i32 @llvm.fshl.i32(i32 %21, i32 %23, i32 24)
%25 = call i32 @llvm.fshl.i32(i32 %20, i32 %24, i32 24)
%26 = load i8, i8* %4
%27 = zext i8 %26 to i32
%28 = call i32 @llvm.fshl.i32(i32 %27, i32 %25, i32 24)
store i32 %28, i32* %1
br label %29
29: ; preds = %3, %7, %11, %15, %19
%30 = phi i32 [ 1, %19 ], [ 0, %15 ], [ 0, %11 ], [ 0, %7 ], [ 0, %3 ]
ret i32 %30
}