#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 */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ errno;
int /*<<< orphan*/ error(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, char, char);
int read(int, char *, int);
int read_verify_pkt(int fdr, char payload_char) {
  char buf[100];
  int ret;
  ret = read(fdr, buf, sizeof(buf));
  if (ret != sizeof(buf))
    error(1, errno, "read");
  if (buf[60] != payload_char) {
    printf("wrong pattern: 0x%x != 0x%x\n", buf[60], payload_char);
    return 1;
  }
  printf("read: %c (0x%x)\n", buf[60], buf[60]);
  return 0;
}


x86 assembly (clang, -O0):
<read_verify_pkt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %sil,%al
mov    %edi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x64,%edx
call   1040 <read@plt>
mov    %eax,-0x74(%rbp)
movslq -0x74(%rbp),%rax
cmp    $0x64,%rax
je     1180 <read_verify_pkt+0x50>
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xe85(%rip),%rdx
call   1050 <error@plt>
movsbl -0x34(%rbp),%eax
movsbl -0x9(%rbp),%ecx
cmp    %ecx,%eax
je     11b2 <read_verify_pkt+0x82>
mov    -0x34(%rbp),%al
lea    0xe6b(%rip),%rdi
movsbl %al,%esi
movsbl -0x9(%rbp),%edx
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11cf <read_verify_pkt+0x9f>
mov    -0x34(%rbp),%al
lea    0xe66(%rip),%rdi
movsbl %al,%esi
movsbl -0x34(%rbp),%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_verify_pkt>:
push   %rbx
sub    $0x70,%rsp
mov    %esi,%ebx
mov    %rsp,%rsi
mov    $0x64,%edx
call   1040 <read@plt>
cmp    $0x64,%eax
je     1163 <read_verify_pkt+0x33>
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdx
mov    $0x1,%edi
call   1050 <error@plt>
mov    0x3c(%rsp),%al
cmp    %bl,%al
jne    1180 <read_verify_pkt+0x50>
movsbl %bl,%edx
lea    0xead(%rip),%rdi
mov    %edx,%esi
call   1030 <printf@plt>
xor    %eax,%eax
jmp    1197 <read_verify_pkt+0x67>
movsbl %al,%esi
movsbl %bl,%edx
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [5 x i8] c"read\00"
@.str.1 = [29 x i8] c"wrong pattern: 0x%x != 0x%x\0A\00"
@.str.2 = [17 x i8] c"read: %c (0x%x)\0A\00"
define i32 @read_verify_pkt(i32 %0, i8 signext %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8
%6 = alloca [100 x i8]
%7 = alloca i32
store i32 %0, i32* %4
store i8 %1, i8* %5
%8 = load i32, i32* %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%10 = call i32 @read(i32 %8, i8* %9, i32 100)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = sext i32 %11 to i64
%13 = icmp ne i64 %12, 100
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load i32, i32* @errno
%16 = call i32 @error(i32 1, i32 %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %14, %2
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 60
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = load i8, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %20, %22
br i1 %23, label %24, label %29
24: ; preds = %17
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 60
%26 = load i8, i8* %25
%27 = load i8, i8* %5
%28 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8 signext %26, i8 signext %27)
store i32 1, i32* %3
br label %35
29: ; preds = %17
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 60
%31 = load i8, i8* %30
%32 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 60
%33 = load i8, i8* %32
%34 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext %31, i8 signext %33)
store i32 0, i32* %3
br label %35
35: ; preds = %29, %24
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [5 x i8] c"read\00"
@.str.1 = [29 x i8] c"wrong pattern: 0x%x != 0x%x\0A\00"
@.str.2 = [17 x i8] c"read: %c (0x%x)\0A\00"
define i32 @read_verify_pkt(i32 %0, i8 signext %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 %0, i8* %4, i32 100)
%6 = icmp eq i32 %5, 100
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = load i32, i32* @errno
%9 = tail call i32 @error(i32 1, i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %2
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 60
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, %1
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8 signext %12, i8 signext %1)
br label %18
16: ; preds = %10
%17 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8 signext %1, i8 signext %1)
br label %18
18: ; preds = %16, %14
%19 = phi i32 [ 1, %14 ], [ 0, %16 ]
ret i32 %19
}