#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*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ si2c_deinit();
int /*<<< orphan*/ si2c_init();
int /*<<< orphan*/ si2c_start();
int /*<<< orphan*/ si2c_stop();
int /*<<< orphan*/ si2c_tx_byte(short);
int sscanf(char *, char *, short *);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  char line[8];
  short int number;
  si2c_init();
  si2c_start();
  puts("ready");
  while (fgets(line, 8, stdin) != NULL) {
    if (sscanf(line, "%hi\n", &number) == 1) {
      if ((number >= 0) && (number <= 255)) {
        puts("tx");
        si2c_tx_byte(number);
      }
    }
    if (strcmp(line, "push\n") == 0) {
      puts("sig");
      si2c_stop();
    }
  }
  si2c_stop();
  si2c_deinit();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1040 <si2c_init@plt>
mov    $0x0,%al
call   10b0 <si2c_start@plt>
lea    0xe45(%rip),%rdi
call   1030 <puts@plt>
lea    -0x18(%rbp),%rdi
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    $0x8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1266 <main+0xd6>
lea    -0x18(%rbp),%rdi
lea    0xe1a(%rip),%rsi
lea    -0x1a(%rbp),%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1234 <main+0xa4>
movswl -0x1a(%rbp),%eax
cmp    $0x0,%eax
jl     122f <main+0x9f>
movswl -0x1a(%rbp),%eax
cmp    $0xff,%eax
jg     122f <main+0x9f>
lea    0xdea(%rip),%rdi
call   1030 <puts@plt>
movswl -0x1a(%rbp),%edi
call   1090 <si2c_tx_byte@plt>
jmp    1234 <main+0xa4>
lea    -0x18(%rbp),%rdi
lea    0xdcf(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    1261 <main+0xd1>
lea    0xdbf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x0,%al
call   10a0 <si2c_stop@plt>
jmp    11c0 <main+0x30>
mov    $0x0,%al
call   10a0 <si2c_stop@plt>
mov    $0x0,%al
call   1070 <si2c_deinit@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <si2c_init@plt>
xor    %eax,%eax
call   10b0 <si2c_start@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e29(%rip),%rbp
mov    0x0(%rbp),%edx
lea    0x10(%rsp),%rdi
mov    $0x8,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     126b <main+0xdb>
lea    0xe25(%rip),%r14
lea    0x10(%rsp),%rbx
lea    0xe(%rsp),%r15
lea    0xe19(%rip),%r12
lea    0xe15(%rip),%r13
jmp    1215 <main+0x85>
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x8,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     126b <main+0xdb>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1080 <sscanf@plt>
cmp    $0x1,%eax
jne    1246 <main+0xb6>
movzwl 0xe(%rsp),%eax
cmp    $0xff,%eax
ja     1246 <main+0xb6>
mov    %r12,%rdi
call   1030 <puts@plt>
movswl 0xe(%rsp),%edi
call   1090 <si2c_tx_byte@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    1200 <main+0x70>
lea    0xdb7(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <si2c_stop@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
call   10a0 <si2c_stop@plt>
xor    %eax,%eax
call   1070 <si2c_deinit@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"ready\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"%hi\0A\00"
@.str.2 = [3 x i8] c"tx\00"
@.str.3 = [6 x i8] c"push\0A\00"
@.str.4 = [4 x i8] c"sig\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32 (...) @si2c_init()
%9 = call i32 (...) @si2c_start()
%10 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %40, %2
%12 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%13 = load i32, i32* @stdin
%14 = call i32* @fgets(i8* %12, i32 8, i32 %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %41
16: ; preds = %11
%17 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%18 = call i32 @sscanf(i8* %17, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i16* %7)
%19 = icmp eq i32 %18, 1
br i1 %19, label %20, label %33
20: ; preds = %16
%21 = load i16, i16* %7
%22 = sext i16 %21 to i32
%23 = icmp sge i32 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %20
%25 = load i16, i16* %7
%26 = sext i16 %25 to i32
%27 = icmp sle i32 %26, 255
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = call i32 @puts(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = load i16, i16* %7
%31 = call i32 @si2c_tx_byte(i16 signext %30)
br label %32
32: ; preds = %28, %24, %20
br label %33
33: ; preds = %32, %16
%34 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = call i32 @puts(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%39 = call i32 (...) @si2c_stop()
br label %40
40: ; preds = %37, %33
br label %11
41: ; preds = %11
%42 = call i32 (...) @si2c_stop()
%43 = call i32 (...) @si2c_deinit()
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"ready\00"
@stdin = global i32 0
@.str.1 = [5 x i8] c"%hi\0A\00"
@.str.2 = [3 x i8] c"tx\00"
@.str.3 = [6 x i8] c"push\0A\00"
@.str.4 = [4 x i8] c"sig\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [8 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = bitcast i16* %4 to i8*
%7 = tail call i32 (...) @si2c_init()
%8 = tail call i32 (...) @si2c_start()
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %5, i32 8, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %33, label %13
13: ; preds = %2, %29
%14 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i16* %4)
%15 = icmp eq i32 %14, 1
%16 = load i16, i16* %4
%17 = icmp ult i16 %16, 256
%18 = select i1 %15, i1 %17, i1 false
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = load i16, i16* %4
%22 = call i32 @si2c_tx_byte(i16 signext %21)
br label %23
23: ; preds = %19, %13
%24 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%28 = call i32 (...) @si2c_stop()
br label %29
29: ; preds = %26, %23
%30 = load i32, i32* @stdin
%31 = call i32* @fgets(i8* %5, i32 8, i32 %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %13
33: ; preds = %29, %2
%34 = call i32 (...) @si2c_stop()
%35 = call i32 (...) @si2c_deinit()
ret i32 0
}