decompiled_code:
__int64 __fastcall get_status_msg(int a1, __int64 a2)
{
__int64 result; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8184) = 0LL;
result = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 0x2000) >> 3));
if ( a1 == 404 )
{
result = 0x6E756F4620746F4ELL;
strcpy((char *)a2, "Not Found");
return result;
}
if ( a1 <= 404 )
{
if ( a1 == 400 )
{
result = 0x7571655220646142LL;
strcpy((char *)a2, "Bad Request");
return result;
}
if ( a1 <= 400 )
{
if ( a1 == 200 )
{
strcpy((char *)a2, "OK");
return result;
}
if ( a1 == 304 )
{
result = 0x69646F4D20746F4ELL;
strcpy((char *)a2, "Not Modified");
return result;
}
}
else if ( a1 == 403 )
{
result = 0x6564646962726F46LL;
strcpy((char *)a2, "Forbidden");
return result;
}
}
else
{
if ( a1 == 505 )
{
result = 0x206E6F6973726556LL;
strcpy((char *)a2, "Version Not Support");
return result;
}
if ( a1 <= 505 )
{
if ( a1 == 408 )
{
result = 0x2074736575716552LL;
strcpy((char *)a2, "Request Timeout");
return result;
}
if ( a1 == 501 )
{
result = 0x6C706D4920746F4ELL;
strcpy((char *)a2, "Not Implemented");
return result;
}
}
else if ( a1 == 522 )
{
result = 0x697463656E6E6F43LL;
strcpy((char *)a2, "Connection Timed Out");
return result;
}
}
result = 0x6E676F6365726E55LL;
strcpy((char *)a2, "Unrecognized Statues");
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2)
{
__int64 result; // rax

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8184) = 0LL;
result = 0LL;
memset(
(void *)((a2 + 8) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((unsigned int)a2 - (((_DWORD)a2 + 8) & 0xFFFFFFF8) + 0x2000) >> 3));
if ( a1 == 404 )
{
result = 0x6E756F4620746F4ELL;
strcpy((char *)a2, "Not Found");
return result;
}
if ( a1 <= 404 )
{
if ( a1 == 400 )
{
result = 0x7571655220646142LL;
strcpy((char *)a2, "Bad Request");
return result;
}
if ( a1 <= 400 )
{
if ( a1 == 200 )
{
strcpy((char *)a2, "OK");
return result;
}
if ( a1 == 304 )
{
result = 0x69646F4D20746F4ELL;
strcpy((char *)a2, "Not Modified");
return result;
}
}
else if ( a1 == 403 )
{
result = 0x6564646962726F46LL;
strcpy((char *)a2, "Forbidden");
return result;
}
}
else
{
if ( a1 == 505 )
{
result = 0x206E6F6973726556LL;
strcpy((char *)a2, "Version Not Support");
return result;
}
if ( a1 <= 505 )
{
if ( a1 == 408 )
{
result = 0x2074736575716552LL;
strcpy((char *)a2, "Request Timeout");
return result;
}
if ( a1 == 501 )
{
result = 0x6C706D4920746F4ELL;
strcpy((char *)a2, "Not Implemented");
return result;
}
}
else if ( a1 == 522 )
{
result = 0x697463656E6E6F43LL;
strcpy((char *)a2, "Connection Timed Out");
return result;
}
}
result = 0x6E676F6365726E55LL;
strcpy((char *)a2, "Unrecognized Statues");
return result;
}

original_code:
void get_status_msg(int code, char msg[]) {
    bzero(msg, 8192);
    switch(code){
    case 200:
        strcpy(msg, "OK");
        break;
    case 304:
        strcpy(msg,"Not Modified");
        break;
    case 400:
        strcpy(msg, "Bad Request");
        break;
    case 403:
        strcpy(msg, "Forbidden");
        break;
    case 404:
        strcpy(msg, "Not Found");
        break;
    case 408:
        strcpy(msg, "Request Timeout");
        break;
    case 501:
        strcpy(msg, "Not Implemented");
        break;
    case 505:
        strcpy(msg, "Version Not Support");
        break;
    case 522:
        strcpy(msg, "Connection Timed Out");
        break;
    default:
        strcpy(msg, "Unrecognized Statues");
        break;
    }
}

variable_types: code int

variable_types:
msg
char []


repo: Wilbeibi/sws

decompiled_code:
size_t __fastcall err_response(unsigned int a1, unsigned int a2)
{
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
char v10[256]; // [rsp+0h] [rbp-6118h] BYREF
char v11[8192]; // [rsp+100h] [rbp-6018h] BYREF
char s[8192]; // [rsp+2100h] [rbp-4018h] BYREF
char v13[8216]; // [rsp+4100h] [rbp-2018h] BYREF

get_status_msg(a2, (__int64)v11);
strcpy(s, "<!DOCTYPE html><title>SWS Response</title>\r\n");
sprintf(s, "%s%d: %s\r\n", s, a2, v11);
sprintf(s, "%s May the force be with you.\r\n", s);
if ( simple_response != 1 )
{
sprintf(v13, "HTTP/1.0 %d %s\r\n", a2, v11);
v3 = strlen(v13);
Send(a1, v13, v3, 0LL);
get_timestamp(v10);
sprintf(v13, "Date: %s\r\n", v10);
v4 = strlen(v13);
Send(a1, v13, v4, 0LL);
strcpy(v13, "Server: Four0Four\r\n");
v5 = strlen(v13);
Send(a1, v13, v5, 0LL);
strcpy(v13, "Content-type: text/html\r\n");
v6 = strlen(v13);
Send(a1, v13, v6, 0LL);
v7 = strlen(s);
sprintf(v13, "Content-length: %d\r\n\r\n", v7);
v8 = strlen(v13);
Send(a1, v13, v8, 0LL);
}
if ( head_response != 1 )
{
v9 = strlen(s);
Send(a1, s, v9, 0LL);
}
return strlen(s);
}

canonical_decompiled_code:
size_t __fastcall func2(unsigned int a1, unsigned int a2)
{
size_t v3; // rax
size_t v4; // rax
size_t v5; // rax
size_t v6; // rax
size_t v7; // rax
size_t v8; // rax
size_t v9; // rax
char v10[256]; // [rsp+0h] [rbp-6118h] BYREF
char v11[8192]; // [rsp+100h] [rbp-6018h] BYREF
char s[8192]; // [rsp+2100h] [rbp-4018h] BYREF
char v13[8216]; // [rsp+4100h] [rbp-2018h] BYREF

func1(a2, (__int64)v11);
strcpy(s, "<!DOCTYPE html><title>SWS Response</title>\r\n");
sprintf(s, "%s%d: %s\r\n", s, a2, v11);
sprintf(s, "%s May the force be with you.\r\n", s);
if ( simple_response != 1 )
{
sprintf(v13, "HTTP/1.0 %d %s\r\n", a2, v11);
v3 = strlen(v13);
Send(a1, v13, v3, 0LL);
func0(v10);
sprintf(v13, "Date: %s\r\n", v10);
v4 = strlen(v13);
Send(a1, v13, v4, 0LL);
strcpy(v13, "Server: Four0Four\r\n");
v5 = strlen(v13);
Send(a1, v13, v5, 0LL);
strcpy(v13, "Content-type: text/html\r\n");
v6 = strlen(v13);
Send(a1, v13, v6, 0LL);
v7 = strlen(s);
sprintf(v13, "Content-length: %d\r\n\r\n", v7);
v8 = strlen(v13);
Send(a1, v13, v8, 0LL);
}
if ( head_response != 1 )
{
v9 = strlen(s);
Send(a1, s, v9, 0LL);
}
return strlen(s);
}

original_code:
int err_response(int fd, int status) {
    char buf[8192], body[8192], msg[8192];
    get_status_msg(status, msg);
    char date[256];
    sprintf(body, "<!DOCTYPE html><title>SWS Response</title>\r\n");
    sprintf(body, "%s%d: %s\r\n", body, status, msg);
    sprintf(body, "%s May the force be with you.\r\n", body);
    if (_simple_response !=1 ) {
        sprintf(buf, "HTTP/1.0 %d %s\r\n", status, msg);
        Send(fd, buf, strlen(buf),0);
        get_timestamp(date);
        sprintf(buf, "Date: %s\r\n",date);
        Send(fd, buf, strlen(buf), 0);
        sprintf(buf, "Server: Four0Four\r\n");
        Send(fd, buf, strlen(buf), 0);
        sprintf(buf, "Content-type: text/html\r\n");
        Send(fd, buf, strlen(buf), 0);
        sprintf(buf, "Content-length: %d\r\n\r\n", (int)strlen(body));
        Send(fd, buf, strlen(buf), 0);
    }
    if (_head_response != 1)
        Send(fd, body, strlen(body), 0);
    return (int)strlen(body);
}

canonical_original_code:
int err_response(int fd, int status) {
    char buf[8192]; char body[8192]; char msg[8192];
    get_status_msg(status, msg);
    char date[256];
    sprintf(body, "<!DOCTYPE html><title>SWS Response</title>\r\n");
    sprintf(body, "%s%d: %s\r\n", body, status, msg);
    sprintf(body, "%s May the force be with you.\r\n", body);
    if (_simple_response !=1 ) {
        sprintf(buf, "HTTP/1.0 %d %s\r\n", status, msg);
        Send(fd, buf, strlen(buf),0);
        get_timestamp(date);
        sprintf(buf, "Date: %s\r\n",date);
        Send(fd, buf, strlen(buf), 0);
        sprintf(buf, "Server: Four0Four\r\n");
        Send(fd, buf, strlen(buf), 0);
        sprintf(buf, "Content-type: text/html\r\n");
        Send(fd, buf, strlen(buf), 0);
        sprintf(buf, "Content-length: %d\r\n\r\n", (int)strlen(body));
        Send(fd, buf, strlen(buf), 0);
    }
    if (_head_response != 1)
        Send(fd, body, strlen(body), 0);
    return (int)strlen(body);
}

variable_types: fd int

variable_types: status int

variable_types:
buf
char [8192]

variable_types:
body
char [8192]

variable_types:
msg
char [8192]

variable_types:
date
char [256]

return_type: int


logging

decompiled_code:
void __fastcall logging(__int64 a1)
{
size_t v1; // rax
char s[8200]; // [rsp+0h] [rbp-2008h] BYREF

if ( logDir )
{
sprintf(
s,
"%s %s \"%s\" %d %d\n",
(const char *)(a1 + 528),
(const char *)(a1 + 544),
(const char *)(a1 + 272),
*(unsigned int *)(a1 + 4),
*(unsigned int *)(a1 + 12));
v1 = strlen(s);
fwrite(s, 1uLL, v1, log_fd);
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
size_t v1; // rax
char s[8200]; // [rsp+0h] [rbp-2008h] BYREF

if ( logDir )
{
sprintf(
s,
"%s %s \"%s\" %d %d\n",
(const char *)(a1 + 528),
(const char *)(a1 + 544),
(const char *)(a1 + 272),
*(unsigned int *)(a1 + 4),
*(unsigned int *)(a1 + 12));
v1 = strlen(s);
fwrite(s, 1uLL, v1, log_fd);
}
}

original_code:
void logging(Req_info *req) {
    if (logDir != ((void *)0)) {
         char msg[8192];
        sprintf(msg, "%s %s \"%s\" %d %d\n",req->clientIp,req->recvTime,req->fstLine,req->status,req->contLen);
        (void)fwrite(msg,sizeof(char),strlen(msg),log_fd);
    }
}

canonical_original_code:
void logging(struct req_info *req) {
    if (logDir != ((void *)0)) {
         char msg[8192];
        sprintf(msg, "%s %s \"%s\" %d %d\n",req->clientIp,req->recvTime,req->fstLine,req->status,req->contLen);
        (void)fwrite(msg,sizeof(char),strlen(msg),log_fd);
    }
}

variable_types: struct req_info { int method; int status; int cgi; int contLen; char uri[256]; char fstLine[256]; char clientIp[16]; char recvTime[256]; char ifModified[128]; char query[256]; char msg_body[1024]; } *

return_type: void


decompiled_code:
void __fastcall sws_response(unsigned int a1, __int64 a2)
{
*(_DWORD *)(a2 + 12) = err_response(a1, *(_DWORD *)(a2 + 4));
logging(a2);
}

canonical_decompiled_code:
void __fastcall func4(unsigned int a1, __int64 a2)
{
*(_DWORD *)(a2 + 12) = func2(a1, *(_DWORD *)(a2 + 4));
func3(a2);
}

original_code:
void sws_response(int fd, Req_info *req)
{
    req->contLen = err_response(fd, req->status);
    logging(req);
}

canonical_original_code:
void sws_response(int fd, struct req_info *req)
{
    req->contLen = err_response(fd, req->status);
    logging(req);
}

user_defined_types: struct req_info { int method; int status; int cgi; int contLen; char uri[256]; char fstLine[256]; char clientIp[16]; char recvTime[256]; char ifModified[128]; char query[256]; char msg_body[1024]; }


decompiled_code:
void __fastcall __noreturn sys_err(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void sys_err(const char *msg){
    perror(msg);
    exit( 1 );
}

canonical_original_code:
void sys_err(char *msg){
    perror(msg);
    exit( 1 );
}

variable_types:
msg
char *


Calloc

decompiled_code:
void *__fastcall Calloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
sys_err("calloc error");
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
func0("calloc error");
return result;
}

original_code:
void *Calloc(size_t n, size_t size){
    void *p;
    if( (p = calloc(n,size)) == ((void *)0))
        sys_err("calloc error");
    return (p);
}

canonical_original_code:
void *Calloc(unsigned long n, unsigned long size){
    void *p;
    if( (p = calloc(n,size)) == ((void *)0))
        sys_err("calloc error");
    return (p);
}

variable_types:
n
unsigned long

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


Socket

decompiled_code:
int __fastcall Socket(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
sys_err("socket error");
return result;
}

canonical_decompiled_code:
int __fastcall func2(int a1, int a2, int a3)
{
int result; // eax

result = socket(a1, a2, a3);
if ( result < 0 )
func0("socket error");
return result;
}

original_code:
int Socket(int family, int type, int protocol){
    int n;
    if( (n = socket(family, type, protocol)) < 0)
        sys_err("socket error");
    return (n);
}

variable_types: family int

variable_types: type int

variable_types: protocol int

variable_types: n int


Accept

decompiled_code:
int __fastcall Accept(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = accept(a1, a2, a3);
if ( result < 0 )
sys_err("accept error");
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1, struct sockaddr *a2, socklen_t *a3)
{
int result; // eax

result = accept(a1, a2, a3);
if ( result < 0 )
func0("accept error");
return result;
}

original_code:
int Accept(int fd, struct sockaddr *sa, socklen_t *addrlen){
    int n;
    if( (n = accept(fd, sa, addrlen)) < 0){
        sys_err("accept error");
    }
    return (n);
}

canonical_original_code:
int Accept(int fd, struct sockaddr *sa, unsigned int *addrlen){
    int n;
    if( (n = accept(fd, sa, addrlen)) < 0){
        sys_err("accept error");
    }
    return (n);
}

variable_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; } *

variable_types:
addrlen
unsigned int *


Bind

decompiled_code:
int __fastcall Bind(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
sys_err("bind error");
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = bind(a1, a2, a3);
if ( result < 0 )
func0("bind error");
return result;
}

original_code:
void Bind(int fd, const struct sockaddr *sa, socklen_t addrlen){
    if(bind(fd, sa, addrlen) < 0)
        sys_err("bind error");
}

canonical_original_code:
void Bind(int fd, struct sockaddr *sa, unsigned int addrlen){
    if(bind(fd, sa, addrlen) < 0)
        sys_err("bind error");
}

variable_types: fd int

variable_types:
addrlen
unsigned int

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


Connect

decompiled_code:
int __fastcall Connect(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
sys_err("connect error");
return result;
}

canonical_decompiled_code:
int __fastcall func5(int a1, const struct sockaddr *a2, socklen_t a3)
{
int result; // eax

result = connect(a1, a2, a3);
if ( result < 0 )
func0("connect error");
return result;
}

original_code:
void Connect(int fd, const struct sockaddr *sa, socklen_t addrlen){
    if(connect(fd, sa, addrlen) < 0)
        sys_err("connect error");
}

canonical_original_code:
void Connect(int fd, struct sockaddr *sa, unsigned int addrlen){
    if(connect(fd, sa, addrlen) < 0)
        sys_err("connect error");
}


Listen

decompiled_code:
int __fastcall Listen(int a1, int a2)
{
int result; // eax

result = listen(a1, a2);
if ( result < 0 )
sys_err("listen error");
return result;
}

canonical_decompiled_code:
int __fastcall func6(int a1, int a2)
{
int result; // eax

result = listen(a1, a2);
if ( result < 0 )
func0("listen error");
return result;
}

original_code:
void Listen(int fd, int backlog){
    if(listen(fd, backlog) < 0)
        sys_err("listen error");
}

variable_types: backlog int


Setsockopt

decompiled_code:
int __fastcall Setsockopt(int a1, int a2, int a3, const void *a4, socklen_t a5)
{
int result; // eax

result = setsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
sys_err("setsockopt error");
return result;
}

canonical_decompiled_code:
int __fastcall func7(int a1, int a2, int a3, const void *a4, socklen_t a5)
{
int result; // eax

result = setsockopt(a1, a2, a3, a4, a5);
if ( result < 0 )
func0("setsockopt error");
return result;
}

original_code:
void Setsockopt(int fd, int level, int optname, const void *optval, int optlen){
    if(setsockopt(fd, level, optname, optval, optlen) < 0)
        sys_err("setsockopt error");
}

canonical_original_code:
void Setsockopt(int fd, int level, int optname, void *optval, int optlen){
    if(setsockopt(fd, level, optname, optval, optlen) < 0)
        sys_err("setsockopt error");
}

variable_types: level int

variable_types: optname int

variable_types:
optval
void *

variable_types: optlen int


Close

decompiled_code:
int __fastcall Close(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
sys_err("close error");
return result;
}

canonical_decompiled_code:
int __fastcall func8(int a1)
{
int result; // eax

result = close(a1);
if ( result == -1 )
func0("close error");
return result;
}

original_code:
void Close(int fd){
    if(close(fd) == -1)
        sys_err("close error");
}


decompiled_code:
int __fastcall Inet_pton(int a1, const char *a2, void *a3)
{
int result; // eax

result = inet_pton(a1, a2, a3);
if ( result <= 0 )
{
fprintf(stderr, "inet error ->%s", a2);
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, const char *a2, void *a3)
{
int result; // eax

result = inet_pton(a1, a2, a3);
if ( result <= 0 )
{
fprintf(stderr, "inet error ->%s", a2);
exit(1);
}
return result;
}

original_code:
void Inet_pton(int family, const char *strptr, void *addrptr){
    int n;
    if( (n = inet_pton(family, strptr, addrptr)) <= 0){
        fprintf(stderr, "inet error ->%s", strptr);
        exit ( 1 );
    }
}

canonical_original_code:
void Inet_pton(int family, char *strptr, void *addrptr){
    int n;
    if( (n = inet_pton(family, strptr, addrptr)) <= 0){
        fprintf(stderr, "inet error ->%s", strptr);
        exit ( 1 );
    }
}

variable_types:
strptr
char *

variable_types:
addrptr
void *


decompiled_code:
const char *__fastcall Inet_ntop(int a1, const void *a2, char *a3, socklen_t a4)
{
const char *result; // rax

result = inet_ntop(a1, a2, a3, a4);
if ( !result )
sys_err("inet_ntop error");
return result;
}

canonical_decompiled_code:
const char *__fastcall func10(int a1, const void *a2, char *a3, socklen_t a4)
{
const char *result; // rax

result = inet_ntop(a1, a2, a3, a4);
if ( !result )
func0("inet_ntop error");
return result;
}

original_code:
const char *Inet_ntop(int family, const void *addrptr, char *strptr, size_t len){
    const char *ptr;
    if ( (ptr = inet_ntop(family, addrptr, strptr, len)) == ((void *)0))
        sys_err("inet_ntop error");
    return(ptr);
}

canonical_original_code:
char *Inet_ntop(int family, void *addrptr, char *strptr, unsigned long len){
    char *ptr;
    if ( (ptr = inet_ntop(family, addrptr, strptr, len)) == ((void *)0))
        sys_err("inet_ntop error");
    return(ptr);
}

variable_types:
len
unsigned long

variable_types:
ptr
char *

return_type: char *


Getaddrinfo

decompiled_code:
__int64 __fastcall Getaddrinfo(const char *a1, const char *a2, const struct addrinfo *a3, struct addrinfo **a4)
{
int v4; // eax
const char *v6; // rax

v4 = getaddrinfo(a1, a2, a3, a4);
if ( v4 )
{
v6 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo error: %s\n", v6);
exit(1);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, const char *a2, const struct addrinfo *a3, struct addrinfo **a4)
{
int v4; // eax
const char *v6; // rax

v4 = getaddrinfo(a1, a2, a3, a4);
if ( v4 )
{
v6 = gai_strerror(v4);
fprintf(stderr, "getaddrinfo error: %s\n", v6);
exit(1);
}
return 0LL;
}

original_code:
int Getaddrinfo(const char *hostname, const char *servname, const struct addrinfo *hints, struct addrinfo **res){
    int n;
    if( (n = getaddrinfo(hostname, servname, hints, res)) != 0){
        fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(n));
        exit(1);
    }
    return (n);
}

canonical_original_code:
int Getaddrinfo(char *hostname, char *servname, struct addrinfo *hints, struct addrinfo **res){
    int n;
    if( (n = getaddrinfo(hostname, servname, hints, res)) != 0){
        fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(n));
        exit(1);
    }
    return (n);
}

variable_types:
hostname
char *

variable_types:
servname
char *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

variable_types:
res
struct addrinfo **

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


Read

decompiled_code:
__int64 __fastcall Read(int a1, void *a2, size_t a3)
{
int v3; // ebx
int *v5; // rax
char *v6; // rax

v3 = read(a1, a2, a3);
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Read warning: %s.\n", v6);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, void *a2, size_t a3)
{
int v3; // ebx
int *v5; // rax
char *v6; // rax

v3 = read(a1, a2, a3);
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Read warning: %s.\n", v6);
}
return v3;
}

original_code:
ssize_t Read(int fd, void *buf, size_t count){
    int n;
    if ((n = read(fd, buf, count)) < 0)
        fprintf(stderr, "Read warning: %s.\n", strerror((*__errno_location ())));
    return (n);
}

canonical_original_code:
long Read(int fd, void *buf, unsigned long count){
    int n;
    if ((n = read(fd, buf, count)) < 0)
        fprintf(stderr, "Read warning: %s.\n", strerror((*__errno_location ())));
    return (n);
}

variable_types:
buf
void *

variable_types:
count
unsigned long

variable_types: n int

return_type: long


Write

decompiled_code:
__int64 __fastcall Write(int a1, const void *a2, size_t a3)
{
int v3; // ebx
int *v5; // rax
char *v6; // rax

v3 = write(a1, a2, a3);
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Write warning: %s.\n", v6);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, const void *a2, size_t a3)
{
int v3; // ebx
int *v5; // rax
char *v6; // rax

v3 = write(a1, a2, a3);
if ( v3 < 0 )
{
v5 = _errno_location();
v6 = strerror(*v5);
fprintf(stderr, "Write warning: %s.\n", v6);
}
return v3;
}

original_code:
ssize_t Write(int fd, const void *buf, size_t count){
    int n;
    if ((n = write(fd, buf, count)) < 0)
        fprintf(stderr, "Write warning: %s.\n", strerror((*__errno_location ())));
    return (n);
}

canonical_original_code:
long Write(int fd, void *buf, unsigned long count){
    int n;
    if ((n = write(fd, buf, count)) < 0)
        fprintf(stderr, "Write warning: %s.\n", strerror((*__errno_location ())));
    return (n);
}

variable_types: fd int


Send

decompiled_code:
__int64 __fastcall Send(int a1, const void *a2, size_t a3, int a4)
{
int v4; // ebx
int *v6; // rax
char *v7; // rax

v4 = send(a1, a2, a3, a4);
if ( v4 < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Send warning: %s.\n", v7);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, const void *a2, size_t a3, int a4)
{
int v4; // ebx
int *v6; // rax
char *v7; // rax

v4 = send(a1, a2, a3, a4);
if ( v4 < 0 )
{
v6 = _errno_location();
v7 = strerror(*v6);
fprintf(stderr, "Send warning: %s.\n", v7);
}
return v4;
}

original_code:
ssize_t Send(int sock, const void *buf, size_t count, int flag){
    int n;
    if ((n = send(sock, buf, count,flag)) < 0)
        fprintf(stderr, "Send warning: %s.\n", strerror((*__errno_location ())));
    return (n);
}

canonical_original_code:
long Send(int sock, void *buf, unsigned long count, int flag){
    int n;
    if ((n = send(sock, buf, count,flag)) < 0)
        fprintf(stderr, "Send warning: %s.\n", strerror((*__errno_location ())));
    return (n);
}

variable_types: sock int

variable_types: flag int


Readline

decompiled_code:
__int64 __fastcall Readline(int fd, _BYTE *a2)
{
unsigned int v3; // ebp
int v4; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = 1;
while ( 1 )
{
v4 = read(fd, buf, 1uLL);
if ( v4 != 1 )
break;
if ( buf[0] != 10 )
{
*a2++ = buf[0];
if ( ++v3 != 0x2000 )
continue;
}
goto LABEL_8;
}
if ( v4 )
return (unsigned int)-1;
if ( v3 != 1 )
{
LABEL_8:
*a2 = 0;
return v3;
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func15(int fd, _BYTE *a2)
{
unsigned int v3; // ebp
int v4; // eax
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

v3 = 1;
while ( 1 )
{
v4 = read(fd, buf, 1uLL);
if ( v4 != 1 )
break;
if ( buf[0] != 10 )
{
*a2++ = buf[0];
if ( ++v3 != 0x2000 )
continue;
}
goto LABEL_8;
}
if ( v4 )
return (unsigned int)-1;
if ( v3 != 1 )
{
LABEL_8:
*a2 = 0;
return v3;
}
return 0;
}

original_code:
int Readline(int fd, char* buf)
{
    int n, rc;
    char c, *bufp = buf;
    for (n = 1; n < 8192; n++) {
        if ((rc = read(fd, &c, 1)) == 1) {
            if (c == '\n')
                break;
            *bufp++ = c;
        } else if (rc == 0) {
            if (n == 1)
                return 0;
            else
                break;
        } else
            return -1;
    }
    *bufp = '\0';
    return n;
}

canonical_original_code:
int Readline(int fd, char *buf)
{
    int n; int rc;
    char c; char *bufp = buf;
    for (n = 1; n < 8192; n++) {
        if ((rc = read(fd, &c, 1)) == 1) {
            if (c == '\n')
                break;
            *bufp++ = c;
        } else if (rc == 0) {
            if (n == 1)
                return 0;
            else
                break;
        } else
            return -1;
    }
    *bufp = '\0';
    return n;
}

variable_types:
buf
char *

variable_types: rc int

variable_types: c char

variable_types:
bufp
char *


decompiled_code:
void child_handler()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) != -1 )
;
}

canonical_decompiled_code:
void func0()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) != -1 )
;
}

original_code:
static void child_handler(int sig){
    pid_t p;
    int status;
    while( (p = waitpid(-1, &status, 1)) != -1)
        ;
}

canonical_original_code:
static void child_handler(int sig){
    int p;
    int status;
    while( (p = waitpid(-1, &status, 1)) != -1)
        ;
}

variable_types: sig int

variable_types: p int

variable_types: status int


decompiled_code:
void __fastcall __noreturn server_listen(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rbp
int v4; // er12
__int64 v5; // r13
unsigned int v6; // er15
int v7; // [rsp+Ch] [rbp-A4Ch] BYREF
struct timeval timeout; // [rsp+10h] [rbp-A48h] BYREF
fd_set readfds; // [rsp+20h] [rbp-A38h] BYREF
char v10[528]; // [rsp+A0h] [rbp-9B8h] BYREF
char dest[1688]; // [rsp+2B0h] [rbp-7A8h] BYREF
int v12; // [rsp+948h] [rbp-110h] BYREF
int v13; // [rsp+94Ch] [rbp-10Ch] BYREF
char v14[4]; // [rsp+950h] [rbp-108h] BYREF
int v15; // [rsp+954h] [rbp-104h]
char src[24]; // [rsp+9D0h] [rbp-88h] BYREF
__int64 v17; // [rsp+9E8h] [rbp-70h] BYREF
__int64 v18[13]; // [rsp+9F0h] [rbp-68h] BYREF

v12 = 1;
v18[0] = 1LL;
v18[1] = 1LL;
v18[2] = 0LL;
v18[3] = 0LL;
v18[4] = 0LL;
v18[5] = 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
Getaddrinfo(v2, *(_QWORD *)(a1 + 24), v18, &v17);
else
Getaddrinfo(0LL, *(_QWORD *)(a1 + 24), v18, &v17);
v3 = (unsigned int)Socket(*(unsigned int *)(v17 + 4), *(unsigned int *)(v17 + 8), *(unsigned int *)(v17 + 12));
Setsockopt(v3, 1LL, 2LL, &v12, 4LL);
Bind((unsigned int)v3, *(_QWORD *)(v17 + 24), *(unsigned int *)(v17 + 16));
Listen((unsigned int)v3, 10LL);
signal(17, (__sighandler_t)child_handler);
v4 = (int)v3 / 64;
v5 = 1LL << ((int)v3 % 64);
while ( 1 )
{
do
{
do
{
v7 = v15;
v13 = 128;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v4] |= v5;
}
while ( (unsigned int)(select(v3 + 1, &readfds, 0LL, 0LL, &timeout) + 1) <= 1 );
}
while ( (readfds.fds_bits[v4] & v5) == 0 );
v6 = Accept((unsigned int)v3, v14, &v13);
if ( !fork() )
{
pidfile_close(pfh);
signal(15, 0LL);
Close((unsigned int)v3);
Inet_ntop(2LL, &v7, src, 16LL);
strncpy(dest, src, 0x10uLL);
read_sock(v6, v10, a1);
exit(0);
}
Close(v6);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(__int64 a1)
{
__int64 v2; // rdi
__int64 v3; // rbp
int v4; // er12
__int64 v5; // r13
unsigned int v6; // er15
int v7; // [rsp+Ch] [rbp-A4Ch] BYREF
struct timeval timeout; // [rsp+10h] [rbp-A48h] BYREF
fd_set readfds; // [rsp+20h] [rbp-A38h] BYREF
char v10[528]; // [rsp+A0h] [rbp-9B8h] BYREF
char dest[1688]; // [rsp+2B0h] [rbp-7A8h] BYREF
int v12; // [rsp+948h] [rbp-110h] BYREF
int v13; // [rsp+94Ch] [rbp-10Ch] BYREF
char v14[4]; // [rsp+950h] [rbp-108h] BYREF
int v15; // [rsp+954h] [rbp-104h]
char src[24]; // [rsp+9D0h] [rbp-88h] BYREF
__int64 v17; // [rsp+9E8h] [rbp-70h] BYREF
__int64 v18[13]; // [rsp+9F0h] [rbp-68h] BYREF

v12 = 1;
v18[0] = 1LL;
v18[1] = 1LL;
v18[2] = 0LL;
v18[3] = 0LL;
v18[4] = 0LL;
v18[5] = 0LL;
v2 = *(_QWORD *)(a1 + 8);
if ( v2 )
Getaddrinfo(v2, *(_QWORD *)(a1 + 24), v18, &v17);
else
Getaddrinfo(0LL, *(_QWORD *)(a1 + 24), v18, &v17);
v3 = (unsigned int)Socket(*(unsigned int *)(v17 + 4), *(unsigned int *)(v17 + 8), *(unsigned int *)(v17 + 12));
Setsockopt(v3, 1LL, 2LL, &v12, 4LL);
Bind((unsigned int)v3, *(_QWORD *)(v17 + 24), *(unsigned int *)(v17 + 16));
Listen((unsigned int)v3, 10LL);
signal(17, (__sighandler_t)child_handler);
v4 = (int)v3 / 64;
v5 = 1LL << ((int)v3 % 64);
while ( 1 )
{
do
{
do
{
v7 = v15;
v13 = 128;
timeout.tv_sec = 5LL;
timeout.tv_usec = 0LL;
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v4] |= v5;
}
while ( (unsigned int)(select(v3 + 1, &readfds, 0LL, 0LL, &timeout) + 1) <= 1 );
}
while ( (readfds.fds_bits[v4] & v5) == 0 );
v6 = Accept((unsigned int)v3, v14, &v13);
if ( !fork() )
{
pidfile_close(pfh);
signal(15, 0LL);
Close((unsigned int)v3);
Inet_ntop(2LL, &v7, src, 16LL);
strncpy(dest, src, 0x10uLL);
read_sock(v6, v10, a1);
exit(0);
}
Close(v6);
}
}

original_code:
int server_listen( Arg_t *optInfo){
    struct addrinfo hints, *res;
    char ipstr[16];
    int listenfd, connfd;
    struct sockaddr_storage client_addr;
    socklen_t clientlen;
    int ignore = 1;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if(optInfo->ipAddr == ((void *)0)){
        hints.ai_flags = 0x0001;
        Getaddrinfo(((void *)0), optInfo->port, &hints, &res);
    }
    else{
        Getaddrinfo(optInfo->ipAddr, optInfo->port, &hints, &res);
    }
    listenfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    Setsockopt(listenfd, 1, 2, &ignore, sizeof(int));
    Bind(listenfd, res->ai_addr, res->ai_addrlen);
    Listen(listenfd, 10);
    signal(17, child_handler);
    while(1){
        pid_t childpid;
        struct sockaddr_in* cliAdr = (struct sockaddr_in*)&client_addr;
        int ipAddr = cliAdr->sin_addr.s_addr;
        clientlen = sizeof(client_addr);
        Req_info req;
        struct timeval to;
        fd_set rdy;
        to.tv_sec=5;
        to.tv_usec=0;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdy)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rdy)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
        int ret=select(listenfd+1, &rdy, 0, 0, &to);
        if (ret==-1)
            continue;
        else if (ret==0)
            continue;
        else if (((((&rdy)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)==0)
            continue;
        connfd = Accept(listenfd, (struct sockaddr *) &client_addr, &clientlen);
        if( (childpid = fork()) == 0){
            pidfile_close(pfh);
            signal(15, ((__sighandler_t) 0));
            Close(listenfd);
            Inet_ntop(2, &ipAddr, ipstr, 16);
            memset(req.clientIp,0,sizeof(req.clientIp));
            strncpy(req.clientIp,ipstr,16);
            read_sock(connfd, &req, optInfo);
            exit(0);
        }
        Close(connfd);
    }
    freeaddrinfo(res);
    return connfd;
}

canonical_original_code:
int server_listen(struct arg_t *optInfo){
    struct addrinfo hints; struct addrinfo *res;
    char ipstr[16];
    int listenfd; int connfd;
    struct sockaddr_storage client_addr;
    unsigned int clientlen;
    int ignore = 1;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = 0;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = 0x0001;
    if(optInfo->ipAddr == ((void *)0)){
        hints.ai_flags = 0x0001;
        Getaddrinfo(((void *)0), optInfo->port, &hints, &res);
    }
    else{
        Getaddrinfo(optInfo->ipAddr, optInfo->port, &hints, &res);
    }
    listenfd = Socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    Setsockopt(listenfd, 1, 2, &ignore, sizeof(int));
    Bind(listenfd, res->ai_addr, res->ai_addrlen);
    Listen(listenfd, 10);
    signal(17, child_handler);
    while(1){
        int childpid;
        struct sockaddr_in *cliAdr = (struct sockaddr_in*)&client_addr;
        int ipAddr = cliAdr->sin_addr.s_addr;
        clientlen = sizeof(client_addr);
        struct req_info req;
        struct timeval to;
        struct fd_set rdy;
        to.tv_sec=5;
        to.tv_usec=0;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdy)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&rdy)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))));
        int ret = select(listenfd+1, &rdy, 0, 0, &to);
        if (ret==-1)
            continue;
        else if (ret==0)
            continue;
        else if (((((&rdy)->__fds_bits)[((listenfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((listenfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)==0)
            continue;
        connfd = Accept(listenfd, (struct sockaddr *) &client_addr, &clientlen);
        if( (childpid = fork()) == 0){
            pidfile_close(pfh);
            signal(15, ((void (*)(int)) 0));
            Close(listenfd);
            Inet_ntop(2, &ipAddr, ipstr, 16);
            memset(req.clientIp,0,sizeof(req.clientIp));
            strncpy(req.clientIp,ipstr,16);
            read_sock(connfd, &req, optInfo);
            exit(0);
        }
        Close(connfd);
    }
    freeaddrinfo(res);
    return connfd;
}

variable_types: struct arg_t { char *cgiDir; char *ipAddr; char *logFile; char *port; char *dir; } *

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

variable_types:
ipstr
char [16]

variable_types: listenfd int

variable_types: connfd int

variable_types: struct sockaddr_storage { unsigned short ss_family; char __ss_padding[-1]; unsigned long __ss_align; }

variable_types:
clientlen
unsigned int

variable_types: ignore int

variable_types: childpid int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: ipAddr int

variable_types: struct req_info { int method; int status; int cgi; int contLen; char uri[256]; char fstLine[256]; char clientIp[16]; char recvTime[256]; char ifModified[128]; char query[256]; char msg_body[1024]; }

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
rdy
struct fd_set { long __fds_bits[-1]; }

variable_types: ret int

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
int __fastcall print_char(char a1)
{
int result; // eax

if ( (unsigned __int8)(a1 - 32) > 0x5Eu )
result = putchar(46);
else
result = putchar(a1);
return result;
}

canonical_decompiled_code:
int __fastcall func7(char a1)
{
int result; // eax

if ( (unsigned __int8)(a1 - 32) > 0x5Eu )
result = putchar(46);
else
result = putchar(a1);
return result;
}

original_code:
void print_char(char c) {
    if (c >= 32 && c < 127) {
        printf("%c", c);
    } else {
        printf(".");
    }
}

variable_types: c char


repo: WojciechMula/toys

decompiled_code:
unsigned __int64 __fastcall movmask_unsafe(unsigned int a1)
{
if ( (a1 & 0x7F7F7F7F) != 0 )
__assert_fail("(input & 0x7f7f7f7f) == 0", "movmask.c", 6u, "movmask_unsafe");
return ((33818640 * (unsigned __int64)a1) >> 32) & 0xF;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(unsigned int a1)
{
if ( (a1 & 0x7F7F7F7F) != 0 )
__assert_fail("(input & 0x7f7f7f7f) == 0", "movmask.c", 6u, "movmask_unsafe");
return ((33818640 * (unsigned __int64)a1) >> 32) & 0xF;
}

original_code:
uint32_t movmask_unsafe(const uint32_t input) {
    (((input & 0x7f7f7f7f) == 0) ? (void) (0) : __assert_fail ("(input & 0x7f7f7f7f) == 0", "movmask.c", 6, __extension__ __PRETTY_FUNCTION__));
 const uint32_t mult = 0x02040810;
 const uint64_t result = (uint64_t)input * mult;
 return (result >> 32) & 0x0f;
}

canonical_original_code:
unsigned int movmask_unsafe(unsigned int input) {
    (((input & 0x7f7f7f7f) == 0) ? (void) (0) : __assert_fail ("(input & 0x7f7f7f7f) == 0", "movmask.c", 6, __extension__ __PRETTY_FUNCTION__));
 unsigned int mult = 0x02040810;
 unsigned long result = (uint64_t)input * mult;
 return (result >> 32) & 0x0f;
}

variable_types:
input
unsigned int

variable_types:
mult
unsigned int

variable_types:
result
unsigned long

return_type: unsigned int


movmask

decompiled_code:
unsigned __int64 __fastcall movmask(int a1)
{
return movmask_unsafe(a1 & 0x80808080);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func8(int a1)
{
return func7(a1 & 0x80808080);
}

original_code:
uint32_t movmask(const uint32_t input) {
    return movmask_unsafe(input & 0x80808080);
}

canonical_original_code:
unsigned int movmask(unsigned int input) {
    return movmask_unsafe(input & 0x80808080);
}


decompiled_code:
__int64 __fastcall movmask64(__int64 a1)
{
return movmask64_unsafe(a1 & 0x8080808080808080LL);
}

original_code:
uint64_t movmask64(const uint64_t input) {
    return movmask64_unsafe(input & 0x8080808080808080lu);
}

canonical_original_code:
unsigned long movmask64(unsigned long input) {
    return movmask64_unsafe(input & 0x8080808080808080lu);
}

variable_types:
input
unsigned long

return_type: unsigned long


generate

decompiled_code:
__int64 __fastcall generate(int a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

if ( a1 < 0 )
__assert_fail("x >= 0", "demo.c", 8u, "generate");
if ( a1 > 15 )
__assert_fail("x < 16", "demo.c", 9u, "generate");
v1 = 0;
v2 = 0;
do
{
if ( _bittest(&a1, v1) )
v2 |= 1 << (8 * v1 + 7);
++v1;
}
while ( v1 != 4 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func11(int a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

if ( a1 < 0 )
__assert_fail("x >= 0", "demo.c", 8u, "generate");
if ( a1 > 15 )
__assert_fail("x < 16", "demo.c", 9u, "generate");
v1 = 0;
v2 = 0;
do
{
if ( _bittest(&a1, v1) )
v2 |= 1 << (8 * v1 + 7);
++v1;
}
while ( v1 != 4 );
return v2;
}

original_code:
uint32_t generate(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "demo.c", 8, __extension__ __PRETTY_FUNCTION__));
 ((x < 16) ? (void) (0) : __assert_fail ("x < 16", "demo.c", 9, __extension__ __PRETTY_FUNCTION__));
 uint32_t result = 0;
 for (int i=0; i < 4; i++) {
  if (x & (1 << i))
   result |= 1 << (8*i + 7);
 }
 return result;
}

canonical_original_code:
unsigned int generate(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "demo.c", 8, __extension__ __PRETTY_FUNCTION__));
 ((x < 16) ? (void) (0) : __assert_fail ("x < 16", "demo.c", 9, __extension__ __PRETTY_FUNCTION__));
 unsigned int result = 0;
 for (int i = 0; i < 4; i++) {
  if (x & (1 << i))
   result |= 1 << (8*i + 7);
 }
 return result;
}

variable_types: x int

variable_types:
result
unsigned int

variable_types: i int


decompiled_code:
__int64 test32()
{
unsigned int v0; // ebp
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax

v0 = 0;
while ( 1 )
{
v1 = generate(v0);
v2 = v1;
if ( (v1 & 0x7F7F7F7F) != 0 )
__assert_fail("(input & 0x7f7f7f7f) == 0", "demo.c", 0x1Au, "test32");
v3 = movmask(v1);
if ( v3 != v0 )
break;
if ( ++v0 == 16 )
return 1LL;
}
printf("%08x => %x (expected %x)\n", v2, v3, v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
unsigned int v0; // ebp
int v1; // eax
unsigned int v2; // ebx
unsigned int v3; // eax

v0 = 0;
while ( 1 )
{
v1 = func11(v0);
v2 = v1;
if ( (v1 & 0x7F7F7F7F) != 0 )
__assert_fail("(input & 0x7f7f7f7f) == 0", "demo.c", 0x1Au, "test32");
v3 = func8(v1);
if ( v3 != v0 )
break;
if ( ++v0 == 16 )
return 1LL;
}
printf("%08x => %x (expected %x)\n", v2, v3, v0);
return 0LL;
}

original_code:
int test32() {
 for (unsigned mask=0; mask < 16; mask++) {
  const uint32_t input = generate(mask);
  (((input & 0x7f7f7f7f) == 0) ? (void) (0) : __assert_fail ("(input & 0x7f7f7f7f) == 0", "demo.c", 26, __extension__ __PRETTY_FUNCTION__));
  const uint32_t result = movmask(input);
        if (result != mask) {
      printf("%08x => %x (expected %x)\n", input, result, mask);
            return 0;
        }
 }
    return 1;
}

canonical_original_code:
int test32() {
 for (unsigned int mask = 0; mask < 16; mask++) {
  unsigned int input = generate(mask);
  (((input & 0x7f7f7f7f) == 0) ? (void) (0) : __assert_fail ("(input & 0x7f7f7f7f) == 0", "demo.c", 26, __extension__ __PRETTY_FUNCTION__));
  unsigned int result = movmask(input);
        if (result != mask) {
      printf("%08x => %x (expected %x)\n", input, result, mask);
            return 0;
        }
 }
    return 1;
}

variable_types:
mask
unsigned int


decompiled_code:
__int64 __fastcall generate64(int a1)
{
char v1; // cl
unsigned int v2; // eax
__int64 v3; // rdx

if ( a1 < 0 )
__assert_fail("x >= 0", "demo.c", 0x29u, "generate64");
if ( a1 > 255 )
__assert_fail("x < 256", "demo.c", 0x2Au, "generate64");
v1 = 7;
v2 = 0;
v3 = 0LL;
do
{
if ( _bittest(&a1, v2) )
v3 |= 1LL << v1;
++v2;
v1 += 8;
}
while ( v2 != 8 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1)
{
char v1; // cl
unsigned int v2; // eax
__int64 v3; // rdx

if ( a1 < 0 )
__assert_fail("x >= 0", "demo.c", 0x29u, "generate64");
if ( a1 > 255 )
__assert_fail("x < 256", "demo.c", 0x2Au, "generate64");
v1 = 7;
v2 = 0;
v3 = 0LL;
do
{
if ( _bittest(&a1, v2) )
v3 |= 1LL << v1;
++v2;
v1 += 8;
}
while ( v2 != 8 );
return v3;
}

original_code:
uint64_t generate64(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "demo.c", 41, __extension__ __PRETTY_FUNCTION__));
 ((x < 256) ? (void) (0) : __assert_fail ("x < 256", "demo.c", 42, __extension__ __PRETTY_FUNCTION__));
 uint64_t result = 0;
 for (int i=0; i < 8; i++) {
  if (x & (1 << i))
   result |= 1lu << (8*i + 7);
 }
 return result;
}

canonical_original_code:
unsigned long generate64(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "demo.c", 41, __extension__ __PRETTY_FUNCTION__));
 ((x < 256) ? (void) (0) : __assert_fail ("x < 256", "demo.c", 42, __extension__ __PRETTY_FUNCTION__));
 unsigned long result = 0;
 for (int i = 0; i < 8; i++) {
  if (x & (1 << i))
   result |= 1lu << (8*i + 7);
 }
 return result;
}


decompiled_code:
__int64 test64()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax

v0 = 0LL;
while ( 1 )
{
v1 = generate64(v0);
v2 = v1;
if ( (v1 & 0x7F7F7F7F7F7F7F7FLL) != 0 )
__assert_fail("(input & 0x7f7f7f7f7f7f7f7flu) == 0", "demo.c", 0x3Bu, "test64");
v3 = movmask64(v1);
if ( v3 != v0 )
break;
if ( ++v0 == 256 )
return 1LL;
}
printf("%016lx => %lx (expected %x)\n", v2, v3, (unsigned int)v0);
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
__int64 v0; // rbx
__int64 v1; // rax
__int64 v2; // rbp
__int64 v3; // rax

v0 = 0LL;
while ( 1 )
{
v1 = func13(v0);
v2 = v1;
if ( (v1 & 0x7F7F7F7F7F7F7F7FLL) != 0 )
__assert_fail("(input & 0x7f7f7f7f7f7f7f7flu) == 0", "demo.c", 0x3Bu, "test64");
v3 = func10(v1);
if ( v3 != v0 )
break;
if ( ++v0 == 256 )
return 1LL;
}
printf("%016lx => %lx (expected %x)\n", v2, v3, (unsigned int)v0);
return 0LL;
}

original_code:
int test64() {
 for (unsigned mask=0; mask < 256; mask++) {
  const uint64_t input = generate64(mask);
  (((input & 0x7f7f7f7f7f7f7f7flu) == 0) ? (void) (0) : __assert_fail ("(input & 0x7f7f7f7f7f7f7f7flu) == 0", "demo.c", 59, __extension__ __PRETTY_FUNCTION__));
  const uint64_t result = movmask64(input);
        if (result != mask) {
            printf("%016lx => %lx (expected %x)\n", input, result, mask);
            return 0;
        }
 }
    return 1;
}

canonical_original_code:
int test64() {
 for (unsigned int mask = 0; mask < 256; mask++) {
  unsigned long input = generate64(mask);
  (((input & 0x7f7f7f7f7f7f7f7flu) == 0) ? (void) (0) : __assert_fail ("(input & 0x7f7f7f7f7f7f7f7flu) == 0", "demo.c", 59, __extension__ __PRETTY_FUNCTION__));
  unsigned long result = movmask64(input);
        if (result != mask) {
            printf("%016lx => %lx (expected %x)\n", input, result, mask);
            return 0;
        }
 }
    return 1;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v4; // rdi

puts("testing 32-bit code...");
v3 = test32("testing 32-bit code...", argv);
puts("testing 64-bit code...");
v4 = "OK";
if ( !((unsigned int)test64() | (v3 != 0)) )
v4 = "FAILED";
puts(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
const char *v4; // rdi

puts("testing 32-bit code...");
v3 = func12("testing 32-bit code...", argv);
puts("testing 64-bit code...");
v4 = "OK";
if ( !((unsigned int)func14() | (v3 != 0)) )
v4 = "FAILED";
puts(v4);
return 0;
}

original_code:
int main() {
    int result = 0;
    puts("testing 32-bit code...");
    result = test32() || result;
    puts("testing 64-bit code...");
    result = test64() || result;
    puts(result ? "OK" : "FAILED");
}

variable_types: result int


seq

decompiled_code:
void __fastcall seq(__int64 a1, int a2)
{
__int64 i; // rax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
*(_DWORD *)(a1 + 4 * i) = i;
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2)
{
__int64 i; // rax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
*(_DWORD *)(a1 + 4 * i) = i;
}
}

original_code:
void seq(uint32_t* tbl, uint32_t n) {
 uint32_t i;
 for (i=0; i < n; i++)
  tbl[i] = i;
}

canonical_original_code:
void seq(unsigned int *tbl, unsigned int n) {
 unsigned int i;
 for (i=0; i < n; i++)
  tbl[i] = i;
}

variable_types:
tbl
unsigned int *

variable_types:
n
unsigned int

variable_types:
i
unsigned int


shuffle

decompiled_code:
void __fastcall shuffle(__int64 a1, unsigned int a2)
{
__int64 v3; // r13
__int64 v4; // rbx
unsigned int v5; // eax
int v6; // esi
_DWORD *v7; // rax
__int64 v8; // rax

if ( a2 > 1 )
{
v3 = a2 - 2;
v4 = 0LL;
do
{
v5 = rand();
v6 = *(_DWORD *)(a1 + 4 * v4);
v7 = (_DWORD *)(a1 + 4LL * (v5 % (a2 - (unsigned int)v4) + (unsigned int)v4));
*(_DWORD *)(a1 + 4 * v4) = *v7;
*v7 = v6;
v8 = v4++;
}
while ( v8 != v3 );
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, unsigned int a2)
{
__int64 v3; // r13
__int64 v4; // rbx
unsigned int v5; // eax
int v6; // esi
_DWORD *v7; // rax
__int64 v8; // rax

if ( a2 > 1 )
{
v3 = a2 - 2;
v4 = 0LL;
do
{
v5 = rand();
v6 = *(_DWORD *)(a1 + 4 * v4);
v7 = (_DWORD *)(a1 + 4LL * (v5 % (a2 - (unsigned int)v4) + (unsigned int)v4));
*(_DWORD *)(a1 + 4 * v4) = *v7;
*v7 = v6;
v8 = v4++;
}
while ( v8 != v3 );
}
}

original_code:
void shuffle(uint32_t* tbl, uint32_t n) {
 uint32_t i, j, x;
 if (n == 0)
  return;
 for (i=0; i < n - 1; i++) {
  j = rand() % (n - i);
  x = tbl[i];
  tbl[i] = tbl[i+j];
  tbl[i+j] = x;
 }
}

canonical_original_code:
void shuffle(unsigned int *tbl, unsigned int n) {
 unsigned int i; unsigned int j; unsigned int x;
 if (n == 0)
  return;
 for (i=0; i < n - 1; i++) {
  j = rand() % (n - i);
  x = tbl[i];
  tbl[i] = tbl[i+j];
  tbl[i+j] = x;
 }
}

variable_types:
j
unsigned int

variable_types:
x
unsigned int


scanmem

decompiled_code:
__int64 __fastcall scanmem(__int64 a1, unsigned int *a2, unsigned int a3)
{
unsigned int *v3; // rax
__int64 v4; // rsi

if ( a3 )
{
v3 = a2;
v4 = (__int64)&a2[a3];
a3 = 0;
do
a3 += *(_DWORD *)(a1 + 4LL * *v3++);
while ( v3 != (unsigned int *)v4 );
}
return a3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned int *a2, unsigned int a3)
{
unsigned int *v3; // rax
__int64 v4; // rsi

if ( a3 )
{
v3 = a2;
v4 = (__int64)&a2[a3];
a3 = 0;
do
a3 += *(_DWORD *)(a1 + 4LL * *v3++);
while ( v3 != (unsigned int *)v4 );
}
return a3;
}

original_code:
uint32_t scanmem(uint32_t* tbl, uint32_t* indexes, uint32_t n) {
 uint32_t i, acc;
 acc = 0;
 for (i=0; i < n; i++)
  acc += tbl[indexes[i]];
 return acc;
}

canonical_original_code:
unsigned int scanmem(unsigned int *tbl, unsigned int *indexes, unsigned int n) {
 unsigned int i; unsigned int acc;
 acc = 0;
 for (i=0; i < n; i++)
  acc += tbl[indexes[i]];
 return acc;
}

variable_types:
indexes
unsigned int *

variable_types:
acc
unsigned int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebx
size_t v5; // rbp
void *v6; // r12
void *v7; // rax
void *v8; // rbp
int v9; // er13
unsigned int v10; // eax
clock_t v11; // r13
clock_t v12; // rbx
int result; // eax
double v14; // [rsp+0h] [rbp-38h]
double v15; // [rsp+8h] [rbp-30h]

if ( argc <= 1 )
{
fwrite("program table_size\n", 1uLL, 0x13uLL, stderr);
result = 1;
}
else
{
v3 = strtoul(argv[1], 0LL, 0);
v4 = v3;
if ( v3 <= 0 )
{
fprintf(stderr, "table_size=%d <= 0\n", (unsigned int)v3);
result = 1;
}
else
{
v5 = 4LL * v3;
v6 = malloc(v5);
v7 = malloc(v5);
v8 = v7;
if ( !v6 || !v7 )
{
if ( v6 )
free(v6);
if ( v8 )
free(v6);
}
seq((__int64)v6, v4);
seq((__int64)v8, v4);
printf("sequential scan... ");
fflush(stdout);
v9 = clock();
v14 = (double)(int)(clock() - v9);
printf("took %0.2fs\n", v14 / 1000000.0);
printf("shuffling indexes... ");
fflush(stdout);
v10 = time(0LL);
srand(v10);
shuffle((__int64)v8, v4);
putchar(10);
printf("random scan... ");
fflush(stdout);
v11 = clock();
v12 = clock();
v15 = (double)((int)v12 - (int)v11);
printf("took %0.2fs\n", v15 / 1000000.0);
if ( v11 != v12 )
printf("slower %0.3f times\n", v15 / v14);
free(v6);
free(v8);
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // ebx
size_t v5; // rbp
void *v6; // r12
void *v7; // rax
void *v8; // rbp
int v9; // er13
unsigned int v10; // eax
clock_t v11; // r13
clock_t v12; // rbx
int result; // eax
double v14; // [rsp+0h] [rbp-38h]
double v15; // [rsp+8h] [rbp-30h]

if ( argc <= 1 )
{
fwrite("program table_size\n", 1uLL, 0x13uLL, stderr);
result = 1;
}
else
{
v3 = strtoul(argv[1], 0LL, 0);
v4 = v3;
if ( v3 <= 0 )
{
fprintf(stderr, "table_size=%d <= 0\n", (unsigned int)v3);
result = 1;
}
else
{
v5 = 4LL * v3;
v6 = malloc(v5);
v7 = malloc(v5);
v8 = v7;
if ( !v6 || !v7 )
{
if ( v6 )
free(v6);
if ( v8 )
free(v6);
}
func7((__int64)v6, v4);
func7((__int64)v8, v4);
printf("sequential scan... ");
fflush(stdout);
v9 = clock();
v14 = (double)(int)(clock() - v9);
printf("took %0.2fs\n", v14 / 1000000.0);
printf("shuffling indexes... ");
fflush(stdout);
v10 = time(0LL);
srand(v10);
func8((__int64)v8, v4);
putchar(10);
printf("random scan... ");
fflush(stdout);
v11 = clock();
v12 = clock();
v15 = (double)((int)v12 - (int)v11);
printf("took %0.2fs\n", v15 / 1000000.0);
if ( v11 != v12 )
printf("slower %0.3f times\n", v15 / v14);
free(v6);
free(v8);
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char* argv[]) {
 int n = 0;
 uint32_t* table = ((void *)0);
 uint32_t* indexes = ((void *)0);
 clock_t ta1, ta2;
 clock_t tb1, tb2;
 if (argc < 2) {
  fprintf(stderr, "program table_size\n");
  return 1;
 }
 n = strtoul(argv[1], ((void *)0), 0);
 if (n <= 0) {
  fprintf(stderr, "table_size=%d <= 0\n", n);
  return 1;
 }
 table = malloc(sizeof(uint32_t)*n);
 indexes = malloc(sizeof(uint32_t)*n);
 if (table == ((void *)0) || indexes == ((void *)0)) {
  if (table) free(table);
  if (indexes) free(table);
 }
 seq(table, n);
 seq(indexes, n);
 printf("sequential scan... "); fflush(stdout);
 ta1 = clock();
  scanmem(table, indexes, n);
 ta2 = clock();
 printf("took %0.2fs\n", (double)(ta2 - ta1)/((__clock_t) 1000000));
 printf("shuffling indexes... "); fflush(stdout);
 srand(time(((void *)0)));
 shuffle(indexes, n);
 putchar('\n');
 printf("random scan... "); fflush(stdout);
 tb1 = clock();
  scanmem(table, indexes, n);
 tb2 = clock();
 printf("took %0.2fs\n", (double)(tb2 - tb1)/((__clock_t) 1000000));
 if (tb2 - tb1 != 0) {
  printf("slower %0.3f times\n", (double)(tb2 - tb1)/(ta2 - ta1));
 }
 free(table);
 free(indexes);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int n = 0;
 unsigned int *table = ((void *)0);
 unsigned int *indexes = ((void *)0);
 long ta1; long ta2;
 long tb1; long tb2;
 if (argc < 2) {
  fprintf(stderr, "program table_size\n");
  return 1;
 }
 n = strtoul(argv[1], ((void *)0), 0);
 if (n <= 0) {
  fprintf(stderr, "table_size=%d <= 0\n", n);
  return 1;
 }
 table = malloc(sizeof(unsigned int)*n);
 indexes = malloc(sizeof(unsigned int)*n);
 if (table == ((void *)0) || indexes == ((void *)0)) {
  if (table) free(table);
  if (indexes) free(table);
 }
 seq(table, n);
 seq(indexes, n);
 printf("sequential scan... "); fflush(stdout);
 ta1 = clock();
  scanmem(table, indexes, n);
 ta2 = clock();
 printf("took %0.2fs\n", (double)(ta2 - ta1)/((long) 1000000));
 printf("shuffling indexes... "); fflush(stdout);
 srand(time(((void *)0)));
 shuffle(indexes, n);
 putchar('\n');
 printf("random scan... "); fflush(stdout);
 tb1 = clock();
  scanmem(table, indexes, n);
 tb2 = clock();
 printf("took %0.2fs\n", (double)(tb2 - tb1)/((long) 1000000));
 if (tb2 - tb1 != 0) {
  printf("slower %0.3f times\n", (double)(tb2 - tb1)/(ta2 - ta1));
 }
 free(table);
 free(indexes);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: n int

variable_types:
table
unsigned int *


decompiled_code:
size_t __fastcall save_8bit_width(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
char *v4; // r14
char *v5; // r13
int v6; // ebp
unsigned __int8 v7; // bl
size_t result; // rax

v4 = (char *)&palette + 3 * a4;
v5 = (char *)&palette + 3 * a3;
v6 = 8;
v7 = 0x80;
do
{
if ( (v7 & a2) != 0 )
result = fwrite(v5, 3uLL, 1uLL, stdout);
else
result = fwrite(v4, 3uLL, 1uLL, stdout);
v7 >>= 1;
--v6;
}
while ( v6 );
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
char *v4; // r14
char *v5; // r13
int v6; // ebp
unsigned __int8 v7; // bl
size_t result; // rax

v4 = (char *)&palette + 3 * a4;
v5 = (char *)&palette + 3 * a3;
v6 = 8;
v7 = 0x80;
do
{
if ( (v7 & a2) != 0 )
result = fwrite(v5, 3uLL, 1uLL, stdout);
else
result = fwrite(v4, 3uLL, 1uLL, stdout);
v7 >>= 1;
--v6;
}
while ( v6 );
return result;
}

original_code:
void save_8bit_width(uint8_t char_code, uint8_t font_row, uint8_t fore, uint8_t back) {
 uint8_t mask;
 for (mask = 0x80; mask != 0; mask >>= 1) {
  if (font_row & mask)
   fwrite(&palette[fore][0], 3, 1, stdout);
  else
   fwrite(&palette[back][0], 3, 1, stdout);
 }
}

canonical_original_code:
void save_8bit_width(unsigned char char_code, unsigned char font_row, unsigned char fore, unsigned char back) {
 unsigned char mask;
 for (mask = 0x80; mask != 0; mask >>= 1) {
  if (font_row & mask)
   fwrite(&palette[fore][0], 3, 1, stdout);
  else
   fwrite(&palette[back][0], 3, 1, stdout);
 }
}

variable_types:
fore
unsigned char

variable_types:
back
unsigned char

variable_types:
mask
unsigned char


decompiled_code:
size_t __fastcall save_9bit_width(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
size_t result; // rax

save_8bit_width(a1, a2, a3, a4);
if ( (unsigned __int8)(a1 + 65) <= 0x20u && (a2 & 1) != 0 )
result = fwrite((char *)&palette + 3 * a3, 3uLL, 1uLL, stdout);
else
result = fwrite((char *)&palette + 3 * a4, 3uLL, 1uLL, stdout);
return result;
}

canonical_decompiled_code:
size_t __fastcall func8(unsigned __int8 a1, unsigned __int8 a2, unsigned __int8 a3, unsigned __int8 a4)
{
size_t result; // rax

func7(a1, a2, a3, a4);
if ( (unsigned __int8)(a1 + 65) <= 0x20u && (a2 & 1) != 0 )
result = fwrite((char *)&palette + 3 * a3, 3uLL, 1uLL, stdout);
else
result = fwrite((char *)&palette + 3 * a4, 3uLL, 1uLL, stdout);
return result;
}

original_code:
void save_9bit_width(uint8_t char_code, uint8_t font_row, uint8_t fore, uint8_t back) {
 save_8bit_width(char_code, font_row, fore, back);
 if (char_code >= 0xbf && char_code <= 0xdf && (font_row & 0x01))
  fwrite(&palette[fore][0], 3, 1, stdout);
 else
  fwrite(&palette[back][0], 3, 1, stdout);
}

canonical_original_code:
void save_9bit_width(unsigned char char_code, unsigned char font_row, unsigned char fore, unsigned char back) {
 save_8bit_width(char_code, font_row, fore, back);
 if (char_code >= 0xbf && char_code <= 0xdf && (font_row & 0x01))
  fwrite(&palette[fore][0], 3, 1, stdout);
 else
  fwrite(&palette[back][0], 3, 1, stdout);
}


swapbits

decompiled_code:
__int64 __fastcall swapbits(int a1)
{
return a1 & 0xFFFFFFAA | (4 * (_BYTE)a1) & 0x44 | ((int)(unsigned __int8)a1 >> 2) & 0x11;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
return a1 & 0xFFFFFFAA | (4 * (_BYTE)a1) & 0x44 | ((int)(unsigned __int8)a1 >> 2) & 0x11;
}

canonical_original_code:
unsigned char swapbits(unsigned char b) {
 return (b & 0xaa) | ((b & 0x44) >> 2) | ((b & 0x11) << 2);
}

variable_types:
b
unsigned char

return_type: unsigned char


ordie

decompiled_code:
int *__fastcall ordie(const char *a1)
{
int *result; // rax
unsigned int *v2; // rbx
unsigned int v3; // eax

result = __errno_location();
if ( *result )
{
v2 = (unsigned int *)result;
v3 = (unsigned int)strerror(*result);
fprintf(stderr, "%s [errno=%d]: %s\n", a1, *v2, (const char *)v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
int *__fastcall func11(const char *a1)
{
int *result; // rax
unsigned int *v2; // rbx
unsigned int v3; // eax

result = __errno_location();
if ( *result )
{
v2 = (unsigned int *)result;
v3 = (unsigned int)strerror(*result);
fprintf(stderr, "%s [errno=%d]: %s\n", a1, *v2, (const char *)v3);
exit(1);
}
return result;
}

original_code:
void ordie(char* info) {
 if ((*__errno_location ()) != 0) {
  fprintf(stderr, "%s [errno=%d]: %s\n", info, (*__errno_location ()), strerror((*__errno_location ())));
  exit(1);
 }
}

canonical_original_code:
void ordie(char *info) {
 if ((*__errno_location ()) != 0) {
  fprintf(stderr, "%s [errno=%d]: %s\n", info, (*__errno_location ()), strerror((*__errno_location ())));
  exit(1);
 }
}

variable_types:
info
char *


usage

decompiled_code:
void __noreturn usage()
{
fwrite(
"Program save contents of console in PNM file\n"
"(PNM is printed on standard output\n"
"\n"
"usage:\n"
"\tttyscreenshot [8|9] console-num\n"
"\n"
"First argument is a character width in pixels;\n"
"9 pixels is a default width use by EGA/VGA cards,\n"
"8 pixels isn't.\n"
"\n"
"You need permissions to read /dev/vcsa[console-num] device.\n",
1uLL,
0x128uLL,
stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func9()
{
fwrite(
"Program save contents of console in PNM file\n"
"(PNM is printed on standard output\n"
"\n"
"usage:\n"
"\tttyscreenshot [8|9] console-num\n"
"\n"
"First argument is a character width in pixels;\n"
"9 pixels is a default width use by EGA/VGA cards,\n"
"8 pixels isn't.\n"
"\n"
"You need permissions to read /dev/vcsa[console-num] device.\n",
1uLL,
0x128uLL,
stderr);
exit(1);
}

original_code:
void usage() {
 fputs(
  "Program save contents of console in PNM file\n"
  "(PNM is printed on standard output\n"
  "\n"
  "usage:\n"
  "\tttyscreenshot [8|9] console-num\n"
  "\n"
  "First argument is a character width in pixels;\n"
  "9 pixels is a default width use by EGA/VGA cards,\n"
  "8 pixels isn't.\n"
  "\n"
  "You need permissions to read /dev/vcsa[console-num] device.\n",
  stderr
 );
 exit(1);
}


die

decompiled_code:
void __fastcall __noreturn die(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func12(const char *a1)
{
fprintf(stderr, "%s\n", a1);
exit(1);
}

original_code:
void die(char* info) {
 fprintf(stderr, "%s\n", info);
 exit(1);
}

canonical_original_code:
void die(char *info) {
 fprintf(stderr, "%s\n", info);
 exit(1);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
unsigned int v5; // ebp
int v6; // er12
int *v7; // r13
unsigned __int8 *v8; // r12
void *v9; // r14
unsigned int v10; // eax
unsigned __int8 v11; // bl
unsigned __int8 v12; // al
__int64 v13; // rbp
int i; // er15
int v16; // [rsp+8h] [rbp-1060h]
int fd; // [rsp+Ch] [rbp-105Ch]
unsigned __int8 v18; // [rsp+1Eh] [rbp-104Ah] BYREF
unsigned __int8 buf; // [rsp+1Fh] [rbp-1049h] BYREF
char s[4096]; // [rsp+20h] [rbp-1048h] BYREF
__int16 v21[4]; // [rsp+1020h] [rbp-48h] BYREF
char *v22; // [rsp+1028h] [rbp-40h]

if ( argc <= 2 )
usage(argc, argv, envp);
v3 = atoi(argv[1]);
if ( (unsigned int)(v3 - 8) > 1 )
die("First argument (character width) must be either 8 or 9.");
v4 = atoi(argv[2]);
v5 = v4;
if ( v4 > 0x3F )
die("Second argument (console number) must lie in range 0..63");
snprintf(s, 0x1000uLL, "/dev/tty%d", v4);
v6 = open(s, 2);
ordie("open(tty)");
v21[0] = 256;
v21[1] = 32;
v22 = font;
ioctl(v6, 0x4B6BuLL, v21);
ordie("ioctl(GIO_FONTX)");
ioctl(v6, 0x4B70uLL, &palette);
v7 = __errno_location();
if ( *v7 )
{
v10 = (unsigned int)strerror(*v7);
fprintf(
stderr,
"Can't load palette, using defaults. Reason [errno=%d]: %s\n",
(unsigned int)*v7,
(const char *)v10);
*v7 = 0;
}
close(v6);
ordie("close(tty)");
snprintf(s, 0x1000uLL, "/dev/vcsa%d", v5);
fd = open(s, 2);
ordie("open(vcsa)");
read(fd, &buf, 1uLL);
ordie("read(lines)");
read(fd, &v18, 1uLL);
ordie("read(columns)");
v8 = (unsigned __int8 *)malloc(2 * v18);
if ( !v8 )
die("malloc failed");
lseek(fd, 4LL, 0);
v9 = save_8bit_width;
if ( v3 != 8 )
v9 = save_9bit_width;
printf("P6\n%d %d\n255\n", v3 * (unsigned int)v18, 16 * (unsigned int)buf);
if ( buf )
{
v16 = 0;
do
{
read(fd, v8, 2 * (unsigned int)v18);
for ( i = 0; i != 16; ++i )
{
v13 = 0LL;
if ( v18 )
{
do
{
v11 = v8[v13];
v12 = swapbits(v8[v13 + 1]);
((void (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))v9)(
v11,
(unsigned __int8)font[32 * v11 + i],
v12 & 0xF,
v12 >> 4);
v13 += 2LL;
}
while ( 2 * v18 > (int)v13 );
}
}
++v16;
}
while ( buf > v16 );
}
free(v8);
close(fd);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
unsigned int v5; // ebp
int v6; // er12
int *v7; // r13
unsigned __int8 *v8; // r12
void *v9; // r14
unsigned int v10; // eax
unsigned __int8 v11; // bl
unsigned __int8 v12; // al
__int64 v13; // rbp
int i; // er15
int v16; // [rsp+8h] [rbp-1060h]
int fd; // [rsp+Ch] [rbp-105Ch]
unsigned __int8 v18; // [rsp+1Eh] [rbp-104Ah] BYREF
unsigned __int8 buf; // [rsp+1Fh] [rbp-1049h] BYREF
char s[4096]; // [rsp+20h] [rbp-1048h] BYREF
__int16 v21[4]; // [rsp+1020h] [rbp-48h] BYREF
char *v22; // [rsp+1028h] [rbp-40h]

if ( argc <= 2 )
func9(argc, argv, envp);
v3 = atoi(argv[1]);
if ( (unsigned int)(v3 - 8) > 1 )
func12("First argument (character width) must be either 8 or 9.");
v4 = atoi(argv[2]);
v5 = v4;
if ( v4 > 0x3F )
func12("Second argument (console number) must lie in range 0..63");
snprintf(s, 0x1000uLL, "/dev/tty%d", v4);
v6 = open(s, 2);
func11("open(tty)");
v21[0] = 256;
v21[1] = 32;
v22 = font;
ioctl(v6, 0x4B6BuLL, v21);
func11("ioctl(GIO_FONTX)");
ioctl(v6, 0x4B70uLL, &palette);
v7 = __errno_location();
if ( *v7 )
{
v10 = (unsigned int)strerror(*v7);
fprintf(
stderr,
"Can't load palette, using defaults. Reason [errno=%d]: %s\n",
(unsigned int)*v7,
(const char *)v10);
*v7 = 0;
}
close(v6);
func11("close(tty)");
snprintf(s, 0x1000uLL, "/dev/vcsa%d", v5);
fd = open(s, 2);
func11("open(vcsa)");
read(fd, &buf, 1uLL);
func11("read(lines)");
read(fd, &v18, 1uLL);
func11("read(columns)");
v8 = (unsigned __int8 *)malloc(2 * v18);
if ( !v8 )
func12("malloc failed");
lseek(fd, 4LL, 0);
v9 = save_8bit_width;
if ( v3 != 8 )
v9 = save_9bit_width;
printf("P6\n%d %d\n255\n", v3 * (unsigned int)v18, 16 * (unsigned int)buf);
if ( buf )
{
v16 = 0;
do
{
read(fd, v8, 2 * (unsigned int)v18);
for ( i = 0; i != 16; ++i )
{
v13 = 0LL;
if ( v18 )
{
do
{
v11 = v8[v13];
v12 = func10(v8[v13 + 1]);
((void (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))v9)(
v11,
(unsigned __int8)font[32 * v11 + i],
v12 & 0xF,
v12 >> 4);
v13 += 2LL;
}
while ( 2 * v18 > (int)v13 );
}
}
++v16;
}
while ( buf > v16 );
}
free(v8);
close(fd);
return 0;
}

original_code:
int main(int argv, char* argc[]) {
 int fd;
 struct consolefontdesc dsc;
 char path[4096];
 save_fun save;
 int char_width, console_num;
 uint8_t lines, columns;
 uint8_t c, attr, fore, back;
 int col, line, y;
 uint8_t* char_row;
 if (argv < 3)
  usage();
 char_width = atoi(argc[1]);
 if (char_width != 8 && char_width != 9)
  die("First argument (character width) must be either 8 or 9.");
 console_num = atoi(argc[2]);
 if (console_num < 0 || console_num > 63)
  die("Second argument (console number) must lie in range 0..63");
 snprintf(path, 4096, "/dev/tty%d", console_num);
 fd = open(path, 02); ordie("open(tty)");
 dsc.charcount = 256;
 dsc.charheight = 32;
 dsc.chardata = (void*)font;
 ioctl(fd, 0x4B6B, &dsc); ordie("ioctl(GIO_FONTX)");
 ioctl(fd, 0x4B70, &palette);
 if ((*__errno_location ())) {
  fprintf(stderr, "Can't load palette, using defaults.  Reason [errno=%d]: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  (*__errno_location ()) = 0;
 }
 close(fd); ordie("close(tty)");
 snprintf(path, 4096, "/dev/vcsa%d", console_num);
 fd = open(path, 02); ordie("open(vcsa)");
 read(fd, &lines, 1); ordie("read(lines)");
 read(fd, &columns, 1); ordie("read(columns)");
 char_row = (uint8_t*)malloc(columns*2);
 if (char_row == ((void *)0))
  die("malloc failed");
 lseek(fd, 4, 0);
 if (char_width == 8)
  save = save_8bit_width;
 else
  save = save_9bit_width;
 printf("P6\n%d %d\n255\n", columns*char_width, lines*16);
 for (line=0; line < lines; line++) {
  read(fd, char_row, columns*2);
  for (y=0; y < 16; y++) {
   for (col=0; col < columns*2; col+=2) {
    c = char_row[col];
    attr = swapbits(char_row[col+1]);
    fore = attr & 0x0f;
    back = attr >> 4;
    save(c, font[c][y], fore, back);
   }
  }
 }
 free(char_row);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argv, char *argc[]) {
 int fd;
 struct consolefontdesc dsc;
 char path[4096];
 void (*save)(unsigned char char_code, unsigned char font_row, unsigned char fore, unsigned char back);
 int char_width; int console_num;
 unsigned char lines; unsigned char columns;
 unsigned char c; unsigned char attr; unsigned char fore; unsigned char back;
 int col; int line; int y;
 unsigned char *char_row;
 if (argv < 3)
  usage();
 char_width = atoi(argc[1]);
 if (char_width != 8 && char_width != 9)
  die("First argument (character width) must be either 8 or 9.");
 console_num = atoi(argc[2]);
 if (console_num < 0 || console_num > 63)
  die("Second argument (console number) must lie in range 0..63");
 snprintf(path, 4096, "/dev/tty%d", console_num);
 fd = open(path, 02); ordie("open(tty)");
 dsc.charcount = 256;
 dsc.charheight = 32;
 dsc.chardata = (void *)font;
 ioctl(fd, 0x4B6B, &dsc); ordie("ioctl(GIO_FONTX)");
 ioctl(fd, 0x4B70, &palette);
 if ((*__errno_location ())) {
  fprintf(stderr, "Can't load palette, using defaults.  Reason [errno=%d]: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  (*__errno_location ()) = 0;
 }
 close(fd); ordie("close(tty)");
 snprintf(path, 4096, "/dev/vcsa%d", console_num);
 fd = open(path, 02); ordie("open(vcsa)");
 read(fd, &lines, 1); ordie("read(lines)");
 read(fd, &columns, 1); ordie("read(columns)");
 char_row = (unsigned char *)malloc(columns*2);
 if (char_row == ((void *)0))
  die("malloc failed");
 lseek(fd, 4, 0);
 if (char_width == 8)
  save = save_8bit_width;
 else
  save = save_9bit_width;
 printf("P6\n%d %d\n255\n", columns*char_width, lines*16);
 for (line=0; line < lines; line++) {
  read(fd, char_row, columns*2);
  for (y=0; y < 16; y++) {
   for (col=0; col < columns*2; col+=2) {
    c = char_row[col];
    attr = swapbits(char_row[col+1]);
    fore = attr & 0x0f;
    back = attr >> 4;
    save(c, font[c][y], fore, back);
   }
  }
 }
 free(char_row);
 close(fd);
 return 0;
}

variable_types: argv int

variable_types:
argc
char *[]

variable_types: fd int

variable_types: struct consolefontdesc { unsigned short charcount; unsigned short charheight; char *chardata; }

variable_types:
path
char [4096]

variable_types: void (*)(unsigned char char_code, unsigned char font_row, unsigned char fore, unsigned char back)

variable_types:
lines
unsigned char

variable_types:
columns
unsigned char

variable_types:
c
unsigned char

variable_types:
attr
unsigned char

variable_types: col int

variable_types: line int

variable_types: y int


decompiled_code:
_BOOL8 __fastcall is_pattern_old(unsigned __int16 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 )
result = ((unsigned __int16)-a1 & a1) == -(__int16)a1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(unsigned __int16 a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 )
result = ((unsigned __int16)-a1 & a1) == -(__int16)a1;
return result;
}

original_code:
int is_pattern_old(uint16_t x) {
    const uint16_t n = -x;
    return (x > 0) && n == (n & x);
}

canonical_original_code:
int is_pattern_old(unsigned short x) {
    unsigned short n = -x;
    return (x > 0) && n == (n & x);
}

variable_types:
x
unsigned short

variable_types:
n
unsigned short


decompiled_code:
_BOOL8 __fastcall is_pattern(unsigned __int16 a1)
{
return (unsigned __int16)(a1 ^ -a1) < a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(unsigned __int16 a1)
{
return (unsigned __int16)(a1 ^ -a1) < a1;
}

original_code:
int is_pattern(uint16_t x) {
    const uint16_t n = -x;
    return (n ^ x) < x;
}

canonical_original_code:
int is_pattern(unsigned short x) {
    unsigned short n = -x;
    return (n ^ x) < x;
}


decompiled_code:
__int64 __fastcall is_pattern_naive(__int16 a1)
{
__int16 v1; // ax
unsigned int v2; // edx

v1 = a1;
v2 = 0;
if ( a1 < 0 )
{
while ( 1 )
{
v1 *= 2;
if ( !v1 )
break;
if ( v1 >= 0 )
return 0;
}
v2 = 1;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int16 a1)
{
__int16 v1; // ax
unsigned int v2; // edx

v1 = a1;
v2 = 0;
if ( a1 < 0 )
{
while ( 1 )
{
v1 *= 2;
if ( !v1 )
break;
if ( v1 >= 0 )
return 0;
}
v2 = 1;
}
return v2;
}

original_code:
int is_pattern_naive(uint16_t x) {
    if (x == 0) {
        return 0;
    }
    while (x > 0) {
        if ((x & 0x8000) == 0) {
            return 0;
        }
        x <<= 1;
    }
    return 1;
}

canonical_original_code:
int is_pattern_naive(unsigned short x) {
    if (x == 0) {
        return 0;
    }
    while (x > 0) {
        if ((x & 0x8000) == 0) {
            return 0;
        }
        x <<= 1;
    }
    return 1;
}


verify

decompiled_code:
unsigned int verify()
{
unsigned int i; // ebx
unsigned int v1; // ebp
unsigned int result; // eax

for ( i = 0; i != 0x10000; ++i )
{
v1 = is_pattern_naive(i);
result = is_pattern(i);
if ( v1 != result )
{
printf("failed for %04x: result %d, expected %d\n", i, result, v1);
exit(1);
}
if ( result )
result = printf("pattern: %04x\n", i);
}
return result;
}

canonical_decompiled_code:
unsigned int func10()
{
unsigned int i; // ebx
unsigned int v1; // ebp
unsigned int result; // eax

for ( i = 0; i != 0x10000; ++i )
{
v1 = func9(i);
result = func8(i);
if ( v1 != result )
{
printf("failed for %04x: result %d, expected %d\n", i, result, v1);
exit(1);
}
if ( result )
result = printf("pattern: %04x\n", i);
}
return result;
}

original_code:
void verify() {
    for (int i=0; i < 65536; i++) {
        int expected = is_pattern_naive(i);
        int result = is_pattern(i);
        if (expected != result) {
            printf("failed for %04x: result %d, expected %d\n", i, result, expected);
            exit(1);
        }
        if (result) {
            printf("pattern: %04x\n", i);
        }
    }
}

canonical_original_code:
void verify() {
    for (int i = 0; i < 65536; i++) {
        int expected = is_pattern_naive(i);
        int result = is_pattern(i);
        if (expected != result) {
            printf("failed for %04x: result %d, expected %d\n", i, result, expected);
            exit(1);
        }
        if (result) {
            printf("pattern: %04x\n", i);
        }
    }
}

variable_types: i int

variable_types: expected int

variable_types: result int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
verify();
puts("All OK");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func10();
puts("All OK");
return 0;
}

original_code:
int main() {
    verify();
    puts("All OK");
}


decompiled_code:
__int64 __fastcall isolate_lowest_set(int a1)
{
return a1 & (unsigned int)-a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return a1 & (unsigned int)-a1;
}

original_code:
uint32_t isolate_lowest_set(uint32_t x) {
    return x & -x;
}

canonical_original_code:
unsigned int isolate_lowest_set(unsigned int x) {
    return x & -x;
}

variable_types:
x
unsigned int


decompiled_code:
_BOOL8 __fastcall is_power_of_two_non_zero(int a1)
{
return (unsigned int)isolate_lowest_set(a1) == a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func8(int a1)
{
return (unsigned int)func7(a1) == a1;
}

original_code:
int is_power_of_two_non_zero(uint32_t x) {
    return isolate_lowest_set(x) == x;
}

canonical_original_code:
int is_power_of_two_non_zero(unsigned int x) {
    return isolate_lowest_set(x) == x;
}


decompiled_code:
_BOOL8 __fastcall is_power_of_two(int a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 )
result = is_power_of_two_non_zero(a1);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(int a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( a1 )
result = func8(a1);
return result;
}

original_code:
int is_power_of_two(uint32_t x) {
    return x != 0 && is_power_of_two_non_zero(x);
}

canonical_original_code:
int is_power_of_two(unsigned int x) {
    return x != 0 && is_power_of_two_non_zero(x);
}


decompiled_code:
__int64 __fastcall is_power_of_two_naive(int a1)
{
int v1; // edx
int i; // eax

if ( a1 == 1 )
return 1LL;
v1 = 31;
for ( i = 2; a1 != i; i *= 2 )
{
if ( !--v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1)
{
int v1; // edx
int i; // eax

if ( a1 == 1 )
return 1LL;
v1 = 31;
for ( i = 2; a1 != i; i *= 2 )
{
if ( !--v1 )
return 0LL;
}
return 1LL;
}

original_code:
int is_power_of_two_naive(uint32_t x) {
    uint32_t bit = 1;
    for (int i=0; i < 32; i++, bit <<= 1) {
        if (x == bit) {
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int is_power_of_two_naive(unsigned int x) {
    unsigned int bit = 1;
    for (int i = 0; i < 32; i++, bit <<= 1) {
        if (x == bit) {
            return 1;
        }
    }
    return 0;
}

variable_types:
bit
unsigned int


verify

decompiled_code:
__int64 verify()
{
int i; // ebp
int v1; // er12
unsigned int v2; // ebx
int v3; // er12
__int64 result; // rax

for ( i = 1; ; ++i )
{
v2 = i - 1;
if ( ((i - 1) & 0xFFFFF) == 0 )
{
printf("%x\n", v2);
v1 = is_power_of_two(v2);
if ( v1 != (unsigned int)is_power_of_two_naive(v2) )
goto LABEL_8;
continue;
}
v3 = is_power_of_two(v2);
result = is_power_of_two_naive(v2);
if ( v3 != (_DWORD)result )
LABEL_8:
__assert_fail("is_power_of_two(x) == is_power_of_two_naive(x)", "is_power_of_two.c", 0x32u, "verify");
if ( !i )
break;
}
return result;
}

canonical_decompiled_code:
__int64 func11()
{
int i; // ebp
int v1; // er12
unsigned int v2; // ebx
int v3; // er12
__int64 result; // rax

for ( i = 1; ; ++i )
{
v2 = i - 1;
if ( ((i - 1) & 0xFFFFF) == 0 )
{
printf("%x\n", v2);
v1 = func9(v2);
if ( v1 != (unsigned int)func10(v2) )
goto LABEL_8;
continue;
}
v3 = func9(v2);
result = func10(v2);
if ( v3 != (_DWORD)result )
LABEL_8:
__assert_fail("is_power_of_two(x) == is_power_of_two_naive(x)", "is_power_of_two.c", 0x32u, "verify");
if ( !i )
break;
}
return result;
}

original_code:
void verify() {
    uint32_t x = 0;
    while (1) {
        if ((x & 0xfffff) == 0) {
            printf("%x\n", x);
        }
        ((is_power_of_two(x) == is_power_of_two_naive(x)) ? (void) (0) : __assert_fail ("is_power_of_two(x) == is_power_of_two_naive(x)", "is_power_of_two.c", 50, __extension__ __PRETTY_FUNCTION__));
        x += 1;
        if (x == 0) break;
    }
}

canonical_original_code:
void verify() {
    unsigned int x = 0;
    while (1) {
        if ((x & 0xfffff) == 0) {
            printf("%x\n", x);
        }
        ((is_power_of_two(x) == is_power_of_two_naive(x)) ? (void) (0) : __assert_fail ("is_power_of_two(x) == is_power_of_two_naive(x)", "is_power_of_two.c", 50, __extension__ __PRETTY_FUNCTION__));
        x += 1;
        if (x == 0) break;
    }
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
verify(argc, argv, envp);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func11(argc, argv, envp);
return 0;
}

original_code:
int main() {
    verify();
}

canonical_original_code:
int main() {
    verify();
}


naive

original_code:
uint32_t naive(uint32_t src, uint32_t mask) {
    uint32_t result = 0;
    uint32_t mask_bit = 1;
    uint32_t src_bit = 1;
    int i;
    for (i=0; i < 32; i++, mask_bit <<= 1) {
        if (mask & mask_bit) {
            if (src & src_bit) {
                result |= mask_bit;
            }
            src_bit <<= 1;
        }
    }
    return result;
}

canonical_original_code:
unsigned int naive(unsigned int src, unsigned int mask) {
    unsigned int result = 0;
    unsigned int mask_bit = 1;
    unsigned int src_bit = 1;
    int i;
    for (i=0; i < 32; i++, mask_bit <<= 1) {
        if (mask & mask_bit) {
            if (src & src_bit) {
                result |= mask_bit;
            }
            src_bit <<= 1;
        }
    }
    return result;
}

variable_types:
src
unsigned int

variable_types:
mask
unsigned int

variable_types:
result
unsigned int


branchless

decompiled_code:
__int64 __fastcall branchless(unsigned int a1, int a2)
{
int v2; // eax
unsigned int v3; // ecx

v2 = a2 & -a2;
if ( !v2 )
return 0;
v3 = 0;
do
{
v3 |= v2 & ((int)(a1 << 31) >> 31);
a2 &= ~v2;
a1 >>= 1;
v2 = a2 & -a2;
}
while ( v2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
int v2; // eax
unsigned int v3; // ecx

v2 = a2 & -a2;
if ( !v2 )
return 0;
v3 = 0;
do
{
v3 |= v2 & ((int)(a1 << 31) >> 31);
a2 &= ~v2;
a1 >>= 1;
v2 = a2 & -a2;
}
while ( v2 );
return v3;
}

original_code:
uint32_t branchless(uint32_t src, uint32_t mask) {
    uint32_t result = 0;
    while (1) {
        const uint32_t lowest = -mask & mask;
        if (lowest == 0) {
            break;
        }
        const uint32_t LSB = (uint32_t)((int32_t)(src << 31) >> 31);
        result |= LSB & lowest;
        mask &= ~lowest;
        src >>= 1;
    }
    return result;
}

canonical_original_code:
unsigned int branchless(unsigned int src, unsigned int mask) {
    unsigned int result = 0;
    while (1) {
        unsigned int lowest = -mask & mask;
        if (lowest == 0) {
            break;
        }
        unsigned int LSB = (uint32_t)((int32_t)(src << 31) >> 31);
        result |= LSB & lowest;
        mask &= ~lowest;
        src >>= 1;
    }
    return result;
}

variable_types:
lowest
unsigned int

variable_types:
LSB
unsigned int


compare

decompiled_code:
__int64 compare()
{
unsigned int i; // ebx
int v1; // ebp
__int64 result; // rax

for ( i = 0; i != 16; ++i )
{
v1 = naive(i, 16843009);
result = branchless(i, 16843009);
if ( v1 != (_DWORD)result )
__assert_fail("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 0x4Fu, "compare");
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
unsigned int i; // ebx
int v1; // ebp
__int64 result; // rax

for ( i = 0; i != 16; ++i )
{
v1 = func7(i, 16843009);
result = func8(i, 16843009);
if ( v1 != (_DWORD)result )
__assert_fail("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 0x4Fu, "compare");
}
return result;
}

original_code:
void compare() {
    const uint32_t mask = 0x01010101;
    for (int i=0; i < 16; i++) {
        ((naive(i, mask) == branchless(i, mask)) ? (void) (0) : __assert_fail ("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 79, __extension__ __PRETTY_FUNCTION__));
    }
}

canonical_original_code:
void compare() {
    unsigned int mask = 0x01010101;
    for (int i = 0; i < 16; i++) {
        ((naive(i, mask) == branchless(i, mask)) ? (void) (0) : __assert_fail ("naive(i, mask) == branchless(i, mask)", "pdep_soft_emu.c", 79, __extension__ __PRETTY_FUNCTION__));
    }
}


decompiled_code:
double __fastcall test_naive(int a1, int a2)
{
int v2; // er13
int i; // ebx
int v5; // [rsp+Ch] [rbp-2Ch]

v5 = 0;
v2 = get_time();
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v5 += naive(i, a2);
}
return (double)(int)(get_time() - v2) / 1000000.0;
}

canonical_decompiled_code:
double __fastcall func11(int a1, int a2)
{
int v2; // er13
int i; // ebx
int v5; // [rsp+Ch] [rbp-2Ch]

v5 = 0;
v2 = func9();
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v5 += func7(i, a2);
}
return (double)(int)(func9() - v2) / 1000000.0;
}

original_code:
double test_naive(int iterations, const uint32_t mask) {
    volatile uint32_t result = 0;
    const uint32_t t1 = get_time();
    for (int i=0; i < iterations; i++) {
        result += naive(i, mask);
    }
    const uint32_t t2 = get_time();
    return (t2 - t1)/1000000.0;
}

canonical_original_code:
double test_naive(int iterations, unsigned int mask) {
    unsigned int result = 0;
    unsigned int t1 = get_time();
    for (int i = 0; i < iterations; i++) {
        result += naive(i, mask);
    }
    unsigned int t2 = get_time();
    return (t2 - t1)/1000000.0;
}

variable_types: iterations int

return_type: double


decompiled_code:
double __fastcall test_branchless(int a1, int a2)
{
int v2; // er13
unsigned int i; // ebx
int v5; // [rsp+Ch] [rbp-2Ch]

v5 = 0;
v2 = get_time();
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v5 += branchless(i, a2);
}
return (double)(int)(get_time() - v2) / 1000000.0;
}

canonical_decompiled_code:
double __fastcall func12(int a1, int a2)
{
int v2; // er13
unsigned int i; // ebx
int v5; // [rsp+Ch] [rbp-2Ch]

v5 = 0;
v2 = func9();
if ( a1 > 0 )
{
for ( i = 0; i != a1; ++i )
v5 += func8(i, a2);
}
return (double)(int)(func9() - v2) / 1000000.0;
}

original_code:
double test_branchless(int iterations, const uint32_t mask) {
    volatile uint32_t result = 0;
    const uint32_t t1 = get_time();
    for (int i=0; i < iterations; i++) {
        result += branchless(i, mask);
    }
    const uint32_t t2 = get_time();
    return (t2 - t1)/1000000.0;
}

canonical_original_code:
double test_branchless(int iterations, unsigned int mask) {
    unsigned int result = 0;
    unsigned int t1 = get_time();
    for (int i = 0; i < iterations; i++) {
        result += branchless(i, mask);
    }
    unsigned int t2 = get_time();
    return (t2 - t1)/1000000.0;
}


decompiled_code:
__int64 get_time()
{
gettimeofday(&T_1, 0LL);
return (unsigned int)(LODWORD(T_1.tv_usec) + 1000000 * LODWORD(T_1.tv_sec));
}

canonical_decompiled_code:
__int64 func9()
{
gettimeofday(&T_1, 0LL);
return (unsigned int)(LODWORD(T_1.tv_usec) + 1000000 * LODWORD(T_1.tv_sec));
}

original_code:
uint32_t get_time(void) {
    static struct timeval T;
    gettimeofday(&T, ((void *)0));
    return (T.tv_sec * 1000000) + T.tv_usec;
}

canonical_original_code:
unsigned int get_time() {
    static struct timeval T;
    gettimeofday(&T, ((void *)0));
    return (T.tv_sec * 1000000) + T.tv_usec;
}

variable_types: struct timeval { long tv_sec; long tv_usec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // ebx
double v5; // rbp
double v6; // xmm1_8

compare(argc, argv, envp);
printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
v3 = 33;
v4 = 0;
do
{
v5 = test_naive(0x100000, v4);
v6 = test_branchless(0x100000, v4);
printf("| %08x | %15.4f | %15.4f | %10.2f |\n", v4, v5, v6, v5 / v6);
v4 = 2 * v4 + 1;
--v3;
}
while ( v3 );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int v4; // ebx
double v5; // rbp
double v6; // xmm1_8

func10(argc, argv, envp);
printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
v3 = 33;
v4 = 0;
do
{
v5 = func11(0x100000, v4);
v6 = func12(0x100000, v4);
printf("| %08x | %15.4f | %15.4f | %10.2f |\n", v4, v5, v6, v5 / v6);
v4 = 2 * v4 + 1;
--v3;
}
while ( v3 );
return 0;
}

original_code:
int main() {
    compare();
    const int iterations = (1 << 20);
    uint32_t mask = 0;
    printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
    for (int i=0; i < 33; i++) {
        const double tn = test_naive(iterations, mask);
        const double tb = test_branchless(iterations, mask);
        const double speedup = tn / tb;
        printf("| %08x | %15.4f | %15.4f | %10.2f |\n", mask, tn, tb, speedup);
        mask = 2*mask + 1;
    }
}

canonical_original_code:
int main() {
    compare();
    int iterations = (1 << 20);
    unsigned int mask = 0;
    printf("| %8s | %15s | %15s | %10s |\n", "mask", "naive", "branchless", "speedup");
    for (int i = 0; i < 33; i++) {
        double tn = test_naive(iterations, mask);
        double tb = test_branchless(iterations, mask);
        double speedup = tn / tb;
        printf("| %08x | %15.4f | %15.4f | %10.2f |\n", mask, tn, tb, speedup);
        mask = 2*mask + 1;
    }
}

variable_types: tn double

variable_types: tb double

variable_types: speedup double


decompiled_code:
_BOOL8 __fastcall anynonzero_epi32(double a1, __m128 _XMM1)
{
char v2; // zf

__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k0, zmm0, zmm1
kortestw k0, k0
}
return !v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(double a1, __m128 _XMM1)
{
char v2; // zf

__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k0, zmm0, zmm1
kortestw k0, k0
}
return !v2;
}

original_code:
int anynonzero_epi32(__m512i x) {
    const __m512i zero = _mm512_setzero_si512();
    const __mmask16 mask = _mm512_cmpneq_epi32_mask(x, zero);
    return mask != 0;
}

canonical_original_code:
int anynonzero_epi32(long long x) {
    long long zero = _mm512_setzero_si512();
    unsigned short mask = _mm512_cmpneq_epi32_mask(x, zero);
    return mask != 0;
}

variable_types:
x
long long

variable_types:
zero
long long

variable_types:
mask
unsigned short


decompiled_code:
__int64 __fastcall anynonzero_epi32_asm(double a1, __m128 _XMM1)
{
__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k1, zmm0, zmm1
ktestw k1, k1
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(double a1, __m128 _XMM1)
{
__asm
{
vpxor xmm1, xmm1, xmm1
vpcmpneqd k1, zmm0, zmm1
ktestw k1, k1
}
return 0LL;
}

original_code:
int anynonzero_epi32_asm(__m512i x) {
    __asm__ __volatile__(
        "vpxor      %xmm1, %xmm1, %xmm1\n"
        "vpcmpneqd	%zmm1, %zmm0, %k1\n"
        "xor        %eax, %eax\n"
        "ktestw     %k1, %k1\n"
        "setne      %al\n"
    );
}

canonical_original_code:
int anynonzero_epi32_asm(long long x) {
    __asm__ __volatile__(
        "vpxor      %xmm1, %xmm1, %xmm1\n"
        "vpcmpneqd	%zmm1, %zmm0, %k1\n"
        "xor        %eax, %eax\n"
        "ktestw     %k1, %k1\n"
        "setne      %al\n"
    );
}


decompiled_code:
__int64 __fastcall decimal_digits_sse(signed int a1)
{
__m128i v1; // xmm0

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_sse.c", 9u, "decimal_digits_sse");
v1 = _mm_shuffle_epi32(_mm_cvtsi32_si128(a1), 0);
_EAX = (unsigned __int16)~_mm_movemask_epi8(
_mm_packs_epi16(
_mm_packs_epi32(
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020E0),
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020F0)),
_mm_packs_epi32(_mm_cmpgt_epi32(v1, (__m128i)xmmword_402100), (__m128i)0LL)));
__asm { tzcnt eax, eax }
return (unsigned int)(_EAX + 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(signed int a1)
{
__m128i v1; // xmm0

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_sse.c", 9u, "decimal_digits_sse");
v1 = _mm_shuffle_epi32(_mm_cvtsi32_si128(a1), 0);
_EAX = (unsigned __int16)~_mm_movemask_epi8(
_mm_packs_epi16(
_mm_packs_epi32(
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020E0),
_mm_cmpgt_epi32(v1, (__m128i)xmmword_4020F0)),
_mm_packs_epi32(_mm_cmpgt_epi32(v1, (__m128i)xmmword_402100), (__m128i)0LL)));
__asm { tzcnt eax, eax }
return (unsigned int)(_EAX + 1);
}

original_code:
int decimal_digits_sse(int32_t x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "decimal_digits_sse.c", 9, __extension__ __PRETTY_FUNCTION__));
    const __m128i powers_a = _mm_setr_epi32(9, 99, 999, 9999);
    const __m128i powers_b = _mm_setr_epi32(99999, 999999, 9999999, 99999999);
    const __m128i powers_c = _mm_setr_epi32(999999999, 2147483647, 2147483647, 2147483647);
    const __m128i value = _mm_set1_epi32(x);
    const __m128i gt0 = _mm_cmpgt_epi32(value, powers_a);
    const __m128i gt1 = _mm_cmpgt_epi32(value, powers_b);
    const __m128i gt2 = _mm_cmpgt_epi32(value, powers_c);
    const __m128i t0 = _mm_packs_epi32(gt0, gt1);
    const __m128i t1 = _mm_packs_epi32(gt2, _mm_setzero_si128());
    const __m128i t2 = _mm_packs_epi16(t0, t1);
    const uint16_t m = ~_mm_movemask_epi8(t2);
    return __builtin_ctz(m) + 1;
}

canonical_original_code:
int decimal_digits_sse(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "decimal_digits_sse.c", 9, __extension__ __PRETTY_FUNCTION__));
    long long powers_a = _mm_setr_epi32(9, 99, 999, 9999);
    long long powers_b = _mm_setr_epi32(99999, 999999, 9999999, 99999999);
    long long powers_c = _mm_setr_epi32(999999999, 2147483647, 2147483647, 2147483647);
    long long value = _mm_set1_epi32(x);
    long long gt0 = _mm_cmpgt_epi32(value, powers_a);
    long long gt1 = _mm_cmpgt_epi32(value, powers_b);
    long long gt2 = _mm_cmpgt_epi32(value, powers_c);
    long long t0 = _mm_packs_epi32(gt0, gt1);
    long long t1 = _mm_packs_epi32(gt2, _mm_setzero_si128());
    long long t2 = _mm_packs_epi16(t0, t1);
    unsigned short m = ~_mm_movemask_epi8(t2);
    return __builtin_ctz(m) + 1;
}

variable_types: x int

variable_types:
value
long long

variable_types:
m
unsigned short


decompiled_code:
__int64 __fastcall decimal_digits_naive(int a1)
{
unsigned int v1; // ecx
int i; // edx

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_naive.c", 3u, "decimal_digits_naive");
v1 = 1;
if ( a1 )
{
v1 = 0;
for ( i = 1; i <= a1; i *= 10 )
++v1;
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned int v1; // ecx
int i; // edx

if ( a1 < 0 )
__assert_fail("x >= 0", "decimal_digits_naive.c", 3u, "decimal_digits_naive");
v1 = 1;
if ( a1 )
{
v1 = 0;
for ( i = 1; i <= a1; i *= 10 )
++v1;
}
return v1;
}

original_code:
int decimal_digits_naive(int x) {
 ((x >= 0) ? (void) (0) : __assert_fail ("x >= 0", "decimal_digits_naive.c", 3, __extension__ __PRETTY_FUNCTION__));
 if (x == 0)
  return 1;
 int pow = 1;
 int digits = 0;
 while (x >= pow) {
  pow *= 10;
  digits += 1;
 }
 return digits;
}

variable_types: pow int

variable_types: digits int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // eax
unsigned int v5; // ebx
__int64 v6; // r13
__int64 v7; // rbx

if ( argc <= 1 )
return 0;
v3 = argv + 1;
do
{
v4 = atoi(*v3);
v5 = v4;
if ( v4 < 0 )
{
printf("%15d: negative numbers not supported\n", (unsigned int)v4);
}
else
{
v6 = (unsigned int)decimal_digits_naive(v4);
printf("%15d: digits %2d (correct)", v5, v6);
v7 = (unsigned int)decimal_digits_sse(v5);
printf(", %2d (SSE proc)", v7);
if ( (_DWORD)v6 != (_DWORD)v7 )
printf(" FAILED");
putchar(10);
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbp
int v4; // eax
unsigned int v5; // ebx
__int64 v6; // r13
__int64 v7; // rbx

if ( argc <= 1 )
return 0;
v3 = argv + 1;
do
{
v4 = atoi(*v3);
v5 = v4;
if ( v4 < 0 )
{
printf("%15d: negative numbers not supported\n", (unsigned int)v4);
}
else
{
v6 = (unsigned int)func8(v4);
printf("%15d: digits %2d (correct)", v5, v6);
v7 = (unsigned int)func7(v5);
printf(", %2d (SSE proc)", v7);
if ( (_DWORD)v6 != (_DWORD)v7 )
printf(" FAILED");
putchar(10);
}
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
return 0;
}

original_code:
int main(int argc, char* argv[]) {
 for (int i=1; i < argc; i++) {
  const int x = atoi(argv[i]);
  if (x < 0) {
   printf("%15d: negative numbers not supported\n", x);
            continue;
        }
        const int ref = decimal_digits_naive(x);
        printf("%15d: digits %2d (correct)", x, ref);
        const int sse = decimal_digits_sse(x);
        printf(", %2d (SSE proc)", sse);
        if (sse != ref)
            printf(" FAILED");
        putchar('\n');
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 for (int i = 1; i < argc; i++) {
  int x = atoi(argv[i]);
  if (x < 0) {
   printf("%15d: negative numbers not supported\n", x);
            continue;
        }
        int ref = decimal_digits_naive(x);
        printf("%15d: digits %2d (correct)", x, ref);
        int sse = decimal_digits_sse(x);
        printf(", %2d (SSE proc)", sse);
        if (sse != ref)
            printf(" FAILED");
        putchar('\n');
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: ref int

variable_types: sse int


decompiled_code:
__int64 get_mxcsr()
{
_mm_getcsr();
return 0LL;
}

canonical_decompiled_code:
__int64 func7()
{
_mm_getcsr();
return 0LL;
}

original_code:
uint32_t get_mxcsr() {
 uint32_t result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

canonical_original_code:
unsigned int get_mxcsr() {
 unsigned int result = 0;
 __asm__ __volatile__("stmxcsr %0": :"m" (result));
 return result;
}

variable_types:
result
unsigned int


decompiled_code:
int *__fastcall set_mxcsr(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

canonical_decompiled_code:
int *__fastcall func8(unsigned int a1)
{
int *result; // rax
int v2; // [rsp+0h] [rbp-4h] BYREF

result = &v2;
_mm_setcsr(a1);
return result;
}

original_code:
void set_mxcsr(uint32_t mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

canonical_original_code:
void set_mxcsr(unsigned int mxcsr) {
 __asm__ __volatile__("ldmxcsr (%0)"
  :
  :"g" (&mxcsr)
  : "memory"
 );
}

variable_types:
mxcsr
unsigned int


decompiled_code:
int dump_mxcsr()
{
unsigned int v0; // eax

v0 = get_mxcsr();
return print_mxcsr(_bss_start, v0);
}

canonical_decompiled_code:
int func11()
{
unsigned int v0; // eax

v0 = func7();
return func10(_bss_start, v0);
}

original_code:
void dump_mxcsr() {
 print_mxcsr(stdout, get_mxcsr());
}


decompiled_code:
const char *__fastcall fpclassifyf_str(float a1)
{
float v2; // xmm0_4
const char *result; // rax

v2 = fabs(a1);
if ( v2 > 3.4028235e38 )
return "infinite";
result = "normalized";
if ( v2 < 1.1754944e-38 )
{
if ( a1 == 0.0 )
result = "zero";
else
result = (const char *)&unk_40211C;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func13(float a1)
{
float v2; // xmm0_4
const char *result; // rax

v2 = fabs(a1);
if ( v2 > 3.4028235e38 )
return "infinite";
result = "normalized";
if ( v2 < 1.1754944e-38 )
{
if ( a1 == 0.0 )
result = "zero";
else
result = (const char *)&unk_40211C;
}
return result;
}

original_code:
const char* fpclassifyf_str(const float x) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, x)) {
  case 0:
   return "NaN";
  case 1:
   return "infinite";
  case 2:
   return "zero";
  case 3:
   return "denormalized";
  case 4:
   return "normalized";
  default:
   return "<unknown>";
 }
}

canonical_original_code:
char *fpclassifyf_str(float x) {
 switch (__builtin_fpclassify (0, 1, 4, 3, 2, x)) {
  case 0:
   return "NaN";
  case 1:
   return "infinite";
  case 2:
   return "zero";
  case 3:
   return "denormalized";
  case 4:
   return "normalized";
  default:
   return "<unknown>";
 }
}

variable_types: x float


original_code:
void test_loop() {
 const int32_t iterations = 10000000;
 uint32_t dummy;
 __asm__ __volatile__(
  "movups %2, %%xmm3\n"
  "movups	%3, %%xmm4\n"
  "1:\n"
  "movaps %%xmm3, %%xmm0\n"
  "movaps %%xmm4, %%xmm1\n"
  "pxor   %%xmm2, %%xmm2\n"
  "mulps  %%xmm1, %%xmm0\n"
  "addps	%%xmm2, %%xmm0\n"
  "loop 1b\n"
  "movups %%xmm0, %4\n"
  : "=c" (dummy)
  : "c" (iterations)
  , "m" (tiny_value)
  , "m" (large_divisor)
  , "m" (final_value)
  : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
 );
}

canonical_original_code:
void test_loop() {
 int iterations = 10000000;
 unsigned int dummy;
 __asm__ __volatile__(
  "movups %2, %%xmm3\n"
  "movups	%3, %%xmm4\n"
  "1:\n"
  "movaps %%xmm3, %%xmm0\n"
  "movaps %%xmm4, %%xmm1\n"
  "pxor   %%xmm2, %%xmm2\n"
  "mulps  %%xmm1, %%xmm0\n"
  "addps	%%xmm2, %%xmm0\n"
  "loop 1b\n"
  "movups %%xmm0, %4\n"
  : "=c" (dummy)
  : "c" (iterations)
  , "m" (tiny_value)
  , "m" (large_divisor)
  , "m" (final_value)
  : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4"
 );
}

variable_types: iterations int

variable_types:
dummy
unsigned int