#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 EXIT_FAILURE;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, unsigned short);
int send_to_camd(unsigned char *, unsigned int);
int /*<<< orphan*/ sscanf(char *, char *, unsigned char *);
int /*<<< orphan*/ stderr;
int strlen(char *);
unsigned int strtoul(char *, int /*<<< orphan*/, int);
int main(int argc, char **argv) {
  size_t length = 0;
  unsigned char in_buf[8192];
  unsigned char out_buf[4096];
  unsigned int i, j = 0;
  unsigned int id;
  unsigned short desc_len;
  if ((argc < 4) || (argc > 5)) {
    fprintf(stderr, "usage: %s <vpid> <apid> <sid> [cadescriptors]\n", argv[0]);
    return EXIT_FAILURE;
  }
  if (argc == 5)
    while (length < (strlen(argv[4]) >> 1)) {
      sscanf(argv[4] + (length << 1), "%2hhx", &in_buf[length]);
      length++;
    }
  out_buf[j++] = 0x9f;
  out_buf[j++] = 0x80;
  out_buf[j++] = 0x32;
  out_buf[j++] = 0x82;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x03;
  id = strtoul(argv[3], 0, 16);
  out_buf[j++] = id >> 8;
  out_buf[j++] = id;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x01;
  for (i = 0; i < length; i += desc_len) {
    desc_len = in_buf[i + 1] + 2;
    if (in_buf[i] == 0x09) {
      memcpy(&out_buf[j], &in_buf[i], desc_len);
      j += desc_len;
    }
  }
  out_buf[10] = ((j - 12) >> 8) & 0xff;
  out_buf[11] = (j - 12) & 0xff;
  out_buf[j++] = 0x02;
  id = strtoul(argv[1], 0, 16);
  out_buf[j++] = id >> 8;
  out_buf[j++] = id;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x04;
  id = strtoul(argv[2], 0, 16);
  out_buf[j++] = id >> 8;
  out_buf[j++] = id;
  out_buf[j++] = 0x00;
  out_buf[j++] = 0x00;
  out_buf[4] = ((j - 6) >> 8) & 0xff;
  out_buf[5] = (j - 6) & 0xff;
  return send_to_camd(out_buf, j);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x3040,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x3028(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     119f <main+0x3f>
cmpl   $0x5,-0x8(%rbp)
jle    11cc <main+0x6c>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1651 <main+0x4f1>
cmpl   $0x5,-0x8(%rbp)
jne    124b <main+0xeb>
jmp    11db <main+0x7b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x3038(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x3038(%rbp),%rax
sar    $0x1,%ecx
movslq %ecx,%rcx
cmp    %rcx,%rax
jae    1246 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    -0x18(%rbp),%rax
shl    $0x1,%rax
add    %rax,%rdi
lea    -0x2020(%rbp),%rdx
add    -0x18(%rbp),%rdx
lea    0xdff(%rip),%rsi
call   1070 <sscanf@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11db <main+0x7b>
jmp    124b <main+0xeb>
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x9f,-0x3020(%rbp,%rax,1)
9f
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x80,-0x3020(%rbp,%rax,1)
80
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x32,-0x3020(%rbp,%rax,1)
32
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x82,-0x3020(%rbp,%rax,1)
82
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x3,-0x3020(%rbp,%rax,1)
03
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x302c(%rbp)
mov    -0x302c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x3028(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3028(%rbp)
mov    %eax,%eax
mov    %cl,-0x3020(%rbp,%rax,1)
mov    -0x302c(%rbp),%eax
mov    %al,%cl
mov    -0x3028(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3028(%rbp)
mov    %eax,%eax
mov    %cl,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x1,-0x3020(%rbp,%rax,1)
01
movl   $0x0,-0x3024(%rbp)
mov    -0x3024(%rbp),%eax
cmp    -0x18(%rbp),%rax
jae    1482 <main+0x322>
mov    -0x3024(%rbp),%eax
add    $0x1,%eax
mov    %eax,%eax
movzbl -0x2020(%rbp,%rax,1),%eax
ff
add    $0x2,%eax
mov    %ax,-0x302e(%rbp)
mov    -0x3024(%rbp),%eax
movzbl -0x2020(%rbp,%rax,1),%eax
ff
cmp    $0x9,%eax
jne    1465 <main+0x305>
mov    -0x3028(%rbp),%eax
lea    -0x3020(%rbp),%rdi
add    %rax,%rdi
mov    -0x3024(%rbp),%eax
lea    -0x2020(%rbp),%rsi
add    %rax,%rsi
mov    -0x302e(%rbp),%ax
movzwl %ax,%edx
call   1060 <memcpy@plt>
movzwl -0x302e(%rbp),%eax
add    -0x3028(%rbp),%eax
mov    %eax,-0x3028(%rbp)
jmp    146a <main+0x30a>
movzwl -0x302e(%rbp),%eax
add    -0x3024(%rbp),%eax
mov    %eax,-0x3024(%rbp)
jmp    13df <main+0x27f>
mov    -0x3028(%rbp),%eax
sub    $0xc,%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x3016(%rbp)
mov    -0x3028(%rbp),%eax
sub    $0xc,%eax
and    $0xff,%eax
mov    %al,-0x3015(%rbp)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x2,-0x3020(%rbp,%rax,1)
02
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x302c(%rbp)
mov    -0x302c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x3028(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3028(%rbp)
mov    %eax,%eax
mov    %cl,-0x3020(%rbp,%rax,1)
mov    -0x302c(%rbp),%eax
mov    %al,%cl
mov    -0x3028(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3028(%rbp)
mov    %eax,%eax
mov    %cl,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x4,-0x3020(%rbp,%rax,1)
04
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
mov    %eax,-0x302c(%rbp)
mov    -0x302c(%rbp),%eax
shr    $0x8,%eax
mov    %al,%cl
mov    -0x3028(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3028(%rbp)
mov    %eax,%eax
mov    %cl,-0x3020(%rbp,%rax,1)
mov    -0x302c(%rbp),%eax
mov    %al,%cl
mov    -0x3028(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3028(%rbp)
mov    %eax,%eax
mov    %cl,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x3028(%rbp)
mov    %eax,%eax
movb   $0x0,-0x3020(%rbp,%rax,1)
mov    -0x3028(%rbp),%eax
sub    $0x6,%eax
shr    $0x8,%eax
and    $0xff,%eax
mov    %al,-0x301c(%rbp)
mov    -0x3028(%rbp),%eax
sub    $0x6,%eax
and    $0xff,%eax
mov    %al,-0x301b(%rbp)
lea    -0x3020(%rbp),%rdi
mov    -0x3028(%rbp),%esi
call   1050 <send_to_camd@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x3040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x3000,%rsp
mov    %rsi,%r14
lea    -0x6(%rdi),%eax
cmp    $0xfffffffd,%eax
ja     11a0 <main+0x40>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xe73(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
jmp    12d7 <main+0x177>
cmp    $0x5,%edi
jne    11b3 <main+0x53>
mov    0x20(%r14),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jae    11b8 <main+0x58>
xor    %r12d,%r12d
jmp    1204 <main+0xa4>
xor    %ebx,%ebx
lea    0xe6e(%rip),%rbp
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x20(%r14),%rdi
add    %rbx,%rdi
lea    (%rsp,%r12,1),%rdx
add    $0x1000,%rdx
mov    %rbp,%rsi
call   1070 <sscanf@plt>
add    $0x1,%r12
mov    0x20(%r14),%rdi
call   1030 <strlen@plt>
sar    %eax
cltq
add    $0x2,%rbx
cmp    %rax,%r12
jb     11d0 <main+0x70>
movl   $0x8232809f,(%rsp)
movw   $0x0,0x4(%rsp)
movb   $0x3,0x6(%rsp)
mov    0x18(%r14),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
mov    %ah,0x7(%rsp)
mov    %al,0x8(%rsp)
movl   $0x1000000,0x9(%rsp)
01
mov    $0xd,%r15d
test   %r12,%r12
jne    12fb <main+0x19b>
lea    -0xc(%r15),%eax
rol    $0x8,%ax
mov    %ax,0xa(%rsp)
lea    0x1(%r15),%ebx
mov    %r15d,%eax
movb   $0x2,(%rsp,%rax,1)
mov    0x8(%r14),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
lea    0x2(%r15),%ecx
mov    %ah,(%rsp,%rbx,1)
lea    0x3(%r15),%edx
mov    %al,(%rsp,%rcx,1)
lea    0x4(%r15),%ebx
movb   $0x0,(%rsp,%rdx,1)
lea    0x5(%r15),%eax
movb   $0x0,(%rsp,%rbx,1)
lea    0x6(%r15),%ebp
movb   $0x4,(%rsp,%rax,1)
mov    0x10(%r14),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <strtoul@plt>
lea    0x7(%r15),%ecx
mov    %ah,(%rsp,%rbp,1)
lea    0x8(%r15),%edx
mov    %al,(%rsp,%rcx,1)
lea    0x9(%r15),%eax
movb   $0x0,(%rsp,%rdx,1)
add    $0xa,%r15d
movb   $0x0,(%rsp,%rax,1)
mov    %bh,0x4(%rsp)
mov    %bl,0x5(%rsp)
mov    %rsp,%rdi
mov    %r15d,%esi
call   1050 <send_to_camd@plt>
add    $0x3000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)
add    %ebp,%ebx
cmp    %rbx,%r12
jbe    1248 <main+0xe8>
lea    0x1(%rbx),%eax
movzbl 0x1000(%rsp,%rax,1),%ebp
add    $0x2,%ebp
cmpb   $0x9,0x1000(%rsp,%rbx,1)
09
jne    12f0 <main+0x190>
lea    (%rsp,%rbx,1),%rsi
add    $0x1000,%rsi
mov    %r15d,%eax
lea    (%rsp,%rax,1),%rdi
movzwl %bp,%ebp
mov    %ebp,%edx
call   1060 <memcpy@plt>
add    %ebp,%r15d
jmp    12f0 <main+0x190>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [47 x i8] c"usage: %s <vpid> <apid> <sid> [cadescriptors]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"%2hhx\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca [8192 x i8]
%8 = alloca [4096 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i16
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store i32 0, i32* %10
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 4
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 5
br i1 %17, label %18, label %25
18: ; preds = %15, %2
%19 = load i32, i32* @stderr
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
store i32 %24, i32* %3
br label %236
25: ; preds = %15
%26 = load i32, i32* %4
%27 = icmp eq i32 %26, 5
br i1 %27, label %28, label %51
28: ; preds = %25
br label %29
29: ; preds = %38, %28
%30 = load i64, i64* %6
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 4
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = ashr i32 %34, 1
%36 = sext i32 %35 to i64
%37 = icmp ult i64 %30, %36
br i1 %37, label %38, label %50
38: ; preds = %29
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 4
%41 = load i8*, i8** %40
%42 = load i64, i64* %6
%43 = shl i64 %42, 1
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i64, i64* %6
%46 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 %45
%47 = call i32 @sscanf(i8* %44, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %46)
%48 = load i64, i64* %6
%49 = add i64 %48, 1
store i64 %49, i64* %6
br label %29
50: ; preds = %29
br label %51
51: ; preds = %50, %25
%52 = load i32, i32* %10
%53 = add i32 %52, 1
store i32 %53, i32* %10
%54 = zext i32 %52 to i64
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %54
store i8 -97, i8* %55
%56 = load i32, i32* %10
%57 = add i32 %56, 1
store i32 %57, i32* %10
%58 = zext i32 %56 to i64
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %58
store i8 -128, i8* %59
%60 = load i32, i32* %10
%61 = add i32 %60, 1
store i32 %61, i32* %10
%62 = zext i32 %60 to i64
%63 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %62
store i8 50, i8* %63
%64 = load i32, i32* %10
%65 = add i32 %64, 1
store i32 %65, i32* %10
%66 = zext i32 %64 to i64
%67 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %66
store i8 -126, i8* %67
%68 = load i32, i32* %10
%69 = add i32 %68, 1
store i32 %69, i32* %10
%70 = zext i32 %68 to i64
%71 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %70
store i8 0, i8* %71
%72 = load i32, i32* %10
%73 = add i32 %72, 1
store i32 %73, i32* %10
%74 = zext i32 %72 to i64
%75 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %74
store i8 0, i8* %75
%76 = load i32, i32* %10
%77 = add i32 %76, 1
store i32 %77, i32* %10
%78 = zext i32 %76 to i64
%79 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %78
store i8 3, i8* %79
%80 = load i8**, i8*** %5
%81 = getelementptr inbounds i8*, i8** %80, i64 3
%82 = load i8*, i8** %81
%83 = call i32 @strtoul(i8* %82, i32 0, i32 16)
store i32 %83, i32* %11
%84 = load i32, i32* %11
%85 = lshr i32 %84, 8
%86 = trunc i32 %85 to i8
%87 = load i32, i32* %10
%88 = add i32 %87, 1
store i32 %88, i32* %10
%89 = zext i32 %87 to i64
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %89
store i8 %86, i8* %90
%91 = load i32, i32* %11
%92 = trunc i32 %91 to i8
%93 = load i32, i32* %10
%94 = add i32 %93, 1
store i32 %94, i32* %10
%95 = zext i32 %93 to i64
%96 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %95
store i8 %92, i8* %96
%97 = load i32, i32* %10
%98 = add i32 %97, 1
store i32 %98, i32* %10
%99 = zext i32 %97 to i64
%100 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %99
store i8 0, i8* %100
%101 = load i32, i32* %10
%102 = add i32 %101, 1
store i32 %102, i32* %10
%103 = zext i32 %101 to i64
%104 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %103
store i8 0, i8* %104
%105 = load i32, i32* %10
%106 = add i32 %105, 1
store i32 %106, i32* %10
%107 = zext i32 %105 to i64
%108 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %107
store i8 0, i8* %108
%109 = load i32, i32* %10
%110 = add i32 %109, 1
store i32 %110, i32* %10
%111 = zext i32 %109 to i64
%112 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %111
store i8 1, i8* %112
store i32 0, i32* %9
br label %113
113: ; preds = %147, %51
%114 = load i32, i32* %9
%115 = zext i32 %114 to i64
%116 = load i64, i64* %6
%117 = icmp ult i64 %115, %116
br i1 %117, label %118, label %152
118: ; preds = %113
%119 = load i32, i32* %9
%120 = add i32 %119, 1
%121 = zext i32 %120 to i64
%122 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 %121
%123 = load i8, i8* %122
%124 = zext i8 %123 to i32
%125 = add nsw i32 %124, 2
%126 = trunc i32 %125 to i16
store i16 %126, i16* %12
%127 = load i32, i32* %9
%128 = zext i32 %127 to i64
%129 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 %128
%130 = load i8, i8* %129
%131 = zext i8 %130 to i32
%132 = icmp eq i32 %131, 9
br i1 %132, label %133, label %146
133: ; preds = %118
%134 = load i32, i32* %10
%135 = zext i32 %134 to i64
%136 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %135
%137 = load i32, i32* %9
%138 = zext i32 %137 to i64
%139 = getelementptr inbounds [8192 x i8], [8192 x i8]* %7, i64 0, i64 %138
%140 = load i16, i16* %12
%141 = call i32 @memcpy(i8* %136, i8* %139, i16 zeroext %140)
%142 = load i16, i16* %12
%143 = zext i16 %142 to i32
%144 = load i32, i32* %10
%145 = add i32 %144, %143
store i32 %145, i32* %10
br label %146
146: ; preds = %133, %118
br label %147
147: ; preds = %146
%148 = load i16, i16* %12
%149 = zext i16 %148 to i32
%150 = load i32, i32* %9
%151 = add i32 %150, %149
store i32 %151, i32* %9
br label %113
152: ; preds = %113
%153 = load i32, i32* %10
%154 = sub i32 %153, 12
%155 = lshr i32 %154, 8
%156 = and i32 %155, 255
%157 = trunc i32 %156 to i8
%158 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 10
store i8 %157, i8* %158
%159 = load i32, i32* %10
%160 = sub i32 %159, 12
%161 = and i32 %160, 255
%162 = trunc i32 %161 to i8
%163 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 11
store i8 %162, i8* %163
%164 = load i32, i32* %10
%165 = add i32 %164, 1
store i32 %165, i32* %10
%166 = zext i32 %164 to i64
%167 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %166
store i8 2, i8* %167
%168 = load i8**, i8*** %5
%169 = getelementptr inbounds i8*, i8** %168, i64 1
%170 = load i8*, i8** %169
%171 = call i32 @strtoul(i8* %170, i32 0, i32 16)
store i32 %171, i32* %11
%172 = load i32, i32* %11
%173 = lshr i32 %172, 8
%174 = trunc i32 %173 to i8
%175 = load i32, i32* %10
%176 = add i32 %175, 1
store i32 %176, i32* %10
%177 = zext i32 %175 to i64
%178 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %177
store i8 %174, i8* %178
%179 = load i32, i32* %11
%180 = trunc i32 %179 to i8
%181 = load i32, i32* %10
%182 = add i32 %181, 1
store i32 %182, i32* %10
%183 = zext i32 %181 to i64
%184 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %183
store i8 %180, i8* %184
%185 = load i32, i32* %10
%186 = add i32 %185, 1
store i32 %186, i32* %10
%187 = zext i32 %185 to i64
%188 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %187
store i8 0, i8* %188
%189 = load i32, i32* %10
%190 = add i32 %189, 1
store i32 %190, i32* %10
%191 = zext i32 %189 to i64
%192 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %191
store i8 0, i8* %192
%193 = load i32, i32* %10
%194 = add i32 %193, 1
store i32 %194, i32* %10
%195 = zext i32 %193 to i64
%196 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %195
store i8 4, i8* %196
%197 = load i8**, i8*** %5
%198 = getelementptr inbounds i8*, i8** %197, i64 2
%199 = load i8*, i8** %198
%200 = call i32 @strtoul(i8* %199, i32 0, i32 16)
store i32 %200, i32* %11
%201 = load i32, i32* %11
%202 = lshr i32 %201, 8
%203 = trunc i32 %202 to i8
%204 = load i32, i32* %10
%205 = add i32 %204, 1
store i32 %205, i32* %10
%206 = zext i32 %204 to i64
%207 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %206
store i8 %203, i8* %207
%208 = load i32, i32* %11
%209 = trunc i32 %208 to i8
%210 = load i32, i32* %10
%211 = add i32 %210, 1
store i32 %211, i32* %10
%212 = zext i32 %210 to i64
%213 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %212
store i8 %209, i8* %213
%214 = load i32, i32* %10
%215 = add i32 %214, 1
store i32 %215, i32* %10
%216 = zext i32 %214 to i64
%217 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %216
store i8 0, i8* %217
%218 = load i32, i32* %10
%219 = add i32 %218, 1
store i32 %219, i32* %10
%220 = zext i32 %218 to i64
%221 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 %220
store i8 0, i8* %221
%222 = load i32, i32* %10
%223 = sub i32 %222, 6
%224 = lshr i32 %223, 8
%225 = and i32 %224, 255
%226 = trunc i32 %225 to i8
%227 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 4
store i8 %226, i8* %227
%228 = load i32, i32* %10
%229 = sub i32 %228, 6
%230 = and i32 %229, 255
%231 = trunc i32 %230 to i8
%232 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 5
store i8 %231, i8* %232
%233 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%234 = load i32, i32* %10
%235 = call i32 @send_to_camd(i8* %233, i32 %234)
store i32 %235, i32* %3
br label %236
236: ; preds = %152, %18
%237 = load i32, i32* %3
ret i32 %237
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [47 x i8] c"usage: %s <vpid> <apid> <sid> [cadescriptors]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [6 x i8] c"%2hhx\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [8192 x i8]
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = add i32 %0, -6
%8 = icmp ult i32 %7, -2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
br label %134
14: ; preds = %2
%15 = icmp eq i32 %0, 5
br i1 %15, label %16, label %34
16: ; preds = %14
%17 = getelementptr inbounds i8*, i8** %1, i64 4
%18 = load i8*, i8** %17
%19 = call i32 @strlen(i8* %18)
%20 = icmp ult i32 %19, 2
br i1 %20, label %34, label %21
21: ; preds = %16, %21
%22 = phi i64 [ %28, %21 ], [ 0, %16 ]
%23 = load i8*, i8** %17
%24 = shl i64 %22, 1
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %22
%27 = call i32 @sscanf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = add nuw i64 %22, 1
%29 = load i8*, i8** %17
%30 = call i32 @strlen(i8* %29)
%31 = ashr i32 %30, 1
%32 = sext i32 %31 to i64
%33 = icmp ult i64 %28, %32
br i1 %33, label %21, label %34
34: ; preds = %21, %16, %14
%35 = phi i64 [ 0, %14 ], [ 0, %16 ], [ %28, %21 ]
store i8 -97, i8* %6
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 1
store i8 -128, i8* %36
%37 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 2
store i8 50, i8* %37
%38 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 3
store i8 -126, i8* %38
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 4
store i8 0, i8* %39
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 5
store i8 0, i8* %40
%41 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 6
store i8 3, i8* %41
%42 = getelementptr inbounds i8*, i8** %1, i64 3
%43 = load i8*, i8** %42
%44 = call i32 @strtoul(i8* %43, i32 0, i32 16)
%45 = lshr i32 %44, 8
%46 = trunc i32 %45 to i8
%47 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 7
store i8 %46, i8* %47
%48 = trunc i32 %44 to i8
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 8
store i8 %48, i8* %49
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 9
store i8 0, i8* %50
%51 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 10
store i8 0, i8* %51
%52 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 11
store i8 0, i8* %52
%53 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 12
store i8 1, i8* %53
%54 = icmp eq i64 %35, 0
br i1 %54, label %82, label %55
55: ; preds = %34, %76
%56 = phi i64 [ %80, %76 ], [ 0, %34 ]
%57 = phi i32 [ %78, %76 ], [ 13, %34 ]
%58 = phi i32 [ %79, %76 ], [ 0, %34 ]
%59 = add i32 %58, 1
%60 = zext i32 %59 to i64
%61 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %60
%62 = load i8, i8* %61
%63 = zext i8 %62 to i16
%64 = add nuw nsw i16 %63, 2
%65 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 %56
%66 = load i8, i8* %65
%67 = icmp eq i8 %66, 9
br i1 %67, label %70, label %68
68: ; preds = %55
%69 = zext i16 %64 to i32
br label %76
70: ; preds = %55
%71 = zext i32 %57 to i64
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %71
%73 = call i32 @memcpy(i8* %72, i8* %65, i16 zeroext %64)
%74 = zext i16 %64 to i32
%75 = add i32 %57, %74
br label %76
76: ; preds = %68, %70
%77 = phi i32 [ %69, %68 ], [ %74, %70 ]
%78 = phi i32 [ %57, %68 ], [ %75, %70 ]
%79 = add i32 %58, %77
%80 = zext i32 %79 to i64
%81 = icmp ugt i64 %35, %80
br i1 %81, label %55, label %82
82: ; preds = %76, %34
%83 = phi i32 [ 13, %34 ], [ %78, %76 ]
%84 = add i32 %83, -12
%85 = lshr i32 %84, 8
%86 = trunc i32 %85 to i8
store i8 %86, i8* %51
%87 = trunc i32 %84 to i8
store i8 %87, i8* %52
%88 = add i32 %83, 1
%89 = zext i32 %83 to i64
%90 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %89
store i8 2, i8* %90
%91 = getelementptr inbounds i8*, i8** %1, i64 1
%92 = load i8*, i8** %91
%93 = call i32 @strtoul(i8* %92, i32 0, i32 16)
%94 = lshr i32 %93, 8
%95 = trunc i32 %94 to i8
%96 = add i32 %83, 2
%97 = zext i32 %88 to i64
%98 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %97
store i8 %95, i8* %98
%99 = trunc i32 %93 to i8
%100 = add i32 %83, 3
%101 = zext i32 %96 to i64
%102 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %101
store i8 %99, i8* %102
%103 = add i32 %83, 4
%104 = zext i32 %100 to i64
%105 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %104
store i8 0, i8* %105
%106 = add i32 %83, 5
%107 = zext i32 %103 to i64
%108 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %107
store i8 0, i8* %108
%109 = add i32 %83, 6
%110 = zext i32 %106 to i64
%111 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %110
store i8 4, i8* %111
%112 = getelementptr inbounds i8*, i8** %1, i64 2
%113 = load i8*, i8** %112
%114 = call i32 @strtoul(i8* %113, i32 0, i32 16)
%115 = lshr i32 %114, 8
%116 = trunc i32 %115 to i8
%117 = add i32 %83, 7
%118 = zext i32 %109 to i64
%119 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %118
store i8 %116, i8* %119
%120 = trunc i32 %114 to i8
%121 = add i32 %83, 8
%122 = zext i32 %117 to i64
%123 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %122
store i8 %120, i8* %123
%124 = add i32 %83, 9
%125 = zext i32 %121 to i64
%126 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %125
store i8 0, i8* %126
%127 = add i32 %83, 10
%128 = zext i32 %124 to i64
%129 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 %128
store i8 0, i8* %129
%130 = lshr i32 %103, 8
%131 = trunc i32 %130 to i8
store i8 %131, i8* %39
%132 = trunc i32 %103 to i8
store i8 %132, i8* %40
%133 = call i32 @send_to_camd(i8* %6, i32 %127)
br label %134
134: ; preds = %82, %9
%135 = phi i32 [ %13, %9 ], [ %133, %82 ]
ret i32 %135
}