#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*/ SEEK_SET;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ lseek(int, int, int /*<<< orphan*/);
unsigned char *malloc_aligned(int);
int /*<<< orphan*/ stderr;
int write(int, unsigned char *, int);
int sendcmd(int fd, int cmd, unsigned int arg1, unsigned int arg2,
            unsigned char arg3) {
  unsigned char *buff;
  buff = malloc_aligned(0x200);
  if (buff == NULL) {
    fprintf(stderr, "malloc_aligned failed :(\n");
    return -1;
  }
  buff[0] = cmd;
  buff[1] = (arg1 >> 0x18) & 0xff;
  buff[2] = (arg1 >> 0x10) & 0xff;
  buff[3] = (arg1 >> 0x08) & 0xff;
  buff[4] = (arg1 >> 0x00) & 0xff;
  buff[5] = (arg2 >> 0x18) & 0xff;
  buff[6] = (arg2 >> 0x10) & 0xff;
  buff[7] = (arg2 >> 0x08) & 0xff;
  buff[8] = (arg2 >> 0x00) & 0xff;
  buff[9] = (arg3);
  if (lseek(fd, 0x6200, SEEK_SET) < 0) {
    return -1;
  }
  return write(fd, buff, 0x200);
}


x86 assembly (clang, -O0):
<sendcmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %r8b,%al
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    $0x200,%edi
call   1040 <malloc_aligned@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1194 <sendcmd+0x54>
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <sendcmd+0x149>
mov    -0xc(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x10(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x10(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x3(%rax)
mov    -0x10(%rbp),%eax
shr    $0x0,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x4(%rax)
mov    -0x14(%rbp),%eax
shr    $0x18,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x5(%rax)
mov    -0x14(%rbp),%eax
shr    $0x10,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x6(%rax)
mov    -0x14(%rbp),%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x7(%rax)
mov    -0x14(%rbp),%eax
shr    $0x0,%eax
and    $0xff,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x8(%rax)
mov    -0x15(%rbp),%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x9(%rax)
mov    -0x8(%rbp),%edi
mov    0x2d85(%rip),%rax
mov    (%rax),%edx
mov    $0x6200,%esi
call   1050 <lseek@plt>
cmp    $0x0,%rax
jge    1275 <sendcmd+0x135>
movl   $0xffffffff,-0x4(%rbp)
jmp    1289 <sendcmd+0x149>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sendcmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %ecx,%r13d
mov    %edx,%ebx
mov    %esi,%r12d
mov    %edi,%r15d
mov    $0x200,%edi
call   1040 <malloc_aligned@plt>
test   %rax,%rax
je     11dc <sendcmd+0x9c>
mov    %rax,%rbp
mov    %r12b,(%rax)
mov    %ebx,%eax
shr    $0x18,%eax
mov    %al,0x1(%rbp)
mov    %ebx,%eax
shr    $0x10,%eax
mov    %al,0x2(%rbp)
mov    %bh,0x3(%rbp)
mov    %bl,0x4(%rbp)
mov    %r13d,%ecx
mov    %r13d,%eax
shr    $0x18,%eax
mov    %al,0x5(%rbp)
mov    %r13d,%eax
shr    $0x10,%eax
mov    %al,0x6(%rbp)
mov    %ch,0x7(%rbp)
mov    %cl,0x8(%rbp)
mov    %r14b,0x9(%rbp)
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    $0x6200,%esi
call   1050 <lseek@plt>
test   %rax,%rax
js     11f1 <sendcmd+0xb1>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <write@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [26 x i8] c"malloc_aligned failed :(\0A\00"
@SEEK_SET = global i32 0
define i32 @sendcmd(i32 %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8
%12 = alloca i8*
store i32 %0, i32* %7
store i32 %1, i32* %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i8 %4, i8* %11
%13 = call i8* @malloc_aligned(i32 512)
store i8* %13, i8** %12
%14 = load i8*, i8** %12
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %5
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %6
br label %84
19: ; preds = %5
%20 = load i32, i32* %8
%21 = trunc i32 %20 to i8
%22 = load i8*, i8** %12
%23 = getelementptr inbounds i8, i8* %22, i64 0
store i8 %21, i8* %23
%24 = load i32, i32* %9
%25 = lshr i32 %24, 24
%26 = and i32 %25, 255
%27 = trunc i32 %26 to i8
%28 = load i8*, i8** %12
%29 = getelementptr inbounds i8, i8* %28, i64 1
store i8 %27, i8* %29
%30 = load i32, i32* %9
%31 = lshr i32 %30, 16
%32 = and i32 %31, 255
%33 = trunc i32 %32 to i8
%34 = load i8*, i8** %12
%35 = getelementptr inbounds i8, i8* %34, i64 2
store i8 %33, i8* %35
%36 = load i32, i32* %9
%37 = lshr i32 %36, 8
%38 = and i32 %37, 255
%39 = trunc i32 %38 to i8
%40 = load i8*, i8** %12
%41 = getelementptr inbounds i8, i8* %40, i64 3
store i8 %39, i8* %41
%42 = load i32, i32* %9
%43 = lshr i32 %42, 0
%44 = and i32 %43, 255
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %12
%47 = getelementptr inbounds i8, i8* %46, i64 4
store i8 %45, i8* %47
%48 = load i32, i32* %10
%49 = lshr i32 %48, 24
%50 = and i32 %49, 255
%51 = trunc i32 %50 to i8
%52 = load i8*, i8** %12
%53 = getelementptr inbounds i8, i8* %52, i64 5
store i8 %51, i8* %53
%54 = load i32, i32* %10
%55 = lshr i32 %54, 16
%56 = and i32 %55, 255
%57 = trunc i32 %56 to i8
%58 = load i8*, i8** %12
%59 = getelementptr inbounds i8, i8* %58, i64 6
store i8 %57, i8* %59
%60 = load i32, i32* %10
%61 = lshr i32 %60, 8
%62 = and i32 %61, 255
%63 = trunc i32 %62 to i8
%64 = load i8*, i8** %12
%65 = getelementptr inbounds i8, i8* %64, i64 7
store i8 %63, i8* %65
%66 = load i32, i32* %10
%67 = lshr i32 %66, 0
%68 = and i32 %67, 255
%69 = trunc i32 %68 to i8
%70 = load i8*, i8** %12
%71 = getelementptr inbounds i8, i8* %70, i64 8
store i8 %69, i8* %71
%72 = load i8, i8* %11
%73 = load i8*, i8** %12
%74 = getelementptr inbounds i8, i8* %73, i64 9
store i8 %72, i8* %74
%75 = load i32, i32* %7
%76 = load i32, i32* @SEEK_SET
%77 = call i64 @lseek(i32 %75, i32 25088, i32 %76)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %19
store i32 -1, i32* %6
br label %84
80: ; preds = %19
%81 = load i32, i32* %7
%82 = load i8*, i8** %12
%83 = call i32 @write(i32 %81, i8* %82, i32 512)
store i32 %83, i32* %6
br label %84
84: ; preds = %80, %79, %16
%85 = load i32, i32* %6
ret i32 %85
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [26 x i8] c"malloc_aligned failed :(\0A\00"
@SEEK_SET = global i32 0
define i32 @sendcmd(i32 %0, i32 %1, i32 %2, i32 %3, i8 zeroext %4) {
%6 = tail call i8* @malloc_aligned(i32 512)
%7 = icmp eq i8* %6, null
br i1 %7, label %8, label %11
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %41
11: ; preds = %5
%12 = trunc i32 %1 to i8
store i8 %12, i8* %6
%13 = lshr i32 %2, 24
%14 = trunc i32 %13 to i8
%15 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %14, i8* %15
%16 = lshr i32 %2, 16
%17 = trunc i32 %16 to i8
%18 = getelementptr inbounds i8, i8* %6, i64 2
store i8 %17, i8* %18
%19 = lshr i32 %2, 8
%20 = trunc i32 %19 to i8
%21 = getelementptr inbounds i8, i8* %6, i64 3
store i8 %20, i8* %21
%22 = trunc i32 %2 to i8
%23 = getelementptr inbounds i8, i8* %6, i64 4
store i8 %22, i8* %23
%24 = lshr i32 %3, 24
%25 = trunc i32 %24 to i8
%26 = getelementptr inbounds i8, i8* %6, i64 5
store i8 %25, i8* %26
%27 = lshr i32 %3, 16
%28 = trunc i32 %27 to i8
%29 = getelementptr inbounds i8, i8* %6, i64 6
store i8 %28, i8* %29
%30 = lshr i32 %3, 8
%31 = trunc i32 %30 to i8
%32 = getelementptr inbounds i8, i8* %6, i64 7
store i8 %31, i8* %32
%33 = trunc i32 %3 to i8
%34 = getelementptr inbounds i8, i8* %6, i64 8
store i8 %33, i8* %34
%35 = getelementptr inbounds i8, i8* %6, i64 9
store i8 %4, i8* %35
%36 = load i32, i32* @SEEK_SET
%37 = tail call i64 @lseek(i32 %0, i32 25088, i32 %36)
%38 = icmp slt i64 %37, 0
br i1 %38, label %41, label %39
39: ; preds = %11
%40 = tail call i32 @write(i32 %0, i8* %6, i32 512)
br label %41
41: ; preds = %11, %39, %8
%42 = phi i32 [ -1, %8 ], [ %40, %39 ], [ -1, %11 ]
ret i32 %42
}