#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*/ uint8_t;
struct gc_atom {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ fail(char *);
int /*<<< orphan*/ mark_gc_atom(struct gc_atom *);
void read_atom_spec(struct gc_atom *atom, const uint8_t *spec) {
  size_t n = *spec++;
  if (!n)
    return;
  if (n > 20)
    fail("Suspicious field count");
  do {
  } while (0);
  do {
  } while (0);
  char *atom_bytes = (char *)atom;
  for (size_t i = 0; i < n; i++) {
    size_t offset = *spec++;
    struct gc_atom **ref = (struct gc_atom **)&atom_bytes[offset];
    struct gc_atom *ref_atom = *ref;
    if (ref_atom)
      mark_gc_atom(ref_atom);
  }
}


x86 assembly (clang, -O0):
<read_atom_spec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movslq (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1156 <read_atom_spec+0x36>
jmp    11f6 <read_atom_spec+0xd6>
cmpq   $0x14,-0x18(%rbp)
jbe    116d <read_atom_spec+0x4d>
lea    0xe98(%rip),%rdi
call   1030 <fail@plt>
jmp    1172 <read_atom_spec+0x52>
jmp    1177 <read_atom_spec+0x57>
jmp    117c <read_atom_spec+0x5c>
jmp    1181 <read_atom_spec+0x61>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    11f6 <read_atom_spec+0xd6>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x10(%rbp)
movslq (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     11e0 <read_atom_spec+0xc0>
mov    -0x40(%rbp),%rdi
call   1040 <mark_gc_atom@plt>
jmp    11e5 <read_atom_spec+0xc5>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1191 <read_atom_spec+0x71>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_atom_spec>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movslq (%rsi),%r12
test   %r12,%r12
je     116e <read_atom_spec+0x4e>
mov    %rsi,%r15
mov    %rdi,%r14
cmp    $0x15,%r12d
jb     1148 <read_atom_spec+0x28>
lea    0xebd(%rip),%rdi
call   1030 <fail@plt>
xor    %ebx,%ebx
jmp    1159 <read_atom_spec+0x39>
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r12
je     116e <read_atom_spec+0x4e>
movslq 0x4(%r15,%rbx,4),%rax
mov    (%r14,%rax,1),%rdi
test   %rdi,%rdi
je     1150 <read_atom_spec+0x30>
call   1040 <mark_gc_atom@plt>
jmp    1150 <read_atom_spec+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.gc_atom = type { i32 }
@.str = [23 x i8] c"Suspicious field count\00"
define void @read_atom_spec(%struct.gc_atom* %0, i32* %1) {
%3 = alloca %struct.gc_atom*
%4 = alloca i32*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca %struct.gc_atom**
%10 = alloca %struct.gc_atom*
store %struct.gc_atom* %0, %struct.gc_atom** %3
store i32* %1, i32** %4
%11 = load i32*, i32** %4
%12 = getelementptr inbounds i32, i32* %11, i32 1
store i32* %12, i32** %4
%13 = load i32, i32* %11
%14 = sext i32 %13 to i64
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = icmp ne i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %2
br label %54
18: ; preds = %2
%19 = load i64, i64* %5
%20 = icmp ugt i64 %19, 20
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @fail(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %18
br label %24
24: ; preds = %23
br label %25
25: ; preds = %24
br label %26
26: ; preds = %25
br label %27
27: ; preds = %26
%28 = load %struct.gc_atom*, %struct.gc_atom** %3
%29 = bitcast %struct.gc_atom* %28 to i8*
store i8* %29, i8** %6
store i64 0, i64* %7
br label %30
30: ; preds = %51, %27
%31 = load i64, i64* %7
%32 = load i64, i64* %5
%33 = icmp ult i64 %31, %32
br i1 %33, label %34, label %54
34: ; preds = %30
%35 = load i32*, i32** %4
%36 = getelementptr inbounds i32, i32* %35, i32 1
store i32* %36, i32** %4
%37 = load i32, i32* %35
%38 = sext i32 %37 to i64
store i64 %38, i64* %8
%39 = load i8*, i8** %6
%40 = load i64, i64* %8
%41 = getelementptr inbounds i8, i8* %39, i64 %40
%42 = bitcast i8* %41 to %struct.gc_atom**
store %struct.gc_atom** %42, %struct.gc_atom*** %9
%43 = load %struct.gc_atom**, %struct.gc_atom*** %9
%44 = load %struct.gc_atom*, %struct.gc_atom** %43
store %struct.gc_atom* %44, %struct.gc_atom** %10
%45 = load %struct.gc_atom*, %struct.gc_atom** %10
%46 = icmp ne %struct.gc_atom* %45, null
br i1 %46, label %47, label %50
47: ; preds = %34
%48 = load %struct.gc_atom*, %struct.gc_atom** %10
%49 = call i32 @mark_gc_atom(%struct.gc_atom* %48)
br label %50
50: ; preds = %47, %34
br label %51
51: ; preds = %50
%52 = load i64, i64* %7
%53 = add i64 %52, 1
store i64 %53, i64* %7
br label %30
54: ; preds = %17, %30
ret void
}

LLVM IR (-O2):
%struct.gc_atom = type { i32 }
@.str = [23 x i8] c"Suspicious field count\00"
define void @read_atom_spec(%struct.gc_atom* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = icmp eq i32 %3, 0
br i1 %4, label %27, label %5
5: ; preds = %2
%6 = icmp ugt i32 %3, 20
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call i32 @fail(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %5, %7
%10 = bitcast %struct.gc_atom* %0 to i8*
%11 = sext i32 %3 to i64
br label %12
12: ; preds = %9, %24
%13 = phi i32* [ %15, %24 ], [ %1, %9 ]
%14 = phi i64 [ %25, %24 ], [ 0, %9 ]
%15 = getelementptr inbounds i32, i32* %13, i64 1
%16 = load i32, i32* %15
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %10, i64 %17
%19 = bitcast i8* %18 to %struct.gc_atom**
%20 = load %struct.gc_atom*, %struct.gc_atom** %19
%21 = icmp eq %struct.gc_atom* %20, null
br i1 %21, label %24, label %22
22: ; preds = %12
%23 = tail call i32 @mark_gc_atom(%struct.gc_atom* %20)
br label %24
24: ; preds = %22, %12
%25 = add nuw i64 %14, 1
%26 = icmp eq i64 %25, %11
br i1 %26, label %27, label %12
27: ; preds = %24, %2
ret void
}