#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 lire_data(char *, int, int);
scalar_t__ strcmp(char *, char *);
int lire_PDU(char *buf, int cx) {
  if (lire_data(buf, cx, 1) != 1)
    return '?';
  if (*buf == 'H') {
    return lire_data(buf + 1, cx, 5) == 5 && strcmp(buf, "HELLO") == 0 ? 'H'
                                                                       : 'e';
  } else if (*buf == 'O') {
    return lire_data(buf + 1, cx, 2) == 2 && strcmp(buf, "OK") == 0 ? 'O' : 'e';
  } else if (*buf == 'F') {
    return lire_data(buf + 1, cx, 3) == 3 && strcmp(buf, "FIN") == 0 ? 'F'
                                                                     : 'e';
  }
  return '?';
}


x86 assembly (clang, -O0):
<lire_PDU>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <lire_data@plt>
cmp    $0x1,%eax
je     1155 <lire_PDU+0x35>
movl   $0x3f,-0x4(%rbp)
jmp    12a4 <lire_PDU+0x184>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x48,%eax
jne    11bf <lire_PDU+0x9f>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
mov    $0x5,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x5,%ecx
mov    %al,-0x15(%rbp)
jne    11a4 <lire_PDU+0x84>
mov    -0x10(%rbp),%rdi
lea    0xe6b(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%dl
mov    $0x65,%eax
mov    $0x48,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <lire_PDU+0x184>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4f,%eax
jne    1229 <lire_PDU+0x109>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x2,%ecx
mov    %al,-0x16(%rbp)
jne    120e <lire_PDU+0xee>
mov    -0x10(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x16(%rbp)
mov    -0x16(%rbp),%dl
mov    $0x65,%eax
mov    $0x4f,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <lire_PDU+0x184>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x46,%eax
jne    1293 <lire_PDU+0x173>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
mov    $0x3,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x3,%ecx
mov    %al,-0x17(%rbp)
jne    1278 <lire_PDU+0x158>
mov    -0x10(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x17(%rbp)
mov    -0x17(%rbp),%dl
mov    $0x65,%eax
mov    $0x46,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    12a4 <lire_PDU+0x184>
jmp    1298 <lire_PDU+0x178>
jmp    129d <lire_PDU+0x17d>
movl   $0x3f,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lire_PDU>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    $0x1,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
mov    $0x3f,%eax
cmp    $0x1,%ecx
jne    11e6 <lire_PDU+0xc6>
mov    (%rbx),%cl
cmp    $0x46,%cl
je     1181 <lire_PDU+0x61>
cmp    $0x4f,%cl
je     11ab <lire_PDU+0x8b>
cmp    $0x48,%cl
jne    11e6 <lire_PDU+0xc6>
lea    0x1(%rbx),%rdi
mov    %ebp,%esi
mov    $0x5,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
mov    $0x65,%eax
cmp    $0x5,%ecx
jne    11e6 <lire_PDU+0xc6>
mov    $0x48,%ebp
lea    0xe81(%rip),%rsi
jmp    11d3 <lire_PDU+0xb3>
lea    0x1(%rbx),%rdi
mov    %ebp,%esi
mov    $0x3,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
mov    $0x65,%eax
cmp    $0x3,%ecx
jne    11e6 <lire_PDU+0xc6>
mov    $0x46,%ebp
lea    0xe60(%rip),%rsi
jmp    11d3 <lire_PDU+0xb3>
lea    0x1(%rbx),%rdi
mov    %ebp,%esi
mov    $0x2,%edx
call   1040 <lire_data@plt>
mov    %eax,%ecx
mov    $0x65,%eax
cmp    $0x2,%ecx
jne    11e6 <lire_PDU+0xc6>
mov    $0x4f,%ebp
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcmp@plt>
test   %rax,%rax
mov    $0x65,%eax
cmove  %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"HELLO\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"FIN\00"
define i32 @lire_PDU(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%6 = load i8*, i8** %4
%7 = load i32, i32* %5
%8 = call i32 @lire_data(i8* %6, i32 %7, i32 1)
%9 = icmp ne i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 63, i32* %3
br label %71
11: ; preds = %2
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 72
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i32, i32* %5
%20 = call i32 @lire_data(i8* %18, i32 %19, i32 5)
%21 = icmp eq i32 %20, 5
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i8*, i8** %4
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br label %26
26: ; preds = %22, %16
%27 = phi i1 [ false, %16 ], [ %25, %22 ]
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 72, i32 101
store i32 %29, i32* %3
br label %71
30: ; preds = %11
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 79
br i1 %34, label %35, label %49
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i64 1
%38 = load i32, i32* %5
%39 = call i32 @lire_data(i8* %37, i32 %38, i32 2)
%40 = icmp eq i32 %39, 2
br i1 %40, label %41, label %45
41: ; preds = %35
%42 = load i8*, i8** %4
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br label %45
45: ; preds = %41, %35
%46 = phi i1 [ false, %35 ], [ %44, %41 ]
%47 = zext i1 %46 to i64
%48 = select i1 %46, i32 79, i32 101
store i32 %48, i32* %3
br label %71
49: ; preds = %30
%50 = load i8*, i8** %4
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 70
br i1 %53, label %54, label %68
54: ; preds = %49
%55 = load i8*, i8** %4
%56 = getelementptr inbounds i8, i8* %55, i64 1
%57 = load i32, i32* %5
%58 = call i32 @lire_data(i8* %56, i32 %57, i32 3)
%59 = icmp eq i32 %58, 3
br i1 %59, label %60, label %64
60: ; preds = %54
%61 = load i8*, i8** %4
%62 = call i64 @strcmp(i8* %61, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%63 = icmp eq i64 %62, 0
br label %64
64: ; preds = %60, %54
%65 = phi i1 [ false, %54 ], [ %63, %60 ]
%66 = zext i1 %65 to i64
%67 = select i1 %65, i32 70, i32 101
store i32 %67, i32* %3
br label %71
68: ; preds = %49
br label %69
69: ; preds = %68
br label %70
70: ; preds = %69
store i32 63, i32* %3
br label %71
71: ; preds = %70, %64, %45, %26, %10
%72 = load i32, i32* %3
ret i32 %72
}

LLVM IR (-O2):
@.str = [6 x i8] c"HELLO\00"
@.str.1 = [3 x i8] c"OK\00"
@.str.2 = [4 x i8] c"FIN\00"
define i32 @lire_PDU(i8* %0, i32 %1) {
%3 = tail call i32 @lire_data(i8* %0, i32 %1, i32 1)
%4 = icmp eq i32 %3, 1
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = load i8, i8* %0
switch i8 %6, label %25 [
i8 72, label %7
i8 79, label %11
i8 70, label %15
]
7: ; preds = %5
%8 = getelementptr inbounds i8, i8* %0, i64 1
%9 = tail call i32 @lire_data(i8* %8, i32 %1, i32 5)
%10 = icmp eq i32 %9, 5
br i1 %10, label %19, label %25
11: ; preds = %5
%12 = getelementptr inbounds i8, i8* %0, i64 1
%13 = tail call i32 @lire_data(i8* %12, i32 %1, i32 2)
%14 = icmp eq i32 %13, 2
br i1 %14, label %19, label %25
15: ; preds = %5
%16 = getelementptr inbounds i8, i8* %0, i64 1
%17 = tail call i32 @lire_data(i8* %16, i32 %1, i32 3)
%18 = icmp eq i32 %17, 3
br i1 %18, label %19, label %25
19: ; preds = %15, %11, %7
%20 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), %7 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %11 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %15 ]
%21 = phi i32 [ 72, %7 ], [ 79, %11 ], [ 70, %15 ]
%22 = tail call i64 @strcmp(i8* %0, i8* %20)
%23 = icmp eq i64 %22, 0
%24 = select i1 %23, i32 %21, i32 101
br label %25
25: ; preds = %19, %5, %15, %11, %7, %2
%26 = phi i32 [ 63, %2 ], [ 101, %7 ], [ 101, %11 ], [ 101, %15 ], [ 63, %5 ], [ %24, %19 ]
ret i32 %26
}