#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) {
  int nb;
  if (lire_data(buf, cx, 1) != 1)
    return '?';
  if (*buf == 'H') {
    nb = lire_data(buf + 1, cx, 5);
    return nb == 5 && strcmp(buf, "HELLO") == 0 ? 'H' : 'e';
  } else if (*buf == 'O') {
    nb = lire_data(buf + 1, cx, 2);
    return nb == 2 && strcmp(buf, "OK") == 0 ? 'O' : 'e';
  } else if (*buf == 'F') {
    nb = lire_data(buf + 1, cx, 3);
    return nb == 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    12aa <lire_PDU+0x18a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x48,%eax
jne    11c1 <lire_PDU+0xa1>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
mov    $0x5,%edx
call   1040 <lire_data@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x5,-0x18(%rbp)
mov    %al,-0x19(%rbp)
jne    11a6 <lire_PDU+0x86>
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
mov    $0x65,%eax
mov    $0x48,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    12aa <lire_PDU+0x18a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x4f,%eax
jne    122d <lire_PDU+0x10d>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
mov    $0x2,%edx
call   1040 <lire_data@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x2,-0x18(%rbp)
mov    %al,-0x1a(%rbp)
jne    1212 <lire_PDU+0xf2>
mov    -0x10(%rbp),%rdi
lea    0xe03(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1a(%rbp)
mov    -0x1a(%rbp),%dl
mov    $0x65,%eax
mov    $0x4f,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    12aa <lire_PDU+0x18a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x46,%eax
jne    1299 <lire_PDU+0x179>
mov    -0x10(%rbp),%rdi
add    $0x1,%rdi
mov    -0x14(%rbp),%esi
mov    $0x3,%edx
call   1040 <lire_data@plt>
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0x3,-0x18(%rbp)
mov    %al,-0x1b(%rbp)
jne    127e <lire_PDU+0x15e>
mov    -0x10(%rbp),%rdi
lea    0xd9a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
mov    %al,-0x1b(%rbp)
mov    -0x1b(%rbp),%dl
mov    $0x65,%eax
mov    $0x46,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    12aa <lire_PDU+0x18a>
jmp    129e <lire_PDU+0x17e>
jmp    12a3 <lire_PDU+0x183>
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
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = load i32, i32* %5
%9 = call i32 @lire_data(i8* %7, i32 %8, i32 1)
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 63, i32* %3
br label %75
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 72
br i1 %16, label %17, label %32
17: ; preds = %12
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = load i32, i32* %5
%21 = call i32 @lire_data(i8* %19, i32 %20, i32 5)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = icmp eq i32 %22, 5
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8*, i8** %4
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br label %28
28: ; preds = %24, %17
%29 = phi i1 [ false, %17 ], [ %27, %24 ]
%30 = zext i1 %29 to i64
%31 = select i1 %29, i32 72, i32 101
store i32 %31, i32* %3
br label %75
32: ; preds = %12
%33 = load i8*, i8** %4
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 79
br i1 %36, label %37, label %52
37: ; preds = %32
%38 = load i8*, i8** %4
%39 = getelementptr inbounds i8, i8* %38, i64 1
%40 = load i32, i32* %5
%41 = call i32 @lire_data(i8* %39, i32 %40, i32 2)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, 2
br i1 %43, label %44, label %48
44: ; preds = %37
%45 = load i8*, i8** %4
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br label %48
48: ; preds = %44, %37
%49 = phi i1 [ false, %37 ], [ %47, %44 ]
%50 = zext i1 %49 to i64
%51 = select i1 %49, i32 79, i32 101
store i32 %51, i32* %3
br label %75
52: ; preds = %32
%53 = load i8*, i8** %4
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 70
br i1 %56, label %57, label %72
57: ; preds = %52
%58 = load i8*, i8** %4
%59 = getelementptr inbounds i8, i8* %58, i64 1
%60 = load i32, i32* %5
%61 = call i32 @lire_data(i8* %59, i32 %60, i32 3)
store i32 %61, i32* %6
%62 = load i32, i32* %6
%63 = icmp eq i32 %62, 3
br i1 %63, label %64, label %68
64: ; preds = %57
%65 = load i8*, i8** %4
%66 = call i64 @strcmp(i8* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%67 = icmp eq i64 %66, 0
br label %68
68: ; preds = %64, %57
%69 = phi i1 [ false, %57 ], [ %67, %64 ]
%70 = zext i1 %69 to i64
%71 = select i1 %69, i32 70, i32 101
store i32 %71, i32* %3
br label %75
72: ; preds = %52
br label %73
73: ; preds = %72
br label %74
74: ; preds = %73
store i32 63, i32* %3
br label %75
75: ; preds = %74, %68, %48, %28, %11
%76 = load i32, i32* %3
ret i32 %76
}

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
}