#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 scalar_t__ int32_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, scalar_t__,
                           scalar_t__);
int read(int, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ swap4(char *, int);
char tolower(char);
int read_param(int fd, char *par, char *partyp, int *size, int swap) {
  int n;
  int32_t rl1, rl2;
  n = read(fd, &rl1, 4);
  if (n == 0)
    return -1;
  if (swap)
    swap4((char *)&rl1, 1);
  n = read(fd, par, 25);
  for (n = 0; n < 25; n++)
    par[n] = tolower(par[n]);
  n = read(fd, partyp, 1);
  n = read(fd, size, 4);
  if (swap)
    swap4((char *)size, 1);
  n = read(fd, &rl2, 4);
  if (swap)
    swap4((char *)&rl2, 1);
  if (rl1 != rl2) {
    fprintf(stderr, "Error reading parameter header (%d %d %d)\n", *size, rl1,
            rl2);
    return -2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<read_param>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1187 <read_param+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    12a8 <read_param+0x168>
cmpl   $0x0,-0x24(%rbp)
je     119f <read_param+0x5f>
lea    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1060 <swap4@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x19,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
cmpl   $0x19,-0x28(%rbp)
jge    11f2 <read_param+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <tolower@plt>
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11bc <read_param+0x7c>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1236 <read_param+0xf6>
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
call   1060 <swap4@plt>
mov    -0x8(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
mov    $0x0,%al
call   1030 <read@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1264 <read_param+0x124>
lea    -0x38(%rbp),%rdi
mov    $0x1,%esi
call   1060 <swap4@plt>
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
je     12a1 <read_param+0x161>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
lea    0xd70(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    12a8 <read_param+0x168>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_param>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,%r12d
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %edi,%r13d
lea    0x10(%rsp),%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
test   %eax,%eax
je     1212 <read_param+0xd2>
test   %r12d,%r12d
je     118a <read_param+0x4a>
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
call   1060 <swap4@plt>
xor    %ebp,%ebp
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x19,%edx
xor    %eax,%eax
call   1030 <read@plt>
xchg   %ax,%ax
movsbl (%rbx,%rbp,1),%edi
call   1050 <tolower@plt>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
cmp    $0x19,%rbp
jne    11a0 <read_param+0x60>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
test   %r12d,%r12d
je     1219 <read_param+0xd9>
mov    %r14,%rdi
mov    $0x1,%esi
call   1060 <swap4@plt>
lea    0x8(%rsp),%rbx
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1060 <swap4@plt>
jmp    122d <read_param+0xed>
mov    $0xffffffff,%eax
jmp    125b <read_param+0x11b>
lea    0x8(%rsp),%rsi
mov    %r13d,%edi
mov    $0x4,%edx
xor    %eax,%eax
call   1030 <read@plt>
mov    0x10(%rsp),%rcx
mov    0x8(%rsp),%r8
xor    %eax,%eax
cmp    %r8,%rcx
je     125b <read_param+0x11b>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%edx
lea    0xdaf(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xfffffffe,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [43 x i8] c"Error reading parameter header (%d %d %d)\0A\00"
define i32 @read_param(i32 %0, i8* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i64
store i32 %0, i32* %7
store i8* %1, i8** %8
store i8* %2, i8** %9
store i32* %3, i32** %10
store i32 %4, i32* %11
%15 = load i32, i32* %7
%16 = call i32 (i32, ...) @read(i32 %15, i64* %13, i32 4)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %5
store i32 -1, i32* %6
br label %80
20: ; preds = %5
%21 = load i32, i32* %11
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = bitcast i64* %13 to i8*
%25 = call i32 @swap4(i8* %24, i32 1)
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %7
%28 = load i8*, i8** %8
%29 = call i32 (i32, ...) @read(i32 %27, i8* %28, i32 25)
store i32 %29, i32* %12
store i32 0, i32* %12
br label %30
30: ; preds = %44, %26
%31 = load i32, i32* %12
%32 = icmp slt i32 %31, 25
br i1 %32, label %33, label %47
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = load i32, i32* %12
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %34, i64 %36
%38 = load i8, i8* %37
%39 = call signext i8 @tolower(i8 signext %38)
%40 = load i8*, i8** %8
%41 = load i32, i32* %12
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
store i8 %39, i8* %43
br label %44
44: ; preds = %33
%45 = load i32, i32* %12
%46 = add nsw i32 %45, 1
store i32 %46, i32* %12
br label %30
47: ; preds = %30
%48 = load i32, i32* %7
%49 = load i8*, i8** %9
%50 = call i32 (i32, ...) @read(i32 %48, i8* %49, i32 1)
store i32 %50, i32* %12
%51 = load i32, i32* %7
%52 = load i32*, i32** %10
%53 = call i32 (i32, ...) @read(i32 %51, i32* %52, i32 4)
store i32 %53, i32* %12
%54 = load i32, i32* %11
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %47
%57 = load i32*, i32** %10
%58 = bitcast i32* %57 to i8*
%59 = call i32 @swap4(i8* %58, i32 1)
br label %60
60: ; preds = %56, %47
%61 = load i32, i32* %7
%62 = call i32 (i32, ...) @read(i32 %61, i64* %14, i32 4)
store i32 %62, i32* %12
%63 = load i32, i32* %11
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %68
65: ; preds = %60
%66 = bitcast i64* %14 to i8*
%67 = call i32 @swap4(i8* %66, i32 1)
br label %68
68: ; preds = %65, %60
%69 = load i64, i64* %13
%70 = load i64, i64* %14
%71 = icmp ne i64 %69, %70
br i1 %71, label %72, label %79
72: ; preds = %68
%73 = load i32, i32* @stderr
%74 = load i32*, i32** %10
%75 = load i32, i32* %74
%76 = load i64, i64* %13
%77 = load i64, i64* %14
%78 = call i32 @fprintf(i32 %73, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %75, i64 %76, i64 %77)
store i32 -2, i32* %6
br label %80
79: ; preds = %68
store i32 0, i32* %6
br label %80
80: ; preds = %79, %72, %19
%81 = load i32, i32* %6
ret i32 %81
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [43 x i8] c"Error reading parameter header (%d %d %d)\0A\00"
define i32 @read_param(i32 %0, i8* %1, i8* %2, i32* %3, i32 %4) {
%6 = alloca i64
%7 = alloca i64
%8 = bitcast i64* %6 to i8*
%9 = bitcast i64* %7 to i8*
%10 = call i32 (i32, ...) @read(i32 %0, i64* %6, i32 4)
%11 = icmp eq i32 %10, 0
br i1 %11, label %43, label %12
12: ; preds = %5
%13 = icmp eq i32 %4, 0
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = call i32 @swap4(i8* %8, i32 1)
br label %16
16: ; preds = %14, %12
%17 = call i32 (i32, ...) @read(i32 %0, i8* %1, i32 25)
br label %18
18: ; preds = %16, %18
%19 = phi i64 [ 0, %16 ], [ %23, %18 ]
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = load i8, i8* %20
%22 = call signext i8 @tolower(i8 signext %21)
store i8 %22, i8* %20
%23 = add nuw nsw i64 %19, 1
%24 = icmp eq i64 %23, 25
br i1 %24, label %25, label %18
25: ; preds = %18
%26 = call i32 (i32, ...) @read(i32 %0, i8* %2, i32 1)
%27 = call i32 (i32, ...) @read(i32 %0, i32* %3, i32 4)
br i1 %13, label %33, label %28
28: ; preds = %25
%29 = bitcast i32* %3 to i8*
%30 = call i32 @swap4(i8* %29, i32 1)
%31 = call i32 (i32, ...) @read(i32 %0, i64* %7, i32 4)
%32 = call i32 @swap4(i8* %9, i32 1)
br label %35
33: ; preds = %25
%34 = call i32 (i32, ...) @read(i32 %0, i64* %7, i32 4)
br label %35
35: ; preds = %33, %28
%36 = load i64, i64* %6
%37 = load i64, i64* %7
%38 = icmp eq i64 %36, %37
br i1 %38, label %43, label %39
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = load i32, i32* %3
%42 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i32 %41, i64 %36, i64 %37)
br label %43
43: ; preds = %35, %5, %39
%44 = phi i32 [ -2, %39 ], [ -1, %5 ], [ 0, %35 ]
ret i32 %44
}