#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 */
struct trace_seq {
  int dummy;
};
typedef int /*<<< orphan*/ states;

/* Variables and functions */
int /*<<< orphan*/ trace_seq_putc(struct trace_seq *, char const);
void write_state(struct trace_seq *s, int val) {
  const char states[] = "SDTtZXxW";
  int found = 0;
  int i;
  for (i = 0; i < (sizeof(states) - 1); i++) {
    if (!(val & (1 << i))) {
      continue;
    }
    if (found) {
      trace_seq_putc(s, '|');
    }
    found = 1;
    trace_seq_putc(s, states[i]);
  }
  if (!found) {
    trace_seq_putc(s, 'R');
  }
}


x86 assembly (clang, -O0):
<write_state>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    0xeda(%rip),%rax
mov    %rax,-0x15(%rbp)
mov    0xed8(%rip),%al
mov    %al,-0xd(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movslq -0x20(%rbp),%rax
cmp    $0x8,%rax
jae    11ad <write_state+0x9d>
mov    -0xc(%rbp),%eax
mov    -0x20(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
jne    116e <write_state+0x5e>
jmp    119f <write_state+0x8f>
cmpl   $0x0,-0x1c(%rbp)
je     1186 <write_state+0x76>
mov    -0x8(%rbp),%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x20(%rbp),%rax
movsbl -0x15(%rbp,%rax,1),%esi
call   1030 <trace_seq_putc@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1141 <write_state+0x31>
cmpl   $0x0,-0x1c(%rbp)
jne    11c5 <write_state+0xb5>
mov    -0x8(%rbp),%rdi
mov    $0x52,%esi
call   1030 <trace_seq_putc@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_state>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
test   $0x1,%bpl
jne    116e <write_state+0x5e>
test   $0x2,%bpl
jne    11c9 <write_state+0xb9>
test   $0x4,%bpl
jne    11e9 <write_state+0xd9>
test   $0x8,%bpl
jne    1209 <write_state+0xf9>
test   $0x10,%bpl
jne    122d <write_state+0x11d>
test   $0x20,%bpl
jne    1251 <write_state+0x141>
test   $0x40,%bpl
jne    1275 <write_state+0x165>
xor    %eax,%eax
test   $0x80,%bpl
setne  %al
lea    (%rax,%rax,4),%eax
add    $0x52,%eax
jmp    129b <write_state+0x18b>
mov    %rbx,%rdi
mov    $0x53,%esi
call   1030 <trace_seq_putc@plt>
test   $0x2,%bpl
jne    11bc <write_state+0xac>
test   $0x4,%bpl
jne    11dc <write_state+0xcc>
test   $0x8,%bpl
jne    11fc <write_state+0xec>
test   $0x10,%bpl
jne    1220 <write_state+0x110>
test   $0x20,%bpl
jne    1244 <write_state+0x134>
test   $0x40,%bpl
jne    1268 <write_state+0x158>
test   $0x80,%bpl
jne    128c <write_state+0x17c>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    %rbx,%rdi
mov    $0x44,%esi
call   1030 <trace_seq_putc@plt>
test   $0x4,%bpl
je     1187 <write_state+0x77>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    %rbx,%rdi
mov    $0x54,%esi
call   1030 <trace_seq_putc@plt>
test   $0x8,%bpl
je     118d <write_state+0x7d>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    %rbx,%rdi
mov    $0x74,%esi
call   1030 <trace_seq_putc@plt>
test   $0x10,%bpl
je     1197 <write_state+0x87>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    %rbx,%rdi
mov    $0x5a,%esi
call   1030 <trace_seq_putc@plt>
test   $0x20,%bpl
je     11a1 <write_state+0x91>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    %rbx,%rdi
mov    $0x58,%esi
call   1030 <trace_seq_putc@plt>
test   $0x40,%bpl
je     11ab <write_state+0x9b>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    %rbx,%rdi
mov    $0x78,%esi
call   1030 <trace_seq_putc@plt>
test   $0x80,%bpl
je     11b5 <write_state+0xa5>
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1030 <trace_seq_putc@plt>
mov    $0x57,%al
movsbl %al,%esi
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <trace_seq_putc@plt>

LLVM IR (-O0):
%struct.trace_seq = type { i32 }
@__const.write_state.states = [9 x i8] c"SDTtZXxW\00"
define void @write_state(%struct.trace_seq* %0, i32 %1) {
%3 = alloca %struct.trace_seq*
%4 = alloca i32
%5 = alloca [9 x i8]
%6 = alloca i32
%7 = alloca i32
store %struct.trace_seq* %0, %struct.trace_seq** %3
store i32 %1, i32* %4
%8 = bitcast [9 x i8]* %5 to i8*
store i32 0, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %33, %2
%10 = load i32, i32* %7
%11 = sext i32 %10 to i64
%12 = icmp ult i64 %11, 8
br i1 %12, label %13, label %36
13: ; preds = %9
%14 = load i32, i32* %4
%15 = load i32, i32* %7
%16 = shl i32 1, %15
%17 = and i32 %14, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %20, label %19
19: ; preds = %13
br label %33
20: ; preds = %13
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load %struct.trace_seq*, %struct.trace_seq** %3
%25 = call i32 @trace_seq_putc(%struct.trace_seq* %24, i8 signext 124)
br label %26
26: ; preds = %23, %20
store i32 1, i32* %6
%27 = load %struct.trace_seq*, %struct.trace_seq** %3
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [9 x i8], [9 x i8]* %5, i64 0, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @trace_seq_putc(%struct.trace_seq* %27, i8 signext %31)
br label %33
33: ; preds = %26, %19
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
br label %9
36: ; preds = %9
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = load %struct.trace_seq*, %struct.trace_seq** %3
%41 = call i32 @trace_seq_putc(%struct.trace_seq* %40, i8 signext 82)
br label %42
42: ; preds = %39, %36
ret void
}

LLVM IR (-O2):
%struct.trace_seq = type { i32 }
define void @write_state(%struct.trace_seq* %0, i32 %1) {
%3 = and i32 %1, 1
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = and i32 %1, 2
%7 = icmp eq i32 %6, 0
br i1 %7, label %19, label %14
8: ; preds = %2
%9 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 83)
%10 = and i32 %1, 2
%11 = icmp eq i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8
%13 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %14
14: ; preds = %5, %12
%15 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 68)
br label %16
16: ; preds = %8, %14
%17 = and i32 %1, 4
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %22
19: ; preds = %5
%20 = and i32 %1, 4
%21 = icmp eq i32 %20, 0
br i1 %21, label %29, label %24
22: ; preds = %16
%23 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %24
24: ; preds = %19, %22
%25 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 84)
br label %26
26: ; preds = %24, %16
%27 = and i32 %1, 8
%28 = icmp eq i32 %27, 0
br i1 %28, label %36, label %32
29: ; preds = %19
%30 = and i32 %1, 8
%31 = icmp eq i32 %30, 0
br i1 %31, label %39, label %34
32: ; preds = %26
%33 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %34
34: ; preds = %29, %32
%35 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 116)
br label %36
36: ; preds = %34, %26
%37 = and i32 %1, 16
%38 = icmp eq i32 %37, 0
br i1 %38, label %46, label %42
39: ; preds = %29
%40 = and i32 %1, 16
%41 = icmp eq i32 %40, 0
br i1 %41, label %49, label %44
42: ; preds = %36
%43 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %44
44: ; preds = %39, %42
%45 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 90)
br label %46
46: ; preds = %44, %36
%47 = and i32 %1, 32
%48 = icmp eq i32 %47, 0
br i1 %48, label %56, label %52
49: ; preds = %39
%50 = and i32 %1, 32
%51 = icmp eq i32 %50, 0
br i1 %51, label %59, label %54
52: ; preds = %46
%53 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %54
54: ; preds = %49, %52
%55 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 88)
br label %56
56: ; preds = %54, %46
%57 = and i32 %1, 64
%58 = icmp eq i32 %57, 0
br i1 %58, label %66, label %62
59: ; preds = %49
%60 = and i32 %1, 64
%61 = icmp eq i32 %60, 0
br i1 %61, label %69, label %64
62: ; preds = %56
%63 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %64
64: ; preds = %59, %62
%65 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 120)
br label %66
66: ; preds = %64, %56
%67 = and i32 %1, 128
%68 = icmp eq i32 %67, 0
br i1 %68, label %78, label %73
69: ; preds = %59
%70 = and i32 %1, 128
%71 = icmp eq i32 %70, 0
%72 = select i1 %71, i8 82, i8 87
br label %75
73: ; preds = %66
%74 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext 124)
br label %75
75: ; preds = %69, %73
%76 = phi i8 [ 87, %73 ], [ %72, %69 ]
%77 = tail call i32 @trace_seq_putc(%struct.trace_seq* %0, i8 signext %76)
br label %78
78: ; preds = %75, %66
ret void
}