#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 /*<<< orphan*/ memcmp(char *, char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
scalar_t__ tag_readblock(int, char *);
int /*<<< orphan*/ tag_write_sessionreg(int, int, int);
int /*<<< orphan*/ tag_writeblock(int, char *);
void tag_set_config(int fd_off, int fd_on, int lastndef, int watchdog) {
  char buf[16];
  char buf2[16];
  memcpy(buf2, buf, 16);
  int nc_reg = (fd_off << 4) + (fd_on << 2);
  if (tag_readblock(0x7A, buf)) {
    buf[0] = nc_reg;
    buf[1] = lastndef;
    buf[2] = 0xF8;
    buf[3] = watchdog & 0xFF;
    buf[4] = (watchdog >> 8) & 0xFF;
    buf[5] = 1;
    if (!memcmp(buf2, buf, 16)) {
      tag_writeblock(0x7A, buf);
    }
  }
  tag_write_sessionreg(0, 0xFF, nc_reg);
  tag_write_sessionreg(1, 0xFF, lastndef);
  tag_write_sessionreg(2, 0xFF, 0xF8);
  tag_write_sessionreg(3, 0xFF, watchdog & 0xFF);
  tag_write_sessionreg(4, 0xFF, (watchdog >> 8) & 0xFF);
  tag_write_sessionreg(5, 0xFF, 1);
}


x86 assembly (clang, -O0):
<tag_set_config>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%eax
shl    $0x4,%eax
mov    -0x8(%rbp),%ecx
shl    $0x2,%ecx
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
lea    -0x20(%rbp),%rsi
mov    $0x7a,%edi
call   1030 <tag_readblock@plt>
cmp    $0x0,%rax
je     11fa <tag_set_config+0xaa>
mov    -0x34(%rbp),%eax
mov    %al,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %al,-0x1f(%rbp)
movb   $0xf8,-0x1e(%rbp)
mov    -0x10(%rbp),%eax
and    $0xff,%eax
mov    %al,-0x1d(%rbp)
mov    -0x10(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x1c(%rbp)
movb   $0x1,-0x1b(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%eax
jne    11f5 <tag_set_config+0xa5>
lea    -0x20(%rbp),%rsi
mov    $0x7a,%edi
call   1070 <tag_writeblock@plt>
jmp    11fa <tag_set_config+0xaa>
mov    -0x34(%rbp),%edx
xor    %edi,%edi
mov    $0xff,%esi
call   1050 <tag_write_sessionreg@plt>
mov    -0xc(%rbp),%edx
mov    $0x1,%edi
mov    $0xff,%esi
call   1050 <tag_write_sessionreg@plt>
mov    $0x2,%edi
mov    $0xff,%esi
mov    $0xf8,%edx
call   1050 <tag_write_sessionreg@plt>
mov    -0x10(%rbp),%edx
and    $0xff,%edx
mov    $0x3,%edi
mov    $0xff,%esi
call   1050 <tag_write_sessionreg@plt>
mov    -0x10(%rbp),%edx
sar    $0x8,%edx
and    $0xff,%edx
mov    $0x4,%edi
mov    $0xff,%esi
call   1050 <tag_write_sessionreg@plt>
mov    $0x5,%edi
mov    $0xff,%esi
mov    $0x1,%edx
call   1050 <tag_write_sessionreg@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tag_set_config>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %ecx,%r15d
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%ebx
lea    0x10(%rsp),%rdi
mov    %rsp,%r12
mov    %r12,%rsi
mov    $0x10,%edx
call   1060 <memcpy@plt>
shl    $0x4,%ebx
lea    (%rbx,%rbp,4),%ebp
mov    $0x7a,%edi
mov    %r12,%rsi
call   1030 <tag_readblock@plt>
test   %rax,%rax
je     11da <tag_set_config+0x8a>
mov    %bpl,(%rsp)
mov    %r14b,0x1(%rsp)
movb   $0xf8,0x2(%rsp)
mov    %r15b,0x3(%rsp)
mov    %r15d,%ebx
shr    $0x8,%ebx
mov    %bl,0x4(%rsp)
movb   $0x1,0x5(%rsp)
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
mov    $0x10,%edx
call   1040 <memcmp@plt>
test   %eax,%eax
jne    11e0 <tag_set_config+0x90>
mov    %rsp,%rsi
mov    $0x7a,%edi
call   1070 <tag_writeblock@plt>
jmp    11e0 <tag_set_config+0x90>
mov    %r15d,%ebx
shr    $0x8,%ebx
xor    %edi,%edi
mov    $0xff,%esi
mov    %ebp,%edx
call   1050 <tag_write_sessionreg@plt>
mov    $0x1,%edi
mov    $0xff,%esi
mov    %r14d,%edx
call   1050 <tag_write_sessionreg@plt>
mov    $0x2,%edi
mov    $0xff,%esi
mov    $0xf8,%edx
call   1050 <tag_write_sessionreg@plt>
movzbl %r15b,%edx
mov    $0x3,%edi
mov    $0xff,%esi
call   1050 <tag_write_sessionreg@plt>
movzbl %bl,%edx
mov    $0x4,%edi
mov    $0xff,%esi
call   1050 <tag_write_sessionreg@plt>
mov    $0x5,%edi
mov    $0xff,%esi
mov    $0x1,%edx
call   1050 <tag_write_sessionreg@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @tag_set_config(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [16 x i8]
%10 = alloca [16 x i8]
%11 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%14 = call i32 @memcpy(i8* %12, i8* %13, i32 16)
%15 = load i32, i32* %5
%16 = shl i32 %15, 4
%17 = load i32, i32* %6
%18 = shl i32 %17, 2
%19 = add nsw i32 %16, %18
store i32 %19, i32* %11
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%21 = call i64 @tag_readblock(i32 122, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %49
23: ; preds = %4
%24 = load i32, i32* %11
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
store i8 %25, i8* %26
%27 = load i32, i32* %7
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 1
store i8 %28, i8* %29
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 2
store i8 -8, i8* %30
%31 = load i32, i32* %8
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 3
store i8 %33, i8* %34
%35 = load i32, i32* %8
%36 = ashr i32 %35, 8
%37 = and i32 %36, 255
%38 = trunc i32 %37 to i8
%39 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 4
store i8 %38, i8* %39
%40 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 5
store i8 1, i8* %40
%41 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%42 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%43 = call i32 @memcmp(i8* %41, i8* %42, i32 16)
%44 = icmp ne i32 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %23
%46 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%47 = call i32 @tag_writeblock(i32 122, i8* %46)
br label %48
48: ; preds = %45, %23
br label %49
49: ; preds = %48, %4
%50 = load i32, i32* %11
%51 = call i32 @tag_write_sessionreg(i32 0, i32 255, i32 %50)
%52 = load i32, i32* %7
%53 = call i32 @tag_write_sessionreg(i32 1, i32 255, i32 %52)
%54 = call i32 @tag_write_sessionreg(i32 2, i32 255, i32 248)
%55 = load i32, i32* %8
%56 = and i32 %55, 255
%57 = call i32 @tag_write_sessionreg(i32 3, i32 255, i32 %56)
%58 = load i32, i32* %8
%59 = ashr i32 %58, 8
%60 = and i32 %59, 255
%61 = call i32 @tag_write_sessionreg(i32 4, i32 255, i32 %60)
%62 = call i32 @tag_write_sessionreg(i32 5, i32 255, i32 1)
ret void
}

LLVM IR (-O2):
define void @tag_set_config(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca [16 x i8]
%6 = alloca [16 x i8]
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%9 = call i32 @memcpy(i8* %8, i8* %7, i32 16)
%10 = shl i32 %0, 4
%11 = shl i32 %1, 2
%12 = add nsw i32 %11, %10
%13 = call i64 @tag_readblock(i32 122, i8* %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = lshr i32 %3, 8
br label %32
17: ; preds = %4
%18 = trunc i32 %12 to i8
store i8 %18, i8* %7
%19 = trunc i32 %2 to i8
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 1
store i8 %19, i8* %20
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 2
store i8 -8, i8* %21
%22 = trunc i32 %3 to i8
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 3
store i8 %22, i8* %23
%24 = lshr i32 %3, 8
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 4
store i8 %25, i8* %26
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 5
store i8 1, i8* %27
%28 = call i32 @memcmp(i8* %8, i8* %7, i32 16)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %17
%31 = call i32 @tag_writeblock(i32 122, i8* %7)
br label %32
32: ; preds = %15, %17, %30
%33 = phi i32 [ %16, %15 ], [ %24, %17 ], [ %24, %30 ]
%34 = call i32 @tag_write_sessionreg(i32 0, i32 255, i32 %12)
%35 = call i32 @tag_write_sessionreg(i32 1, i32 255, i32 %2)
%36 = call i32 @tag_write_sessionreg(i32 2, i32 255, i32 248)
%37 = and i32 %3, 255
%38 = call i32 @tag_write_sessionreg(i32 3, i32 255, i32 %37)
%39 = and i32 %33, 255
%40 = call i32 @tag_write_sessionreg(i32 4, i32 255, i32 %39)
%41 = call i32 @tag_write_sessionreg(i32 5, i32 255, i32 1)
ret void
}