#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*/ InsertI4(int, unsigned char *);
void edit_xing_header(int frames, int bytes, unsigned char *buf, int len,
                      int version, int mode) {
  int offset = 44;
  switch (version) {
  case 3:
    switch (mode) {
    case 3:
      offset = 29;
      break;
    default:
      offset = 44;
      break;
    }
    break;
  default:
    switch (mode) {
    case 3:
      offset = 21;
      break;
    default:
      offset = 29;
      break;
    }
    break;
  }
  InsertI4(frames, &buf[offset]);
  InsertI4(bytes, &buf[offset + 4]);
}


x86 assembly (clang, -O0):
<edit_xing_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
movl   $0x2c,-0x20(%rbp)
mov    -0x18(%rbp),%eax
sub    $0x3,%eax
jne    116e <edit_xing_header+0x5e>
jmp    1145 <edit_xing_header+0x35>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
jne    1162 <edit_xing_header+0x52>
jmp    1156 <edit_xing_header+0x46>
movl   $0x1d,-0x20(%rbp)
jmp    1169 <edit_xing_header+0x59>
movl   $0x2c,-0x20(%rbp)
jmp    1197 <edit_xing_header+0x87>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
jne    118b <edit_xing_header+0x7b>
jmp    117f <edit_xing_header+0x6f>
movl   $0x15,-0x20(%rbp)
jmp    1192 <edit_xing_header+0x82>
movl   $0x1d,-0x20(%rbp)
jmp    1197 <edit_xing_header+0x87>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
movslq -0x20(%rbp),%rax
add    %rax,%rsi
call   1030 <InsertI4@plt>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%eax
add    $0x4,%eax
cltq
add    %rax,%rsi
call   1030 <InsertI4@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<edit_xing_header>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
xor    %eax,%eax
cmp    $0x3,%r9d
setne  %al
mov    $0x1d,%ecx
mov    $0x2c,%edx
cmove  %ecx,%edx
cmp    $0x3,%r8d
lea    0x15(,%rax,8),%ebp
cmove  %edx,%ebp
lea    (%rbx,%rbp,1),%rsi
call   1030 <InsertI4@plt>
lea    (%rbx,%rbp,1),%rsi
add    $0x4,%rsi
mov    %r14d,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <InsertI4@plt>

LLVM IR (-O0):
define void @edit_xing_header(i32 %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i32 %0, i32* %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i32 %4, i32* %11
store i32 %5, i32* %12
store i32 44, i32* %13
%14 = load i32, i32* %11
switch i32 %14, label %20 [
i32 3, label %15
]
15: ; preds = %6
%16 = load i32, i32* %12
switch i32 %16, label %18 [
i32 3, label %17
]
17: ; preds = %15
store i32 29, i32* %13
br label %19
18: ; preds = %15
store i32 44, i32* %13
br label %19
19: ; preds = %18, %17
br label %25
20: ; preds = %6
%21 = load i32, i32* %12
switch i32 %21, label %23 [
i32 3, label %22
]
22: ; preds = %20
store i32 21, i32* %13
br label %24
23: ; preds = %20
store i32 29, i32* %13
br label %24
24: ; preds = %23, %22
br label %25
25: ; preds = %24, %19
%26 = load i32, i32* %7
%27 = load i8*, i8** %9
%28 = load i32, i32* %13
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = call i32 @InsertI4(i32 %26, i8* %30)
%32 = load i32, i32* %8
%33 = load i8*, i8** %9
%34 = load i32, i32* %13
%35 = add nsw i32 %34, 4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %33, i64 %36
%38 = call i32 @InsertI4(i32 %32, i8* %37)
ret void
}

LLVM IR (-O2):
define void @edit_xing_header(i32 %0, i32 %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp eq i32 %4, 3
%8 = icmp eq i32 %5, 3
%9 = select i1 %8, i32 29, i32 44
%10 = select i1 %8, i32 21, i32 29
%11 = select i1 %7, i32 %9, i32 %10
%12 = zext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %2, i64 %12
%14 = tail call i32 @InsertI4(i32 %0, i8* %13)
%15 = add nuw nsw i32 %11, 4
%16 = zext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %2, i64 %16
%18 = tail call i32 @InsertI4(i32 %1, i8* %17)
ret void
}