#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 scalar_t__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ copy_to_buffer(scalar_t__);
int get_buffer_rx_state();
scalar_t__ get_identifier();
int /*<<< orphan*/ set_cpu_read_flag(int);
uint32_t buffers_loop(uint32_t packet_count) {
  uint32_t id = 0;
  uint32_t packets_rxd = 0;
  uint32_t packets_rxd_next = 0;
  uint32_t infinite_loops = (packet_count == 0) ? 1 : 0;
  while (infinite_loops || (packets_rxd < packet_count)) {
    int the_state = get_buffer_rx_state();
    switch (the_state) {
    case 0:
      packets_rxd = packets_rxd_next;
      break;
    case 2:
      set_cpu_read_flag(1);
      packets_rxd = packets_rxd_next;
      while (get_buffer_rx_state() != 3)
        ;
      break;
    case 3:
      id = get_identifier();
      packets_rxd_next += 1;
      set_cpu_read_flag(0);
      break;
    case 4:
      copy_to_buffer(id);
      set_cpu_read_flag(1);
      break;
    case 5:
      set_cpu_read_flag(0);
      break;
    case 1:
      break;
    case 6:
      break;
    case 7:
      break;
    default:
      break;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<buffers_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    $0x1,%al
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x2d(%rbp)
jne    119a <buffers_loop+0x5a>
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
setl   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    11aa <buffers_loop+0x6a>
jmp    1272 <buffers_loop+0x132>
xor    %eax,%eax
call   1050 <get_buffer_rx_state@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x7,%rax
ja     1268 <buffers_loop+0x128>
mov    -0x38(%rbp),%rax
lea    0xe30(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    126d <buffers_loop+0x12d>
mov    $0x1,%edi
call   1060 <set_cpu_read_flag@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <get_buffer_rx_state@plt>
cmp    $0x3,%eax
je     120d <buffers_loop+0xcd>
jmp    11f8 <buffers_loop+0xb8>
jmp    126d <buffers_loop+0x12d>
mov    $0x0,%al
call   1030 <get_identifier@plt>
mov    %rax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
xor    %edi,%edi
call   1060 <set_cpu_read_flag@plt>
jmp    126d <buffers_loop+0x12d>
mov    -0x10(%rbp),%rdi
call   1040 <copy_to_buffer@plt>
mov    $0x1,%edi
call   1060 <set_cpu_read_flag@plt>
jmp    126d <buffers_loop+0x12d>
xor    %edi,%edi
call   1060 <set_cpu_read_flag@plt>
jmp    126d <buffers_loop+0x12d>
jmp    126d <buffers_loop+0x12d>
jmp    126d <buffers_loop+0x12d>
jmp    126d <buffers_loop+0x12d>
jmp    126d <buffers_loop+0x12d>
jmp    117c <buffers_loop+0x3c>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffers_loop>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
js     11e4 <buffers_loop+0xa4>
mov    %rdi,%rbx
lea    0xea4(%rip),%r15
xor    %r14d,%r14d
xor    %r13d,%r13d
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1050 <get_buffer_rx_state@plt>
cmp    $0x5,%eax
ja     11af <buffers_loop+0x6f>
mov    %eax,%eax
movslq (%r15,%rax,4),%rax
add    %r15,%rax
jmp    *%rax
mov    $0x1,%edi
call   1060 <set_cpu_read_flag@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <get_buffer_rx_state@plt>
cmp    $0x3,%eax
jne    11a0 <buffers_loop+0x60>
mov    %r12,%r13
test   %rbx,%rbx
jne    11df <buffers_loop+0x9f>
jmp    1170 <buffers_loop+0x30>
xor    %eax,%eax
call   1030 <get_identifier@plt>
mov    %rax,%r14
add    $0x1,%r12
xor    %edi,%edi
jmp    11d5 <buffers_loop+0x95>
mov    %r14,%rdi
call   1040 <copy_to_buffer@plt>
mov    $0x1,%edi
call   1060 <set_cpu_read_flag@plt>
test   %rbx,%rbx
je     1170 <buffers_loop+0x30>
cmp    %rbx,%r13
jl     1170 <buffers_loop+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @buffers_loop(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
store i64 %0, i64* %2
store i64 0, i64* %3
store i64 0, i64* %4
store i64 0, i64* %5
%8 = load i64, i64* %2
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i64
%11 = select i1 %9, i32 1, i32 0
%12 = sext i32 %11 to i64
store i64 %12, i64* %6
br label %13
13: ; preds = %50, %1
%14 = load i64, i64* %6
%15 = icmp ne i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i64, i64* %4
%18 = load i64, i64* %2
%19 = icmp slt i64 %17, %18
br label %20
20: ; preds = %16, %13
%21 = phi i1 [ true, %13 ], [ %19, %16 ]
br i1 %21, label %22, label %51
22: ; preds = %20
%23 = call i32 (...) @get_buffer_rx_state()
store i32 %23, i32* %7
%24 = load i32, i32* %7
switch i32 %24, label %49 [
i32 0, label %25
i32 2, label %27
i32 3, label %35
i32 4, label %40
i32 5, label %44
i32 1, label %46
i32 6, label %47
i32 7, label %48
]
25: ; preds = %22
%26 = load i64, i64* %5
store i64 %26, i64* %4
br label %50
27: ; preds = %22
%28 = call i32 @set_cpu_read_flag(i32 1)
%29 = load i64, i64* %5
store i64 %29, i64* %4
br label %30
30: ; preds = %33, %27
%31 = call i32 (...) @get_buffer_rx_state()
%32 = icmp ne i32 %31, 3
br i1 %32, label %33, label %34
33: ; preds = %30
br label %30
34: ; preds = %30
br label %50
35: ; preds = %22
%36 = call i64 (...) @get_identifier()
store i64 %36, i64* %3
%37 = load i64, i64* %5
%38 = add nsw i64 %37, 1
store i64 %38, i64* %5
%39 = call i32 @set_cpu_read_flag(i32 0)
br label %50
40: ; preds = %22
%41 = load i64, i64* %3
%42 = call i32 @copy_to_buffer(i64 %41)
%43 = call i32 @set_cpu_read_flag(i32 1)
br label %50
44: ; preds = %22
%45 = call i32 @set_cpu_read_flag(i32 0)
br label %50
46: ; preds = %22
br label %50
47: ; preds = %22
br label %50
48: ; preds = %22
br label %50
49: ; preds = %22
br label %50
50: ; preds = %49, %48, %47, %46, %44, %40, %35, %34, %25
br label %13
51: ; preds = %20
ret i64 0
}

LLVM IR (-O2):
define i64 @buffers_loop(i64 %0) {
%2 = icmp eq i64 %0, 0
%3 = icmp sgt i64 %0, -1
br i1 %3, label %4, label %30
4: ; preds = %1, %24
%5 = phi i64 [ %27, %24 ], [ 0, %1 ]
%6 = phi i64 [ %26, %24 ], [ 0, %1 ]
%7 = phi i64 [ %25, %24 ], [ 0, %1 ]
%8 = tail call i32 (...) @get_buffer_rx_state()
switch i32 %8, label %24 [
i32 0, label %9
i32 2, label %10
i32 3, label %15
i32 4, label %19
i32 5, label %22
]
9: ; preds = %4
br label %24
10: ; preds = %4
%11 = tail call i32 @set_cpu_read_flag(i32 1)
br label %12
12: ; preds = %12, %10
%13 = tail call i32 (...) @get_buffer_rx_state()
%14 = icmp eq i32 %13, 3
br i1 %14, label %24, label %12
15: ; preds = %4
%16 = tail call i64 (...) @get_identifier()
%17 = add nsw i64 %7, 1
%18 = tail call i32 @set_cpu_read_flag(i32 0)
br label %24
19: ; preds = %4
%20 = tail call i32 @copy_to_buffer(i64 %5)
%21 = tail call i32 @set_cpu_read_flag(i32 1)
br label %24
22: ; preds = %4
%23 = tail call i32 @set_cpu_read_flag(i32 0)
br label %24
24: ; preds = %12, %4, %22, %19, %15, %9
%25 = phi i64 [ %7, %4 ], [ %7, %22 ], [ %7, %19 ], [ %17, %15 ], [ %7, %9 ], [ %7, %12 ]
%26 = phi i64 [ %6, %4 ], [ %6, %22 ], [ %6, %19 ], [ %6, %15 ], [ %7, %9 ], [ %7, %12 ]
%27 = phi i64 [ %5, %4 ], [ %5, %22 ], [ %5, %19 ], [ %16, %15 ], [ %5, %9 ], [ %5, %12 ]
%28 = icmp slt i64 %26, %0
%29 = select i1 %2, i1 true, i1 %28
br i1 %29, label %4, label %30
30: ; preds = %24, %1
ret i64 0
}