#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 */
scalar_t__ cmdcmp(int *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ writeport(int, char *);
int cmd_init(int fd, int *f) {
  int s0[] = {' ', ' ', ' ', ' ', ' ', ' ', ' '};
  int s1[] = {'#', '#', 'B', '1', '0', '1', '#'};
  printf("Init cmd detected: '");
  int i = 0;
  while (f[i] != 0) {
    printf("%c", f[i++]);
  }
  printf("'\n");
  if (cmdcmp(f, s0, 7) == 0) {
    ;
  } else if (cmdcmp(f, s1, 7) == 0) {
    writeport(fd, "*#2,101,0,19200,N,8,1#*");
  } else {
    printf("> Unknown Init cmd\n");
  }
}


x86 assembly (clang, -O0):
<cmd_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xeba(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb7(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xeb2(%rip),%eax
mov    %eax,-0x18(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0xead(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea8(%rip),%eax
mov    %eax,-0x38(%rbp)
lea    0xea2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x54(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x54(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
je     11e2 <cmd_init+0xb2>
mov    -0x10(%rbp),%rax
mov    -0x54(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x54(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a8 <cmd_init+0x78>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x7,%edx
call   1050 <cmdcmp@plt>
cmp    $0x0,%rax
jne    1211 <cmd_init+0xe1>
jmp    1254 <cmd_init+0x124>
mov    -0x10(%rbp),%rdi
lea    -0x50(%rbp),%rsi
mov    $0x7,%edx
call   1050 <cmdcmp@plt>
cmp    $0x0,%rax
jne    1241 <cmd_init+0x111>
mov    -0x8(%rbp),%edi
lea    0xe20(%rip),%rsi
call   1030 <writeport@plt>
jmp    124f <cmd_init+0x11f>
lea    0xe27(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1254 <cmd_init+0x124>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmd_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x40,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
movups 0xea7(%rip),%xmm0
movups %xmm0,0x2c(%rsp)
movaps 0xe8f(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xeaf(%rip),%xmm0
movups %xmm0,0xc(%rsp)
movaps 0xe97(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xea8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%edi
test   %edi,%edi
je     11c0 <cmd_init+0x70>
lea    0x4(%rbx),%rbp
cs nopw 0x0(%rax,%rax,1)
nop
call   1030 <putchar@plt>
mov    0x0(%rbp),%edi
add    $0x4,%rbp
test   %edi,%edi
jne    11b0 <cmd_init+0x60>
lea    0xe88(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1070 <cmdcmp@plt>
test   %rax,%rax
je     1215 <cmd_init+0xc5>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x7,%edx
call   1070 <cmdcmp@plt>
test   %rax,%rax
je     1206 <cmd_init+0xb6>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
jmp    1215 <cmd_init+0xc5>
lea    0xe44(%rip),%rsi
mov    %r14d,%edi
call   1050 <writeport@plt>
add    $0x40,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.cmd_init.s0 = [7 x i32] [i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32]
@__const.cmd_init.s1 = [7 x i32] [i32 35, i32 35, i32 66, i32 49, i32 48, i32 49, i32 35]
@.str = [21 x i8] c"Init cmd detected: '\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [3 x i8] c"'\0A\00"
@.str.3 = [24 x i8] c"*,101,0,19200,N,8,1#*\00"
@.str.4 = [20 x i8] c"> Unknown Init cmd\0A\00"
define i32 @cmd_init(i32 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [7 x i32]
%7 = alloca [7 x i32]
%8 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
%9 = bitcast [7 x i32]* %6 to i8*
%10 = bitcast [7 x i32]* %7 to i8*
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %8
br label %12
12: ; preds = %19, %2
%13 = load i32*, i32** %5
%14 = load i32, i32* %8
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = load i32*, i32** %5
%21 = load i32, i32* %8
%22 = add nsw i32 %21, 1
store i32 %22, i32* %8
%23 = sext i32 %21 to i64
%24 = getelementptr inbounds i32, i32* %20, i64 %23
%25 = load i32, i32* %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %12
27: ; preds = %12
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32*, i32** %5
%30 = getelementptr inbounds [7 x i32], [7 x i32]* %6, i64 0, i64 0
%31 = call i64 @cmdcmp(i32* %29, i32* %30, i32 7)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %27
br label %45
34: ; preds = %27
%35 = load i32*, i32** %5
%36 = getelementptr inbounds [7 x i32], [7 x i32]* %7, i64 0, i64 0
%37 = call i64 @cmdcmp(i32* %35, i32* %36, i32 7)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %34
%40 = load i32, i32* %4
%41 = call i32 @writeport(i32 %40, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %44
42: ; preds = %34
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
br label %45
45: ; preds = %44, %33
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@__const.cmd_init.s0 = [7 x i32] [i32 32, i32 32, i32 32, i32 32, i32 32, i32 32, i32 32]
@__const.cmd_init.s1 = [7 x i32] [i32 35, i32 35, i32 66, i32 49, i32 48, i32 49, i32 35]
@.str = [21 x i8] c"Init cmd detected: '\00"
@.str.3 = [24 x i8] c"*,101,0,19200,N,8,1#*\00"
@str = [2 x i8] c"'\00"
@str.5 = [19 x i8] c"> Unknown Init cmd\00"
define i32 @cmd_init(i32 %0, i32* %1) {
%3 = alloca [7 x i32]
%4 = alloca [7 x i32]
%5 = bitcast [7 x i32]* %3 to i8*
%6 = bitcast [7 x i32]* %4 to i8*
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %18, label %10
10: ; preds = %2, %10
%11 = phi i64 [ %13, %10 ], [ 0, %2 ]
%12 = phi i32 [ %16, %10 ], [ %8, %2 ]
%13 = add nuw i64 %11, 1
%14 = tail call i32 @putchar(i32 %12)
%15 = getelementptr inbounds i32, i32* %1, i64 %13
%16 = load i32, i32* %15
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %10
18: ; preds = %10, %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%20 = getelementptr inbounds [7 x i32], [7 x i32]* %3, i64 0, i64 0
%21 = call i64 @cmdcmp(i32* %1, i32* %20, i32 7)
%22 = icmp eq i64 %21, 0
br i1 %22, label %31, label %23
23: ; preds = %18
%24 = getelementptr inbounds [7 x i32], [7 x i32]* %4, i64 0, i64 0
%25 = call i64 @cmdcmp(i32* %1, i32* %24, i32 7)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @writeport(i32 %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
br label %31
29: ; preds = %23
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
br label %31
31: ; preds = %27, %29, %18
ret i32 undef
}