LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::operator+(Playlist&)
Playlist Playlist::operator+ (Playlist& secondPlaylist) {
  Playlist result;
  
  // Insere as músicas da playlist atual na playlist final
  result.insertSong(*this); 

  // Insere as músicas da segunda playlist na playlist final
  result.insertSong(secondPlaylist);

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
callq 0x8e7c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x90a8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x90a8
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq %rbx, %rdi
callq 0x8ef4
movq %r14, %rdi
callq 0x2170
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::insertSong(Playlist&)
void Playlist::insertSong(Playlist& toInsert) {
  // Tratamento para garantir que a nova lista não está vazia
  if (toInsert.getSongs()->getSize() < 1) {
    return;
  } else {
    // Insere as músicas na playlist atual por meio de sobrecarga
    songs->insertEnd(*toInsert.getSongs());
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
movq %rsi, %rbx
movq %rdi, %r14
movq 0x20(%rsi), %rdi
callq 0x28dc
testq %rax, %rax
je 0x90d4
movq 0x20(%r14), %rdi
movq 0x20(%rbx), %rsi
popq %rbx
popq %r14
popq %rbp
jmp 0x2d6e
popq %rbx
popq %r14
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::operator+(Song&)
Playlist Playlist::operator+ (Song& toAdd) {
  Playlist result;

  // Insere as músicas da playlist atual na playlist final
  result.insertSong(*this); 

  // Insere a música do parâmetro no final
  result.songs->insertEnd(toAdd);

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
callq 0x8e7c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x90a8
movq 0x20(%rbx), %r14
leaq -0x50(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x37d8
leaq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x24dc
leaq -0x60(%rbp), %rdi
callq 0x99c6
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x99c6
jmp 0x9187
movq %rax, %r14
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x9187
callq 0x20e0
jmp 0x9187
movq %rax, %r14
movq %rbx, %rdi
callq 0x8ef4
movq %r14, %rdi
callq 0x2170
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::operator-(Playlist&)
Playlist Playlist::operator- (Playlist& secondPlaylist) {
  // Cria a playlist final a partir da playlist atual
  Playlist result(*this);

  node* temp = secondPlaylist.getSongs()->getHead();
  // Percorre a segunda playlist
  while (temp != nullptr) {
    // Procura a posição da música na playlist final
    size_t pos = result.getSongs()->getPosition(temp->data);

    
    if (pos > 0) {
      result.removeSong(pos);
    }

    temp = temp->next;
  }
  
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r14
movq %rdi, %rbx
callq 0x8f32
movq 0x20(%r14), %rdi
callq 0x28c8
movq %rax, %r14
testq %rax, %rax
je 0x9233
leaq -0x38(%rbp), %r15
leaq -0x68(%rbp), %r12
movq 0x20(%rbx), %r13
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x37d8
movq %r15, -0x48(%rbp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x37d8
movq %r13, %rdi
movq %r12, %rsi
callq 0x3282
movq %rax, %r13
movq %r12, %rdi
callq 0x99c6
testq %r13, %r13
je 0x922a
movq 0x20(%rbx), %rdi
movq %r13, %rsi
callq 0x3146
movq 0x40(%r14), %r14
testq %r14, %r14
jne 0x91cd
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x926c
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x926f
callq 0x20e0
jmp 0x926f
movq %rax, %r14
leaq -0x68(%rbp), %rdi
callq 0x99c6
jmp 0x926f
movq %rax, %r14
movq %rbx, %rdi
callq 0x8ef4
movq %r14, %rdi
callq 0x2170
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::operator-(Song&)
Playlist Playlist::operator- (Song& toRemove) {
  // Cria a playlist final a partir da playlist atual
  Playlist result(*this);

  // Obtém a posição da música na playlist final
  size_t pos = result.getSongs()->getPosition(toRemove);

  // Se existir, remove
  if (pos > 0) {
    result.removeSong(pos);
  }

  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdx, %r15
movq %rdi, %rbx
callq 0x8f32
movq 0x20(%rbx), %r14
leaq -0x50(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x37d8
leaq -0x40(%rbp), %rdi
leaq -0x30(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0x3282
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x99c6
testq %r14, %r14
je 0x9317
movq 0x20(%rbx), %rdi
movq %r14, %rsi
callq 0x3146
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x99c6
jmp 0x934b
movq %rax, %r14
movq -0x60(%rbp), %rdi
cmpq %r12, %rdi
je 0x934b
callq 0x20e0
jmp 0x934b
movq %rax, %r14
movq %rbx, %rdi
callq 0x8ef4
movq %r14, %rdi
callq 0x2170
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::operator>>(Song*&)
void Playlist::operator>> (Song*& lastSong) {
  if (songs->getSize() > 0) {
    node* temp = new node;
    // Extrai o ultimo nó da lista de músicas
    *songs >> temp;
    // Guarda a música desse nó
    *lastSong = temp->data;

    delete temp;
  } else {
    lastSong = nullptr;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x20(%rdi), %rdi
callq 0x28dc
testq %rax, %rax
je 0x93e8
movl $0x48, %edi
callq 0x2100
movq %rax, %r15
movq %rax, %rdi
callq 0x99a0
leaq -0x28(%rbp), %r12
movq %r15, (%r12)
movq 0x20(%r14), %rdi
movq %r12, %rsi
callq 0x2776
movq (%r12), %r14
movq (%rbx), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2040
addq $0x20, %rbx
addq $0x20, %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2040
movq (%r12), %rbx
testq %rbx, %rbx
je 0x93ef
movq %rbx, %rdi
callq 0x99c6
movq %rbx, %rdi
callq 0x20e0
jmp 0x93ef
movq $0x0, (%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq %r15, %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2170
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::operator<<(Song*&)
void Playlist::operator<< (Song*& newSong) {
  if (newSong == nullptr) {
    return;
  } else {
    songs->insertEnd(*newSong);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq (%rsi), %r15
testq %r15, %r15
je 0x9475
movq 0x20(%rdi), %rbx
leaq -0x48(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0x37d8
leaq -0x38(%rbp), %rdi
leaq -0x28(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
callq 0x37d8
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0x24dc
leaq -0x58(%rbp), %rdi
callq 0x99c6
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
callq 0x99c6
jmp 0x949f
movq %rax, %rbx
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x949f
callq 0x20e0
movq %rbx, %rdi
callq 0x2170
nop
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::moveSong(unsigned long, unsigned long)
void Playlist::moveSong(size_t start, size_t end) {
  if (start != end) {
    // Acessa o valor da música a ser movida
    node* target = songs->getNode(start);
    Song value = target->data;

    // Remove ela da posição atual
    songs->removePosition(start);

    // Insere ela na nova posição
    if (end < start) {
      songs->insertPosition(end, value);
    } else {
      songs->insertPosition(end + 1, value);
    } 

    // Cada vez que uma música for movida, playing recebe head
    playing = songs->getHead();
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
cmpq %rdx, %rsi
je 0x96d8
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %rbx
movq 0x20(%rdi), %rdi
callq 0x35ec
movq %rax, %r15
leaq -0x58(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq -0x68(%rbp), %rdi
callq 0x37d8
leaq -0x48(%rbp), %rdi
leaq -0x38(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
callq 0x37d8
movq 0x20(%rbx), %rdi
movq %r12, %rsi
callq 0x3146
movq 0x20(%rbx), %r15
cmpq %r12, %r14
jae 0x9665
leaq -0xd8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0xe8(%rbp), %r12
movq %r12, %rdi
callq 0x37d8
leaq -0xc8(%rbp), %rdi
leaq -0xb8(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
callq 0x37d8
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2e26
jmp 0x96ba
leaq -0x98(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
addq %rsi, %rdx
leaq -0xa8(%rbp), %r12
movq %r12, %rdi
callq 0x37d8
leaq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x48(%rbp), %rsi
movq -0x40(%rbp), %rdx
addq %rsi, %rdx
callq 0x37d8
incq %r14
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2e26
movq %r12, %rdi
callq 0x99c6
movq 0x20(%rbx), %rdi
callq 0x28c8
movq %rax, 0x28(%rbx)
leaq -0x68(%rbp), %rdi
callq 0x99c6
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
jmp 0x9700
movq %rax, %rbx
leaq -0xe8(%rbp), %rdi
callq 0x99c6
jmp 0x973f
movq %rax, %rbx
movq -0xa8(%rbp), %rdi
jmp 0x971d
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
cmpq %r13, %rdi
je 0x973f
callq 0x20e0
jmp 0x973f
movq %rax, %rbx
movq -0x68(%rbp), %rdi
cmpq %r13, %rdi
je 0x9748
callq 0x20e0
jmp 0x9748
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x99c6
movq %rbx, %rdi
callq 0x2170
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::removeSong(Playlist&)
size_t Playlist::removeSong(Playlist& toRemove) {
  // Tratamento para garantir que a nova playlist não está vazia
  if (toRemove.getSongs()->getSize() < 1) {
    return 0;
  } else {
    size_t removed = 0;

    node* temp = toRemove.getSongs()->getHead();

    while (temp != nullptr) {
      // Obtém a posição da música na playlist atual
      size_t pos = getSongs()->getPosition(temp->data);

      // Remove da playlist atual
      if (pos > 0) {
        removeSong(pos);
        ++removed;
      }

      temp = temp->next;
    }
    
    return removed;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x20(%rsi), %rdi
callq 0x28dc
testq %rax, %rax
je 0x9800
movq 0x20(%r14), %rdi
callq 0x28c8
testq %rax, %rax
je 0x9800
movq %rax, %r15
xorl %r14d, %r14d
leaq -0x68(%rbp), %r13
movq 0x20(%rbx), %r12
leaq -0x58(%rbp), %rax
movq %rax, -0x68(%rbp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x37d8
leaq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
leaq -0x48(%rbp), %rdi
callq 0x37d8
movq %r12, %rdi
movq %r13, %rsi
callq 0x3282
movq %rax, %r12
movq %r13, %rdi
callq 0x99c6
testq %r12, %r12
je 0x97f5
movq 0x20(%rbx), %rdi
movq %r12, %rsi
callq 0x3146
incq %r14
movq 0x40(%r15), %r15
testq %r15, %r15
jne 0x9791
jmp 0x9803
xorl %r14d, %r14d
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x9838
callq 0x20e0
jmp 0x9838
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x99c6
movq %rbx, %rdi
callq 0x2170
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/playlist.cpp
// Function: Playlist::displayAllSongs(node*)
void Playlist::displayAllSongs(node* current) {
  // Condição de parada
  if (current == nullptr) {
    count = 1;
    return;
  }
  // Imprime a música atual
  cout << count << " - " << current->data.getTitle() << " - " << current->data.getArtist() << endl;
  ++count;
  // Chamada recursiva
  displayAllSongs(current->next);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
testq %rsi, %rsi
je 0x9952
movq %rsi, %r14
movq 0x30(%rbx), %rsi
movq 0x474d(%rip), %rdi      # 0xdfd0
callq 0x2070
movq %rax, %r15
leaq 0x793(%rip), %rsi       # 0xa025
movl $0x3, %edx
movq %rax, %rdi
callq 0x2120
leaq -0x60(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x99fc
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
leaq 0x75c(%rip), %rsi       # 0xa025
movl $0x3, %edx
movq %rax, %rdi
callq 0x2120
leaq -0x40(%rbp), %rdi
movq %r14, %rsi
callq 0x9a28
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
movq %r15, %rdi
callq 0x2120
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x20f0
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2080
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x992e
callq 0x20e0
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9940
callq 0x20e0
incq 0x30(%rbx)
movq 0x40(%r14), %rsi
movq %rbx, %rdi
callq 0x985a
jmp 0x995a
movq $0x1, 0x30(%rbx)
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9969
movq %rax, %rbx
jmp 0x9983
movq %rax, %rbx
leaq -0x30(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9983
callq 0x20e0
leaq -0x50(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9995
callq 0x20e0
movq %rbx, %rdi
callq 0x2170
nopl (%rax)
// File: /workspace/github_cpp_makefile_star2_O1/lorenatoscano[P]musify/src/utils.cpp
// Function: toLowercase(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
string toLowercase(string s) {
  string result = "";

  for (size_t i = 0; i < s.size(); i++) {
    result += tolower(s[i]);
  }
  
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x10(%rdi), %r15
movq %r15, (%rdi)
leaq 0x599(%rip), %rdx       # 0xa028
movq %rdx, %rsi
callq 0x3e72
cmpq $0x0, 0x8(%r14)
je 0x9ac2
xorl %r12d, %r12d
movq (%r14), %rax
movsbl (%rax,%r12), %edi
callq 0x2150
movsbl %al, %esi
movq %rbx, %rdi
callq 0x20c0
incq %r12
cmpq 0x8(%r14), %r12
jb 0x9aa1
movq %rbx, %rax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x9ade
callq 0x20e0
movq %r14, %rdi
callq 0x2170
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/./config.hpp
// Function: key_add_key(TKey*, unsigned char)
TKey *key_add_key(TKey *keys, KeyCode key)
{
    TKey *rval = keys;

    if (keys == NULL)
    {
        keys = new TKey;
        rval = keys;
    }
    else
    {
        while (keys->next != NULL) keys = keys->next;
        keys = (keys->next = new TKey);
    }

    keys->key = key;
    keys->next = NULL;

    return rval;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
testq %rdi, %rdi
je 0x25cb
movq %rdi, %r14
movq %rdi, %rax
movq %rax, %r15
movq 0x8(%rax), %rax
testq %rax, %rax
jne 0x25af
movl $0x10, %edi
callq 0x2140
movq %rax, 0x8(%r15)
jmp 0x25d8
movl $0x10, %edi
callq 0x2140
movq %rax, %r14
movb %bl, (%rax)
movq $0x0, 0x8(%rax)
movq %r14, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: debug(char const*, ...)
void debug(const char *fmt, ...) {
    if (app.debug) {
        va_list args;
        va_start(args, fmt);
        vfprintf(stdout, fmt, args);
        va_end(args);
    }
}

// Assembly:
subq $0xd8, %rsp
testb %al, %al
je 0x262d
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x48(%rsp)
cmpb $0x1, 0x3bfb(%rip)      # 0x6248
jne 0x2689
movq %rdi, %r10
leaq 0x20(%rsp), %rax
movq %rsp, %rdx
movq %rax, 0x10(%rdx)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rdx)
movq 0x3932(%rip), %rax      # 0x5fb0
movq (%rax), %rdi
movq %r10, %rsi
callq 0x21c0
addq $0xd8, %rsp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: TApplication::trigger_key(TModifierKey*)
void TApplication::trigger_key(TModifierKey* mod)
{
    for (auto keycode : mod->fake_keys)
    {
        ::debug("Generating %s!\n", XKeysymToString(sym_from_code(keycode)));

        XTestFakeKeyEvent(_ctrl_conn, keycode, True, 0);
        generated = key_add_key(generated, keycode);
    }
    for (auto keycode : mod->fake_keys)
    {
        XTestFakeKeyEvent(_ctrl_conn, keycode, False, 0);
        generated = key_add_key(generated, keycode);
    }
    XFlush(_ctrl_conn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x10(%rsi), %r12
movq 0x18(%rsi), %r13
cmpq %r13, %r12
je 0x2712
leaq 0x1969(%rip), %r15      # 0x4020
movzbl (%r12), %ebp
movq 0x3aed(%rip), %rdi      # 0x61b0
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x20b0
movq %rax, %rdi
callq 0x22b0
movq %r15, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x25eb
movq 0x8(%rbx), %rdi
movl %ebp, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x21a0
movq 0xd8(%rbx), %rdi
movl %ebp, %esi
callq 0x259d
movq %rax, 0xd8(%rbx)
incq %r12
cmpq %r13, %r12
jne 0x26b7
movq 0x10(%r14), %r15
movq 0x18(%r14), %r14
cmpq %r14, %r15
je 0x274c
movzbl (%r15), %ebp
movq 0x8(%rbx), %rdi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x21a0
movq 0xd8(%rbx), %rdi
movl %ebp, %esi
callq 0x259d
movq %rax, 0xd8(%rbx)
incq %r15
jmp 0x271a
movq 0x8(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2200
nop
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: TApplication::connect_x11()
void TApplication::connect_x11() {
    int dummy;
    _data_conn = XOpenDisplay(NULL);
    _ctrl_conn = XOpenDisplay(NULL);

    if (!_data_conn || !_ctrl_conn)
    {
        cerr << "Unable to connect to X11 display. Is $DISPLAY set?\n";
        exit(EXIT_FAILURE);
    }
    if (!XQueryExtension(_ctrl_conn,
                "XTEST", &dummy, &dummy, &dummy))
    {
        cerr << "Xtst extension missing\n";
        exit(EXIT_FAILURE);
    }
    if (!XRecordQueryVersion(_ctrl_conn, &dummy, &dummy))
    {
        cerr << "Failed to obtain xrecord version\n";
        exit(EXIT_FAILURE);
    }
    if (!XkbQueryExtension(_ctrl_conn, &dummy, &dummy,
            &dummy, &dummy, &dummy))
    {
        cerr << "Failed to obtain xkb version\n";
        exit(EXIT_FAILURE);
    }
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
xorl %edi, %edi
callq 0x21d0
movq %rax, (%rbx)
xorl %edi, %edi
callq 0x21d0
movq %rax, 0x8(%rbx)
cmpq $0x0, (%rbx)
je 0x27e3
testq %rax, %rax
je 0x27e3
leaq 0x18d1(%rip), %rsi      # 0x4064
leaq 0xc(%rsp), %rcx
movq %rax, %rdi
movq %rcx, %rdx
movq %rcx, %r8
callq 0x2060
testl %eax, %eax
je 0x27f3
movq 0x8(%rbx), %rdi
leaq 0xc(%rsp), %rdx
movq %rdx, %rsi
callq 0x2280
testl %eax, %eax
je 0x2803
movq 0x8(%rbx), %rdi
leaq 0xc(%rsp), %rcx
movq %rcx, %rsi
movq %rcx, %rdx
movq %rcx, %r8
movq %rcx, %r9
callq 0x2110
testl %eax, %eax
je 0x2813
addq $0x10, %rsp
popq %rbx
retq
movq 0x3806(%rip), %rdi      # 0x5ff0
leaq 0x183f(%rip), %rsi      # 0x4030
jmp 0x2821
movq 0x37f6(%rip), %rdi      # 0x5ff0
leaq 0x1869(%rip), %rsi      # 0x406a
jmp 0x2821
movq 0x37e6(%rip), %rdi      # 0x5ff0
leaq 0x1871(%rip), %rsi      # 0x4082
jmp 0x2821
movq 0x37d6(%rip), %rdi      # 0x5ff0
leaq 0x1883(%rip), %rsi      # 0x40a4
callq 0x2130
movl $0x1, %edi
callq 0x2190
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: TApplication::hook_x11()
void TApplication::hook_x11() {
    XRecordRange *rec_range = XRecordAllocRange();
    rec_range->device_events.first = KeyPress;
    rec_range->device_events.last = ButtonRelease;
    XRecordClientSpec client_spec = XRecordAllClients;

    _record_ctx = XRecordCreateContext(_ctrl_conn,
            0, &client_spec, 1, &rec_range, 1);

    if (_record_ctx == 0)
    {
        cerr << "Failed to create xrecord context\n";
        exit(EXIT_FAILURE);
    }

    XSync(_ctrl_conn, False);

    if (!XRecordEnableContext(_data_conn,
                _record_ctx, intercept, (XPointer)&app))
    {
        cerr << "Failed to enable xrecord context\n";
        exit(EXIT_FAILURE);
    }

    if (!XRecordFreeContext(_ctrl_conn, _record_ctx))
    {
        cerr << "Failed to free xrecord context\n";
    }
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
callq 0x22f0
leaq 0x8(%rsp), %r8
movq %rax, (%r8)
movw $0x502, 0x12(%rax)      # imm = 0x502
movq %rsp, %rdx
movq $0x3, (%rdx)
movq 0x8(%rbx), %rdi
xorl %esi, %esi
movl $0x1, %ecx
movl $0x1, %r9d
callq 0x2250
movq %rax, 0x10(%rbx)
testq %rax, %rax
je 0x28cc
movq 0x8(%rbx), %rdi
xorl %esi, %esi
callq 0x22d0
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
leaq 0x6c(%rip), %rdx        # 0x28f9
leaq 0x3914(%rip), %rcx      # 0x61a8
callq 0x2220
testl %eax, %eax
je 0x28dc
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x20d0
testl %eax, %eax
jne 0x28c6
movq 0x373b(%rip), %rdi      # 0x5ff0
leaq 0x184a(%rip), %rsi      # 0x4106
movl $0x1f, %edx
callq 0x2160
addq $0x10, %rsp
popq %rbx
retq
movq 0x371d(%rip), %rdi      # 0x5ff0
leaq 0x17e8(%rip), %rsi      # 0x40c2
jmp 0x28ea
movq 0x370d(%rip), %rdi      # 0x5ff0
leaq 0x17fa(%rip), %rsi      # 0x40e4
callq 0x2130
movl $0x1, %edi
callq 0x2190
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: handle_modifier(TModifierKey*, bool, int)
void handle_modifier(TModifierKey* mod, bool mouse_pressed, int key_event)
{
    if (key_event == KeyPress)
    {
        debug("Key pressed!\n");
        mod->is_down = True;

        if (app.timeout_valid)
            gettimeofday(&mod->down_at, NULL);

        if (mouse_pressed)
        {
            mod->used = True;
        }

        // testing heuristic 1
        if (heuristic_test1(mod)) {
            // if heuristic func returns true this means user probably wants
            // the key itself (space) not the modifier.
            app.trigger_key(mod);
            mod->used = true;
        }
    }
    else
    {
        debug("Key released!\n");
        if (!mod->used)
        {
            timeval down_time = app.timeout;
            if (app.timeout_valid)
            {
                gettimeofday(&down_time, NULL);
                timersub(&down_time, &mod->down_at, &down_time);
            }

            if (!app.timeout_valid ||
                timercmp(&down_time, &app.timeout, <))
            {
                // so a modifier key was pressed shortly.
                // generate fake keys (actually... press and release events).
                app.trigger_key(mod);
            }
        }
        mod->used = False;
        mod->is_down = False;
    }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
cmpl $0x2, %edx
jne 0x2b0f
movl %esi, %ebp
leaq 0x16a6(%rip), %rdi      # 0x4168
xorl %eax, %eax
callq 0x25eb
movb $0x1, 0x29(%rbx)
cmpb $0x1, 0x37c4(%rip)      # 0x6298
jne 0x2ae1
leaq 0x30(%rbx), %rdi
xorl %esi, %esi
callq 0x2230
testb %bpl, %bpl
je 0x2aea
movb $0x1, 0x28(%rbx)
callq 0x2c78
testb %al, %al
je 0x2ba7
leaq 0x36aa(%rip), %rdi      # 0x61a8
movq %rbx, %rsi
callq 0x2692
movb $0x1, 0x28(%rbx)
jmp 0x2ba7
leaq 0x1660(%rip), %rdi      # 0x4176
xorl %eax, %eax
callq 0x25eb
cmpb $0x0, 0x28(%rbx)
jne 0x2ba1
movups 0x375e(%rip), %xmm0     # 0x6288
movaps %xmm0, (%rsp)
cmpb $0x1, 0x3763(%rip)      # 0x6298
jne 0x2b6e
movq %rsp, %r14
movq %r14, %rdi
xorl %esi, %esi
callq 0x2230
movq (%r14), %rcx
movq 0x8(%r14), %rax
subq 0x30(%rbx), %rcx
movq %rcx, (%r14)
subq 0x38(%rbx), %rax
movq %rax, 0x8(%r14)
jns 0x2b6e
decq %rcx
movq %rcx, (%rsp)
addq $0xf4240, %rax          # imm = 0xF4240
movq %rax, 0x8(%rsp)
cmpb $0x1, 0x3723(%rip)      # 0x6298
jne 0x2b92
movq 0x370a(%rip), %rax      # 0x6288
cmpq %rax, (%rsp)
jne 0x2b90
movq 0x8(%rsp), %rax
cmpq 0x3700(%rip), %rax      # 0x6290
jge 0x2ba1
leaq 0x360f(%rip), %rdi      # 0x61a8
movq %rbx, %rsi
callq 0x2692
movw $0x0, 0x28(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/utkukaratas[P]xkeylayers/xkeylayers.cpp
// Function: sig_handler(void*)
void* sig_handler(void *user_data)
{
    TApplication *self = (TApplication*)user_data;
    int sig;

    debug("sig_handler running...\n");

    sigwait(&self->_sigset, &sig);

    debug("Caught signal %d!\n", sig);

    if (!XRecordDisableContext(self->_ctrl_conn, self->_record_ctx))
    {
        fprintf(stderr, "Failed to disable xrecord context\n");
        exit(EXIT_FAILURE);
    }

    XSync(self->_ctrl_conn, False);

    debug("sig_handler exiting...\n");

    return NULL;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x143d(%rip), %rdi      # 0x4185
xorl %eax, %eax
callq 0x25eb
leaq 0x20(%rbx), %rdi
leaq 0x4(%rsp), %r14
movq %r14, %rsi
callq 0x2070
movl (%r14), %esi
leaq 0x1433(%rip), %rdi      # 0x419d
xorl %eax, %eax
callq 0x25eb
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x2260
testl %eax, %eax
je 0x2da5
movq 0x8(%rbx), %rdi
xorl %esi, %esi
callq 0x22d0
leaq 0x143f(%rip), %rdi      # 0x41d3
xorl %eax, %eax
callq 0x25eb
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x2310
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: set_op_rep_device(_USB_DEVICE_DESCRIPTOR const&, _USB_CONFIGURATION_DESCRIPTOR const&, _OP_REP_DEVICE*)
void set_op_rep_device(const USB_DEVICE_DESCRIPTOR& dev_dsc,
                       const USB_CONFIGURATION_DESCRIPTOR& config,
                       OP_REP_DEVICE* device) {
  // Set constants.
  memset(device->usbPath, 0, 256);
  strcpy(device->usbPath, kUsbPath);
  memset(device->busID, 0, 32);
  strcpy(device->busID, kBusId);

  device->busnum=htonl(1);
  device->devnum=htonl(2);
  device->speed=htonl(2);

  // Set values using |device|.
  device->idVendor = htons(dev_dsc.idVendor);
  device->idProduct = htons(dev_dsc.idProduct);
  device->bcdDevice = htons(dev_dsc.bcdDevice);
  device->bDeviceClass = dev_dsc.bDeviceClass;
  device->bDeviceSubClass = dev_dsc.bDeviceSubClass;
  device->bDeviceProtocol = dev_dsc.bDeviceProtocol;
  device->bNumConfigurations = dev_dsc.bNumConfigurations;

  // Set values using |config|.
  device->bConfigurationValue = config.bConfigurationValue;
  device->bNumInterfaces = config.bNumInterfaces;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x2e(%rdx), %rdi
movl $0xd2, %edx
xorl %esi, %esi
callq 0x1110
movaps 0x2b62(%rip), %xmm0     # 0x4010
movups %xmm0, (%rbx)
movaps 0x2b68(%rip), %xmm0     # 0x4020
movups %xmm0, 0x10(%rbx)
movups 0x2b6b(%rip), %xmm0     # 0x402e
movups %xmm0, 0x1e(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x100(%rbx)
movups %xmm0, 0x110(%rbx)
movl $0x312d31, 0x100(%rbx)  # imm = 0x312D31
movabsq $0x200000001000000, %rax # imm = 0x200000001000000
movq %rax, 0x120(%rbx)
movl $0x2000000, 0x128(%rbx) # imm = 0x2000000
movzwl 0x8(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x12c(%rbx)
movzwl 0xa(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x12e(%rbx)
movzwl 0xc(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x130(%rbx)
movb 0x4(%r15), %al
movb %al, 0x132(%rbx)
movb 0x5(%r15), %al
movb %al, 0x133(%rbx)
movb 0x6(%r15), %al
movb %al, 0x134(%rbx)
movb 0x11(%r15), %al
movb %al, 0x136(%rbx)
movb 0x5(%r14), %al
movb %al, 0x135(%rbx)
movb 0x4(%r14), %al
movb %al, 0x137(%rbx)
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: set_op_rep_devlist_interfaces(std::vector<_USB_INTERFACE_DESCRIPTOR, std::allocator<_USB_INTERFACE_DESCRIPTOR>> const&, _OP_REP_DEVLIST_INTERFACE**)
void set_op_rep_devlist_interfaces(
    const std::vector<USB_INTERFACE_DESCRIPTOR>& interfaces,
    OP_REP_DEVLIST_INTERFACE **rep_interfaces) {
  // TODO(daviev): Change this to use a smart pointer at some point.
  *rep_interfaces = (OP_REP_DEVLIST_INTERFACE *)malloc(
      interfaces.size() * sizeof(OP_REP_DEVLIST_INTERFACE));
  for (size_t i = 0; i < interfaces.size(); ++i) {
    const auto& interface = interfaces[i];
    (*rep_interfaces)[i].bInterfaceClass = interface.bInterfaceClass;
    (*rep_interfaces)[i].bInterfaceSubClass = interface.bInterfaceSubClass;
    (*rep_interfaces)[i].bInterfaceProtocol = interface.bInterfaceProtocol;
    (*rep_interfaces)[i].padding = 0;
  }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rax
subq (%rdi), %rax
movabsq $0x38e38e38e38e38e4, %rdi # imm = 0x38E38E38E38E38E4
imulq %rax, %rdi
callq 0x11c0
movq %rax, (%rbx)
movq (%r14), %rcx
movq 0x8(%r14), %rdx
subq %rcx, %rdx
je 0x15e8
movabsq $-0x71c71c71c71c71c7, %rsi # imm = 0x8E38E38E38E38E39
imulq %rsi, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
addq $0x7, %rcx
xorl %esi, %esi
movb -0x2(%rcx), %dil
movb %dil, (%rax,%rsi,4)
movb -0x1(%rcx), %dil
movb %dil, 0x1(%rax,%rsi,4)
movb (%rcx), %dil
movb %dil, 0x2(%rax,%rsi,4)
movb $0x0, 0x3(%rax,%rsi,4)
incq %rsi
addq $0x9, %rcx
cmpq %rsi, %rdx
jne 0x15be
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: handle_attach(UsbPrinter const&, int)
int handle_attach(const UsbPrinter& printer, int sockfd) {
  char busid[32];
  OP_REP_IMPORT rep;
  printf("attach device\n");
  ssize_t received = recv(sockfd, busid, 32, 0);
  if (received != 32) {
    printf("receive error : %s \n", strerror(errno));
    return 1;
  }
  create_op_rep_import(printer.device_descriptor(),
                       printer.configuration_descriptor(), &rep);
  ssize_t sent = send(sockfd, &rep, sizeof(rep), 0);
  if (sent != sizeof(rep)) {
    printf("send error : %s \n", strerror(errno));
    return 1;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %esi, %ebp
movq %rdi, %r14
leaq 0x2921(%rip), %rdi      # 0x418e
callq 0x11f0
leaq 0x10(%rsp), %rsi
xorl %ebx, %ebx
movl $0x20, %edx
movl %ebp, %edi
xorl %ecx, %ecx
callq 0x10a0
cmpq $0x20, %rax
jne 0x19c8
movzwl 0x4(%r14), %eax
movw %ax, 0xe(%rsp)
movb 0x6(%r14), %al
movb %al, 0xd(%rsp)
movzwl 0x8(%r14), %r12d
movzwl 0xa(%r14), %r15d
movzwl 0xc(%r14), %r13d
movb 0x11(%r14), %al
movb %al, 0xb(%rsp)
movb 0x16(%r14), %al
movb %al, 0xc(%rsp)
movb 0x17(%r14), %al
movb %al, 0xa(%rsp)
leaq 0x6e(%rsp), %r14
movq $0x3001101, -0x36(%r14) # imm = 0x3001101
movl $0xd2, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x1110
movaps 0x2723(%rip), %xmm0     # 0x4010
movups %xmm0, -0x2e(%r14)
movaps 0x2727(%rip), %xmm0     # 0x4020
movups %xmm0, -0x1e(%r14)
movups 0x2729(%rip), %xmm0     # 0x402e
movups %xmm0, -0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0xd2(%r14)
movups %xmm0, 0xe2(%r14)
movl $0x312d31, 0xd2(%r14) # imm = 0x312D31
movabsq $0x200000001000000, %rax # imm = 0x200000001000000
movq %rax, 0xf2(%r14)
movl $0x2000000, 0xfa(%r14) # imm = 0x2000000
rolw $0x8, %r12w
movw %r12w, 0xfe(%r14)
rolw $0x8, %r15w
movw %r15w, 0x100(%r14)
rolw $0x8, %r13w
movw %r13w, 0x102(%r14)
movzwl 0xe(%rsp), %eax
movw %ax, 0x104(%r14)
movb 0xd(%rsp), %al
movb %al, 0x106(%r14)
movb 0xb(%rsp), %al
movb %al, 0x108(%r14)
movb 0xa(%rsp), %al
movb %al, 0x107(%r14)
movb 0xc(%rsp), %al
movb %al, 0x109(%r14)
leaq 0x38(%rsp), %rsi
movl $0x140, %edx            # imm = 0x140
movl %ebp, %edi
xorl %ecx, %ecx
callq 0x10f0
cmpq $0x140, %rax            # imm = 0x140
je 0x19ed
leaq 0x2678(%rip), %rbx      # 0x403e
jmp 0x19cf
leaq 0x2681(%rip), %rbx      # 0x4050
callq 0x1040
movl (%rax), %edi
callq 0x10b0
movq %rbx, %rdi
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
movl $0x1, %ebx
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: pack_usbip(int*, unsigned long)
void pack_usbip(int *data, size_t msg_size) {
  int size = msg_size / 4;
  for (int i = 0; i < size; i++) {
    data[i] = htonl(data[i]);
  }
  // Put |setup| into network byte order. Since |setup| is a 64-bit integer we
  // have to swap the final 2 int entries since they are both a part of |setup|.
  swap(&data[size - 1], &data[size - 2]);
}

// Assembly:
shrq $0x2, %rsi
testl %esi, %esi
jle 0x1a2b
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movl (%rdi,%rcx,4), %edx
bswapl %edx
movl %edx, (%rdi,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x1a1b
shlq $0x20, %rsi
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rsi, %rax
sarq $0x1e, %rax
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %rsi, %rcx
sarq $0x1e, %rcx
movl (%rdi,%rax), %edx
movl (%rdi,%rcx), %esi
movl %esi, (%rdi,%rax)
movl %edx, (%rdi,%rcx)
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: unpack_usbip(int*, unsigned long)
void unpack_usbip(int *data, size_t msg_size) {
  int size = msg_size / 4;
  for (int i = 0; i < size; i++) {
    data[i] = ntohl(data[i]);
  }
  // Put |setup| into host byte order. Since |setup| is a 64-bit integer we
  // have to swap the final 2 int entries since they are both a part of |setup|.
  swap(&data[size - 1], &data[size - 2]);
}

// Assembly:
shrq $0x2, %rsi
testl %esi, %esi
jle 0x1a7f
movl %esi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movl (%rdi,%rcx,4), %edx
bswapl %edx
movl %edx, (%rdi,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x1a6f
shlq $0x20, %rsi
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rsi, %rax
sarq $0x1e, %rax
movabsq $-0x200000000, %rcx     # imm = 0xFFFFFFFE00000000
addq %rsi, %rcx
sarq $0x1e, %rcx
movl (%rdi,%rax), %edx
movl (%rdi,%rcx), %esi
movl %esi, (%rdi,%rax)
movl %edx, (%rdi,%rcx)
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: print_usbip_cmd_submit(_USBIP_CMD_SUBMIT const&)
void print_usbip_cmd_submit(const USBIP_CMD_SUBMIT& command) {
  printf("usbip cmd %u\n", command.command);
  printf("usbip seqnum %u\n", command.seqnum);
  printf("usbip devid %u\n", command.devid);
  printf("usbip direction %u\n", command.direction);
  printf("usbip ep %u\n", command.ep);
  printf("usbip flags %u\n", command.transfer_flags);
  printf("usbip number of packets %u\n", command.number_of_packets);
  printf("usbip interval %u\n", command.interval);
  printf("usbip setup %llu\n", command.setup);
  printf("usbip buffer length  %u\n", command.transfer_buffer_length);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl (%rdi), %esi
leaq 0x25a6(%rip), %rdi      # 0x4065
xorl %eax, %eax
callq 0x1050
movl 0x4(%rbx), %esi
leaq 0x25a3(%rip), %rdi      # 0x4073
xorl %eax, %eax
callq 0x1050
movl 0x8(%rbx), %esi
leaq 0x25a3(%rip), %rdi      # 0x4084
xorl %eax, %eax
callq 0x1050
movl 0xc(%rbx), %esi
leaq 0x25a2(%rip), %rdi      # 0x4094
xorl %eax, %eax
callq 0x1050
movl 0x10(%rbx), %esi
leaq 0x25a5(%rip), %rdi      # 0x40a8
xorl %eax, %eax
callq 0x1050
movl 0x14(%rbx), %esi
leaq 0x25a1(%rip), %rdi      # 0x40b5
xorl %eax, %eax
callq 0x1050
movl 0x20(%rbx), %esi
leaq 0x25a0(%rip), %rdi      # 0x40c5
xorl %eax, %eax
callq 0x1050
movl 0x24(%rbx), %esi
leaq 0x25ab(%rip), %rdi      # 0x40e1
xorl %eax, %eax
callq 0x1050
movq 0x28(%rbx), %rsi
leaq 0x25ac(%rip), %rdi      # 0x40f4
xorl %eax, %eax
callq 0x1050
movl 0x18(%rbx), %esi
leaq 0x25ad(%rip), %rdi      # 0x4106
xorl %eax, %eax
popq %rbx
jmp 0x1050
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: print_standard_device_request(_StandardDeviceRequest const&)
void print_standard_device_request(const StandardDeviceRequest& request) {
  printf("  UC Request Type %u\n", request.bmRequestType);
  printf("  UC Request %u\n", request.bRequest);
  printf("  UC Value  %u[%u]\n", request.wValue1, request.wValue0);
  printf("  UC Index  %u-%u\n", request.wIndex1, request.wIndex0);
  printf("  UC Length %u\n", request.wLength);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movzbl (%rdi), %esi
leaq 0x25b0(%rip), %rdi      # 0x411f
xorl %eax, %eax
callq 0x1050
movzbl 0x1(%rbx), %esi
leaq 0x25b4(%rip), %rdi      # 0x4135
xorl %eax, %eax
callq 0x1050
movzbl 0x3(%rbx), %esi
movzbl 0x2(%rbx), %edx
leaq 0x25af(%rip), %rdi      # 0x4146
xorl %eax, %eax
callq 0x1050
movzbl 0x5(%rbx), %esi
movzbl 0x4(%rbx), %edx
leaq 0x25ad(%rip), %rdi      # 0x415a
xorl %eax, %eax
callq 0x1050
movzwl 0x6(%rbx), %esi
leaq 0x25ae(%rip), %rdi      # 0x416d
xorl %eax, %eax
popq %rbx
jmp 0x1050
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: create_usbip_ret_submit(_USBIP_CMD_SUBMIT const*)
USBIP_RET_SUBMIT create_usbip_ret_submit(const USBIP_CMD_SUBMIT *command) {
  USBIP_RET_SUBMIT usb_req;
  memset(&usb_req, 0, sizeof(usb_req));
  usb_req.seqnum = command->seqnum;
  usb_req.devid = command->devid;
  usb_req.direction = command->direction;
  usb_req.ep = command->ep;
  usb_req.setup = command->setup;
  return usb_req;
}

// Assembly:
movq %rdi, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movups %xmm0, (%rdi)
movl 0x4(%rsi), %ecx
movl %ecx, 0x4(%rdi)
movl 0x8(%rsi), %ecx
movl %ecx, 0x8(%rdi)
movl 0xc(%rsi), %ecx
movl %ecx, 0xc(%rdi)
movl 0x10(%rsi), %ecx
movl %ecx, 0x10(%rdi)
movq 0x28(%rsi), %rcx
movq %rcx, 0x28(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: CreateUsbipRetSubmit(_USBIP_CMD_SUBMIT const&)
USBIP_RET_SUBMIT CreateUsbipRetSubmit(const USBIP_CMD_SUBMIT& request) {
  USBIP_RET_SUBMIT response;
  memset(&response, 0, sizeof(response));
  response.command = COMMAND_USBIP_RET_SUBMIT;
  response.seqnum = request.seqnum;
  response.devid = request.devid;
  response.direction = request.direction;
  response.ep = request.ep;
  return response;
}

// Assembly:
movq %rdi, %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, 0x10(%rdi)
movl $0x3, (%rdi)
movl 0x4(%rsi), %ecx
movl %ecx, 0x4(%rdi)
movl 0x8(%rsi), %ecx
movl %ecx, 0x8(%rdi)
movl 0xc(%rsi), %ecx
movl %ecx, 0xc(%rdi)
movl 0x10(%rsi), %ecx
movl %ecx, 0x10(%rdi)
retq
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usbip.cc
// Function: SendUsbRequest(int, _USBIP_CMD_SUBMIT const&, char const*, unsigned int, unsigned int)
void SendUsbRequest(int sockfd, const USBIP_CMD_SUBMIT& usb_request,
                    const char* data, unsigned int data_size,
                    unsigned int status) {
  USBIP_RET_SUBMIT response = CreateUsbipRetSubmit(usb_request);
  response.status = status;
  response.actual_length = data_size;
  response.start_frame = 0;
  // TODO(daviev): Figure out what this means.
  response.number_of_packets = 0;
  response.error_count = 0;

  if (data_size > 0) {
    printf("Sending buffer: \n");
    for (int i = 0; i < data_size; ++i) {
      printf("%u ", data[i]);
    }
    printf("\n");
  }

  size_t response_size = sizeof(response);
  pack_usbip((int*)&response, response_size);

  if (send(sockfd, (char*)&response, response_size, 0) != response_size) {
    printf("send error : %s \n", strerror(errno));
    exit(-1);
  }

  // Skip sending data if there isn't any.
  if (data_size == 0) {
    return;
  }

  if (send(sockfd, data, data_size, 0) != data_size) {
    printf("send error : %s \n", strerror(errno));
    exit(-1);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %r14d
movq %rdx, %rbx
movl %edi, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x3, (%rsp)
movl 0x4(%rsi), %eax
movl %eax, 0x4(%rsp)
movl 0x8(%rsi), %eax
movl %eax, 0x8(%rsp)
movl 0xc(%rsi), %eax
movl %eax, 0xc(%rsp)
movl 0x10(%rsi), %eax
movl %eax, 0x10(%rsp)
movl %r8d, 0x14(%rsp)
movl %ecx, 0x18(%rsp)
movq $0x0, 0x1c(%rsp)
movl $0x0, 0x24(%rsp)
movl %ecx, %r15d
testl %ecx, %ecx
je 0x1ccb
leaq 0x2501(%rip), %rdi      # 0x419c
callq 0x11f0
leaq 0x24d6(%rip), %r12      # 0x417d
xorl %r13d, %r13d
movsbl (%rbx,%r13), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x1050
incq %r13
cmpq %r13, %r15
jne 0x1caa
movl $0xa, %edi
callq 0x11d0
xorl %eax, %eax
movl (%rsp,%rax,4), %ecx
bswapl %ecx
movl %ecx, (%rsp,%rax,4)
incq %rax
cmpq $0xc, %rax
jne 0x1ccd
movq %rsp, %rsi
rolq $0x20, 0x28(%rsi)
movl $0x30, %edx
movl %ebp, %edi
xorl %ecx, %ecx
callq 0x10f0
cmpq $0x30, %rax
jne 0x1d22
testl %r14d, %r14d
je 0x1d13
movl %ebp, %edi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x10f0
cmpq %r15, %rax
jne 0x1d22
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1040
movl (%rax), %edi
callq 0x10b0
leaq 0x2309(%rip), %rdi      # 0x403e
movq %rax, %rsi
xorl %eax, %eax
callq 0x1050
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x11a0
nop
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usb_printer.cc
// Function: UsbPrinter::HandleUsbRequest(int, _USBIP_CMD_SUBMIT const&)
void UsbPrinter::HandleUsbRequest(int sockfd,
                                  const USBIP_CMD_SUBMIT& usb_request) {
  // Endpoint 0 is used for USB control requests.
  if (usb_request.ep == 0) {
    printf("# control requests\n");
    HandleUsbControl(sockfd, usb_request);
  } else {
    printf("# data requests\n");
  }
}

// Assembly:
cmpl $0x0, 0x10(%rdx)
je 0x1ec6
leaq 0x2451(%rip), %rdi      # 0x4312
jmp 0x11f0
pushq %rbp
pushq %r14
pushq %rbx
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x2449(%rip), %rdi      # 0x4322
callq 0x11f0
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
popq %rbx
popq %r14
popq %rbp
jmp 0x1ef0
nop
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usb_printer.cc
// Function: UsbPrinter::HandleUsbControl(int, _USBIP_CMD_SUBMIT const&)
void UsbPrinter::HandleUsbControl(int sockfd,
                                  const USBIP_CMD_SUBMIT& usb_request) {
  StandardDeviceRequest control_request =
      CreateStandardDeviceRequest(usb_request.setup);
  print_standard_device_request(control_request);
  int request_type = GetControlType(control_request.bmRequestType);
  switch (request_type) {
    case STANDARD_TYPE:
      HandleStandardControl(sockfd, usb_request, control_request);
      break;
    case CLASS_TYPE:
      HandlePrinterControl(sockfd, usb_request, control_request);
      break;
    case VENDOR_TYPE:
    case RESERVED_TYPE:
    default:
      printf("Unable to handle request of type %d\n", request_type);
      break;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
movq 0x28(%rdx), %rax
bswapq %rax
movq %rsp, %r15
movq %rax, (%r15)
movq %r15, %rdi
callq 0x1b61
movl (%r15), %esi
shrl $0x5, %esi
andl $0x3, %esi
cmpl $0x1, %esi
je 0x1f38
testl %esi, %esi
jne 0x1f4a
movq %rsp, %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x1f64
jmp 0x1f58
movq %rsp, %rcx
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x200c
jmp 0x1f58
leaq 0x228f(%rip), %rdi      # 0x41e0
xorl %eax, %eax
callq 0x1050
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop
// File: /workspace/github_cpp_makefile_star2_O1/DavieV[P]virtual-usb-printer/usb_printer.cc
// Function: UsbPrinter::HandleStandardControl(int, _USBIP_CMD_SUBMIT const&, _StandardDeviceRequest const&)
void UsbPrinter::HandleStandardControl(
    int sockfd, const USBIP_CMD_SUBMIT& usb_request,
    const StandardDeviceRequest& control_request) {
  switch (control_request.bRequest) {
    case GET_STATUS:
      break;
    case GET_DESCRIPTOR:
      HandleGetDescriptor(sockfd, usb_request, control_request);
      break;
    case SET_DESCRIPTOR:
      break;
    case GET_CONFIGURATION:
      HandleGetConfiguration(sockfd, usb_request, control_request);
      break;
    case SET_CONFIGURATION:
      HandleSetConfiguration(sockfd, usb_request, control_request);
      break;
    case GET_INTERFACE:
      // Support for this will be needed for interfaces with alt settings.
      break;
    case SET_INTERFACE:
      HandleSetInterface(sockfd, usb_request, control_request);
      break;
    default:
      break;
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movzbl 0x1(%rcx), %eax
addl $-0x6, %eax
cmpl $0x5, %eax
ja 0x2006
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
leaq 0x2229(%rip), %rdx      # 0x41b0
movslq (%rdx,%rax,4), %rax
addq %rdx, %rax
jmpq *%rax
movq %r14, %rdi
movl %ebp, %esi
movq %rbx, %rdx
popq %rbx
popq %r14
popq %rbp
jmp 0x2030
movzbl 0x3(%rcx), %esi
movzbl 0x2(%rcx), %edx
leaq 0x230e(%rip), %rdi      # 0x42be
jmp 0x1fea
movzbl 0x3(%rcx), %esi
movzbl 0x2(%rcx), %edx
leaq 0x22de(%rip), %rdi      # 0x429f
xorl %eax, %eax
callq 0x1050
addq $0x17, %r14
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x1, %ecx
jmp 0x1ffa
movzbl 0x3(%rcx), %esi
movzbl 0x2(%rcx), %edx
leaq 0x22f3(%rip), %rdi      # 0x42dd
xorl %eax, %eax
callq 0x1050
movl %ebp, %edi
movq %rbx, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
popq %rbx
popq %r14
popq %rbp
jmp 0x1c29
popq %rbx
popq %r14
popq %rbp
retq
nop