#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*/ B4800;
int /*<<< orphan*/ CS8;
scalar_t__ readchar(int, unsigned char *, int);
int /*<<< orphan*/ setline(int, int /*<<< orphan*/, int /*<<< orphan*/);
int write(int, char *, int);
int warrior_init(int fd) {
  unsigned char c;
  if (readchar(fd, &c, 2000) || c != 'J')
    return -1;
  while (c != ')' - 0x20)
    if (readchar(fd, &c, 1000))
      return -1;
  if (write(fd, "*S", 2) != 2)
    return -1;
  if (readchar(fd, &c, 1000) || c != '*' || readchar(fd, &c, 1000) || c != 'S')
    return -1;
  setline(fd, B4800, CS8);
  return 0;
}


x86 assembly (clang, -O0):
<warrior_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x7d0,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    1163 <warrior_init+0x33>
movzbl -0x9(%rbp),%eax
cmp    $0x4a,%eax
je     116f <warrior_init+0x3f>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <warrior_init+0x123>
jmp    1174 <warrior_init+0x44>
movzbl -0x9(%rbp),%eax
cmp    $0x9,%eax
je     11ad <warrior_init+0x7d>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
je     11a8 <warrior_init+0x78>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <warrior_init+0x123>
jmp    1174 <warrior_init+0x44>
mov    -0x8(%rbp),%edi
lea    0xe49(%rip),%rsi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
je     11d6 <warrior_init+0xa6>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <warrior_init+0x123>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    1226 <warrior_init+0xf6>
movzbl -0x9(%rbp),%eax
cmp    $0x2a,%eax
jne    1226 <warrior_init+0xf6>
mov    -0x8(%rbp),%edi
lea    -0x9(%rbp),%rsi
mov    $0x3e8,%edx
call   1030 <readchar@plt>
cmp    $0x0,%rax
jne    1226 <warrior_init+0xf6>
movzbl -0x9(%rbp),%eax
cmp    $0x53,%eax
je     1232 <warrior_init+0x102>
movl   $0xffffffff,-0x4(%rbp)
jmp    1253 <warrior_init+0x123>
mov    -0x8(%rbp),%edi
mov    0x2dac(%rip),%rax
mov    (%rax),%esi
mov    0x2d9b(%rip),%rax
mov    (%rax),%edx
call   1050 <setline@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<warrior_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xf(%rsp),%rsi
mov    $0x7d0,%edx
call   1030 <readchar@plt>
mov    $0xffffffff,%r14d
test   %rax,%rax
jne    11f9 <warrior_init+0xc9>
cmpb   $0x4a,0xf(%rsp)
jne    11f9 <warrior_init+0xc9>
lea    0xf(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    11f9 <warrior_init+0xc9>
cmpb   $0x9,0xf(%rsp)
jne    1170 <warrior_init+0x40>
lea    0xe6e(%rip),%rsi
mov    %ebp,%edi
mov    $0x2,%edx
call   1040 <write@plt>
cmp    $0x2,%eax
jne    11f9 <warrior_init+0xc9>
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3e8,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    11f9 <warrior_init+0xc9>
cmpb   $0x2a,0xf(%rsp)
jne    11f9 <warrior_init+0xc9>
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3e8,%edx
call   1030 <readchar@plt>
test   %rax,%rax
jne    11f9 <warrior_init+0xc9>
cmpb   $0x53,0xf(%rsp)
jne    11f9 <warrior_init+0xc9>
mov    0x2e04(%rip),%rax
mov    (%rax),%esi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <setline@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"*S\00"
@B4800 = global i32 0
@CS8 = global i32 0
define i32 @warrior_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i64 @readchar(i32 %5, i8* %4, i32 2000)
%7 = icmp ne i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load i8, i8* %4
%10 = zext i8 %9 to i32
%11 = icmp ne i32 %10, 74
br i1 %11, label %12, label %13
12: ; preds = %8, %1
store i32 -1, i32* %2
br label %51
13: ; preds = %8
br label %14
14: ; preds = %23, %13
%15 = load i8, i8* %4
%16 = zext i8 %15 to i32
%17 = icmp ne i32 %16, 9
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = load i32, i32* %3
%20 = call i64 @readchar(i32 %19, i8* %4, i32 1000)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 -1, i32* %2
br label %51
23: ; preds = %18
br label %14
24: ; preds = %14
%25 = load i32, i32* %3
%26 = call i32 @write(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%27 = icmp ne i32 %26, 2
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %2
br label %51
29: ; preds = %24
%30 = load i32, i32* %3
%31 = call i64 @readchar(i32 %30, i8* %4, i32 1000)
%32 = icmp ne i64 %31, 0
br i1 %32, label %45, label %33
33: ; preds = %29
%34 = load i8, i8* %4
%35 = zext i8 %34 to i32
%36 = icmp ne i32 %35, 42
br i1 %36, label %45, label %37
37: ; preds = %33
%38 = load i32, i32* %3
%39 = call i64 @readchar(i32 %38, i8* %4, i32 1000)
%40 = icmp ne i64 %39, 0
br i1 %40, label %45, label %41
41: ; preds = %37
%42 = load i8, i8* %4
%43 = zext i8 %42 to i32
%44 = icmp ne i32 %43, 83
br i1 %44, label %45, label %46
45: ; preds = %41, %37, %33, %29
store i32 -1, i32* %2
br label %51
46: ; preds = %41
%47 = load i32, i32* %3
%48 = load i32, i32* @B4800
%49 = load i32, i32* @CS8
%50 = call i32 @setline(i32 %47, i32 %48, i32 %49)
store i32 0, i32* %2
br label %51
51: ; preds = %46, %45, %28, %22, %12
%52 = load i32, i32* %2
ret i32 %52
}

LLVM IR (-O2):
@.str = [3 x i8] c"*S\00"
@B4800 = global i32 0
@CS8 = global i32 0
define i32 @warrior_init(i32 %0) {
%2 = alloca i8
%3 = call i64 @readchar(i32 %0, i8* %2, i32 2000)
%4 = icmp ne i64 %3, 0
%5 = load i8, i8* %2
%6 = icmp ne i8 %5, 74
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %33, label %11
8: ; preds = %11
%9 = load i8, i8* %2
%10 = icmp eq i8 %9, 9
br i1 %10, label %14, label %11
11: ; preds = %1, %8
%12 = call i64 @readchar(i32 %0, i8* %2, i32 1000)
%13 = icmp eq i64 %12, 0
br i1 %13, label %8, label %33
14: ; preds = %8
%15 = call i32 @write(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 2)
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %33
17: ; preds = %14
%18 = call i64 @readchar(i32 %0, i8* %2, i32 1000)
%19 = icmp ne i64 %18, 0
%20 = load i8, i8* %2
%21 = icmp ne i8 %20, 42
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %33, label %23
23: ; preds = %17
%24 = call i64 @readchar(i32 %0, i8* %2, i32 1000)
%25 = icmp ne i64 %24, 0
%26 = load i8, i8* %2
%27 = icmp ne i8 %26, 83
%28 = select i1 %25, i1 true, i1 %27
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load i32, i32* @B4800
%31 = load i32, i32* @CS8
%32 = call i32 @setline(i32 %0, i32 %30, i32 %31)
br label %33
33: ; preds = %11, %17, %23, %14, %1, %29
%34 = phi i32 [ 0, %29 ], [ -1, %1 ], [ -1, %14 ], [ -1, %23 ], [ -1, %17 ], [ -1, %11 ]
ret i32 %34
}