file
stringlengths
18
26
data
stringlengths
3
1.04M
the_stack_data/6044.c
#include <stdio.h> float fahr2celsius(float fahr) { return (5.0/9.0) * (fahr-32.0); } /* print Fahrenheit-Celsius table * for fahr = 0, 20, ..., 300; floating-point version */ int main() { float fahr, celsius; int lower, upper, step; lower = 0; /* lower limit of temperature table */ upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = fahr2celsius(fahr); printf("%3.0f %6.1f\n", fahr, celsius); fahr = fahr + step; } return 0; }
the_stack_data/3262554.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strncat.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: wipariso <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2015/11/30 17:59:33 by wipariso #+# #+# */ /* Updated: 2015/12/03 15:56:46 by wipariso ### ########.fr */ /* */ /* ************************************************************************** */ #include <string.h> char *ft_strncat(char *dest, const char *src, size_t n) { char *head; head = dest; while (*dest) dest++; while (n-- && *src) *dest++ = *src++; *dest = 0; return (head); }
the_stack_data/37889.c
int main(){ int a=5*+2; return a; }
the_stack_data/751004.c
#include<stdio.h> // "I hereby certify that this program code submitted as a requirement for the course CS 12 A is accomplished with all due honesty. // I am fully aware of the consequences should I cheat in this program code. // Consequences for any actions considered academic dishonesty are stipulated in the XU Student Handbook." #define SIZE 5 int main() { // Declaring an array // with the SIZE as the maximum // num of arrays and nested arrays // 5 * 5 = 25 arrays all in all. int arr[SIZE][SIZE]; // Used for iteration purposes int x, y; // Iterating over the size of the array for(y = 0; y < SIZE; y++) for(x = 0; x < SIZE; x++) // Tertiary expression // If it is true // It will return 0 // However, I used tertiary expression again // tertiary-ception, If x > y // It will return 1 else -1 arr[y][x] = (x == y) ? 0 : ((x > y) ? 1 : -1); // Responsible for displaying the square matrix for(y = 0; y < SIZE; y++) { for(x = 0; x < SIZE; x++) printf("%d\t", arr[y][x]); printf("\n\n"); } getch(); return 0; }
the_stack_data/140765903.c
int main() { int a; int b; int n; int i; #pragma scop { int c1; if (n >= 1) { for (c1 = 0; c1 <= n + -1; ++c1) { a += b; --a; b++; } } } #pragma endscop return 0; }
the_stack_data/317528.c
#include <stdio.h> int main() { int a = "hello"; }
the_stack_data/99343.c
#include <stdio.h> #include <stdlib.h> struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; }; static void traverse(struct TreeNode *node, int *result, int *count) { if (node == NULL) { return; } traverse(node->left, result, count); result[*count] = node->val; (*count)++; traverse(node->right, result, count); } /** ** Return an array of size *returnSize. ** Note: The returned array must be malloced, assume caller calls free(). **/ static int* inorderTraversal(struct TreeNode* root, int* returnSize) { if (root == NULL) { *returnSize = 0; return NULL; } int count = 0; int *result = malloc(5000 * sizeof(int)); traverse(root, result, &count); *returnSize = count; return result; } int main() { int count = 0; inorderTraversal(NULL, &count); return 0; }
the_stack_data/168893649.c
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct Nameval Nameval; struct Nameval { char *name; int value; }; struct NVtab { int nval; int max; Nameval *nameval; } nvtab; enum { NVINIT = 1, NVGROW = 2 }; int addname(Nameval newname) { Nameval *nvp; int free; if (nvtab.nameval == NULL) { nvtab.nameval = (Nameval *)malloc(NVINIT * sizeof(Nameval)); if (nvtab.nameval == NULL) { return -1; } nvtab.max = NVINIT; nvtab.nval = 0; } do { nvp = (Nameval *)realloc(nvtab.nameval, (NVGROW * nvtab.max) * sizeof(Nameval)); if (nvp == NULL) { return -1; } nvtab.max *= NVGROW; nvtab.nameval = nvp; nvtab.nameval[nvtab.nval] = newname; return nvtab.nval++; free++; } while (nvtab.nameval[free].name == NULL); } int delname(char *name) { for (int i = 0; i < nvtab.nval; i++) if (strcmp(nvtab.nameval[i].name, name) == 0) { memmove(nvtab.nameval + i, nvtab.nameval + i + 1, (nvtab.nval - (i + 1)) * sizeof(Nameval)); nvtab.nval--; return 1; } return 0; } int main(void) { int curnum = addname((struct Nameval){.name = "Andy", .value = 12}); printf("%d\n", curnum); curnum = addname((struct Nameval){.name = "Billy", .value = 18}); printf("%d\n", curnum); for (int i = 0; i < nvtab.nval; i++) { printf("%s %d\n", nvtab.nameval[i].name, nvtab.nameval[i].value); } return 0; }
the_stack_data/165764664.c
/*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * %sccs.include.redist.c% * * @(#)tp_inet.c 8.1 (Berkeley) 06/10/93 */ /*********************************************************** Copyright IBM Corporation 1987 All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of IBM not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /* * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison */ /* * ARGO TP * $Header: tp_inet.c,v 5.3 88/11/18 17:27:29 nhall Exp $ * $Source: /usr/argo/sys/netiso/RCS/tp_inet.c,v $ * * Here is where you find the inet-dependent code. We've tried * keep all net-level and (primarily) address-family-dependent stuff * out of the tp source, and everthing here is reached indirectly * through a switch table (struct nl_protosw *) tpcb->tp_nlproto * (see tp_pcb.c). * The routines here are: * in_getsufx: gets transport suffix out of an inpcb structure. * in_putsufx: put transport suffix into an inpcb structure. * in_putnetaddr: put a whole net addr into an inpcb. * in_getnetaddr: get a whole net addr from an inpcb. * in_cmpnetaddr: compare a whole net addr from an isopcb. * in_recycle_suffix: clear suffix for reuse in inpcb * tpip_mtu: figure out what size tpdu to use * tpip_input: take a pkt from ip, strip off its ip header, give to tp * tpip_output_dg: package a pkt for ip given 2 addresses & some data * tpip_output: package a pkt for ip given an inpcb & some data */ #ifdef INET #include <sys/param.h> #include <sys/socket.h> #include <sys/socketvar.h> #include <sys/mbuf.h> #include <sys/errno.h> #include <sys/time.h> #include <net/if.h> #include <netiso/tp_param.h> #include <netiso/argo_debug.h> #include <netiso/tp_stat.h> #include <netiso/tp_ip.h> #include <netiso/tp_pcb.h> #include <netiso/tp_trace.h> #include <netiso/tp_stat.h> #include <netiso/tp_tpdu.h> #include <netinet/in_var.h> #ifndef ISO #include <netiso/iso_chksum.c> #endif /* * NAME: in_getsufx() * CALLED FROM: pr_usrreq() on PRU_BIND, * PRU_CONNECT, PRU_ACCEPT, and PRU_PEERADDR * * FUNCTION, ARGUMENTS, and RETURN VALUE: * Get a transport suffix from an inpcb structure (inp). * The argument (which) takes the value TP_LOCAL or TP_FOREIGN. * * RETURNS: internet port / transport suffix * (CAST TO AN INT) * * SIDE EFFECTS: * * NOTES: */ in_getsufx(inp, lenp, data_out, which) struct inpcb *inp; u_short *lenp; caddr_t data_out; int which; { *lenp = sizeof(u_short); switch (which) { case TP_LOCAL: *(u_short *)data_out = inp->inp_lport; return; case TP_FOREIGN: *(u_short *)data_out = inp->inp_fport; } } /* * NAME: in_putsufx() * * CALLED FROM: tp_newsocket(); i.e., when a connection * is being established by an incoming CR_TPDU. * * FUNCTION, ARGUMENTS: * Put a transport suffix (found in name) into an inpcb structure (inp). * The argument (which) takes the value TP_LOCAL or TP_FOREIGN. * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: */ /*ARGSUSED*/ void in_putsufx(inp, sufxloc, sufxlen, which) struct inpcb *inp; caddr_t sufxloc; int which; { if (which == TP_FOREIGN) { bcopy(sufxloc, (caddr_t)&inp->inp_fport, sizeof(inp->inp_fport)); } } /* * NAME: in_recycle_tsuffix() * * CALLED FROM: tp.trans whenever we go into REFWAIT state. * * FUNCTION and ARGUMENT: * Called when a ref is frozen, to allow the suffix to be reused. * (inp) is the net level pcb. * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: This really shouldn't have to be done in a NET level pcb * but... for the internet world that just the way it is done in BSD... * The alternative is to have the port unusable until the reference * timer goes off. */ void in_recycle_tsuffix(inp) struct inpcb *inp; { inp->inp_fport = inp->inp_lport = 0; } /* * NAME: in_putnetaddr() * * CALLED FROM: * tp_newsocket(); i.e., when a connection is being established by an * incoming CR_TPDU. * * FUNCTION and ARGUMENTS: * Copy a whole net addr from a struct sockaddr (name). * into an inpcb (inp). * The argument (which) takes values TP_LOCAL or TP_FOREIGN * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: */ void in_putnetaddr(inp, name, which) register struct inpcb *inp; struct sockaddr_in *name; int which; { switch (which) { case TP_LOCAL: bcopy((caddr_t)&name->sin_addr, (caddr_t)&inp->inp_laddr, sizeof(struct in_addr)); /* won't work if the dst address (name) is INADDR_ANY */ break; case TP_FOREIGN: if( name != (struct sockaddr_in *)0 ) { bcopy((caddr_t)&name->sin_addr, (caddr_t)&inp->inp_faddr, sizeof(struct in_addr)); } } } /* * NAME: in_putnetaddr() * * CALLED FROM: * tp_input() when a connection is being established by an * incoming CR_TPDU, and considered for interception. * * FUNCTION and ARGUMENTS: * Compare a whole net addr from a struct sockaddr (name), * with that implicitly stored in an inpcb (inp). * The argument (which) takes values TP_LOCAL or TP_FOREIGN * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: */ in_cmpnetaddr(inp, name, which) register struct inpcb *inp; register struct sockaddr_in *name; int which; { if (which == TP_LOCAL) { if (name->sin_port && name->sin_port != inp->inp_lport) return 0; return (name->sin_addr.s_addr == inp->inp_laddr.s_addr); } if (name->sin_port && name->sin_port != inp->inp_fport) return 0; return (name->sin_addr.s_addr == inp->inp_faddr.s_addr); } /* * NAME: in_getnetaddr() * * CALLED FROM: * pr_usrreq() PRU_SOCKADDR, PRU_ACCEPT, PRU_PEERADDR * FUNCTION and ARGUMENTS: * Copy a whole net addr from an inpcb (inp) into * an mbuf (name); * The argument (which) takes values TP_LOCAL or TP_FOREIGN. * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: */ void in_getnetaddr( inp, name, which) register struct mbuf *name; struct inpcb *inp; int which; { register struct sockaddr_in *sin = mtod(name, struct sockaddr_in *); bzero((caddr_t)sin, sizeof(*sin)); switch (which) { case TP_LOCAL: sin->sin_addr = inp->inp_laddr; sin->sin_port = inp->inp_lport; break; case TP_FOREIGN: sin->sin_addr = inp->inp_faddr; sin->sin_port = inp->inp_fport; break; default: return; } name->m_len = sin->sin_len = sizeof (*sin); sin->sin_family = AF_INET; } /* * NAME: tpip_mtu() * * CALLED FROM: * tp_route_to() on incoming CR, CC, and pr_usrreq() for PRU_CONNECT * * FUNCTION, ARGUMENTS, and RETURN VALUE: * * Perform subnetwork dependent part of determining MTU information. * It appears that setting a double pointer to the rtentry associated with * the destination, and returning the header size for the network protocol * suffices. * * SIDE EFFECTS: * Sets tp_routep pointer in pcb. * * NOTES: */ tpip_mtu(tpcb) register struct tp_pcb *tpcb; { struct inpcb *inp = (struct inpcb *)tpcb->tp_npcb; IFDEBUG(D_CONN) printf("tpip_mtu(tpcb)\n", tpcb); printf("tpip_mtu routing to addr 0x%x\n", inp->inp_faddr.s_addr); ENDDEBUG tpcb->tp_routep = &(inp->inp_route.ro_rt); return (sizeof (struct ip)); } /* * NAME: tpip_output() * * CALLED FROM: tp_emit() * * FUNCTION and ARGUMENTS: * Take a packet(m0) from tp and package it so that ip will accept it. * This means prepending space for the ip header and filling in a few * of the fields. * inp is the inpcb structure; datalen is the length of the data in the * mbuf string m0. * RETURNS: * whatever (E*) is returned form the net layer output routine. * * SIDE EFFECTS: * * NOTES: */ int tpip_output(inp, m0, datalen, nochksum) struct inpcb *inp; struct mbuf *m0; int datalen; int nochksum; { return tpip_output_dg( &inp->inp_laddr, &inp->inp_faddr, m0, datalen, &inp->inp_route, nochksum); } /* * NAME: tpip_output_dg() * * CALLED FROM: tp_error_emit() * * FUNCTION and ARGUMENTS: * This is a copy of tpip_output that takes the addresses * instead of a pcb. It's used by the tp_error_emit, when we * don't have an in_pcb with which to call the normal output rtn. * * RETURNS: ENOBUFS or whatever (E*) is * returned form the net layer output routine. * * SIDE EFFECTS: * * NOTES: */ /*ARGSUSED*/ int tpip_output_dg(laddr, faddr, m0, datalen, ro, nochksum) struct in_addr *laddr, *faddr; struct mbuf *m0; int datalen; struct route *ro; int nochksum; { register struct mbuf *m; register struct ip *ip; int error; IFDEBUG(D_EMIT) printf("tpip_output_dg datalen 0x%x m0 0x%x\n", datalen, m0); ENDDEBUG MGETHDR(m, M_DONTWAIT, TPMT_IPHDR); if (m == 0) { error = ENOBUFS; goto bad; } m->m_next = m0; MH_ALIGN(m, sizeof(struct ip)); m->m_len = sizeof(struct ip); ip = mtod(m, struct ip *); bzero((caddr_t)ip, sizeof *ip); ip->ip_p = IPPROTO_TP; m->m_pkthdr.len = ip->ip_len = sizeof(struct ip) + datalen; ip->ip_ttl = MAXTTL; /* don't know why you need to set ttl; * overlay doesn't even make this available */ ip->ip_src = *laddr; ip->ip_dst = *faddr; IncStat(ts_tpdu_sent); IFDEBUG(D_EMIT) dump_mbuf(m, "tpip_output_dg before ip_output\n"); ENDDEBUG error = ip_output(m, (struct mbuf *)0, ro, IP_ALLOWBROADCAST, NULL); IFDEBUG(D_EMIT) printf("tpip_output_dg after ip_output\n"); ENDDEBUG return error; bad: m_freem(m); IncStat(ts_send_drop); return error; } /* * NAME: tpip_input() * * CALLED FROM: * ip's input routine, indirectly through the protosw. * * FUNCTION and ARGUMENTS: * Take a packet (m) from ip, strip off the ip header and give it to tp * * RETURNS: No return value. * * SIDE EFFECTS: * * NOTES: */ ProtoHook tpip_input(m, iplen) struct mbuf *m; int iplen; { struct sockaddr_in src, dst; register struct ip *ip; int s = splnet(), hdrlen; IncStat(ts_pkt_rcvd); /* * IP layer has already pulled up the IP header, * but the first byte after the IP header may not be there, * e.g. if you came in via loopback, so you have to do an * m_pullup to before you can even look to see how much you * really need. The good news is that m_pullup will round * up to almost the next mbuf's worth. */ if((m = m_pullup(m, iplen + 1)) == MNULL) goto discard; CHANGE_MTYPE(m, TPMT_DATA); /* * Now pull up the whole tp header: * Unfortunately, there may be IP options to skip past so we * just fetch it as an unsigned char. */ hdrlen = iplen + 1 + mtod(m, u_char *)[iplen]; if( m->m_len < hdrlen ) { if((m = m_pullup(m, hdrlen)) == MNULL){ IFDEBUG(D_TPINPUT) printf("tp_input, pullup 2!\n"); ENDDEBUG goto discard; } } /* * cannot use tp_inputprep() here 'cause you don't * have quite the same situation */ IFDEBUG(D_TPINPUT) dump_mbuf(m, "after tpip_input both pullups"); ENDDEBUG /* * m_pullup may have returned a different mbuf */ ip = mtod(m, struct ip *); /* * drop the ip header from the front of the mbuf * this is necessary for the tp checksum */ m->m_len -= iplen; m->m_data += iplen; src.sin_addr = *(struct in_addr *)&(ip->ip_src); src.sin_family = AF_INET; src.sin_len = sizeof(src); dst.sin_addr = *(struct in_addr *)&(ip->ip_dst); dst.sin_family = AF_INET; dst.sin_len = sizeof(dst); (void) tp_input(m, (struct sockaddr *)&src, (struct sockaddr *)&dst, 0, tpip_output_dg, 0); return 0; discard: IFDEBUG(D_TPINPUT) printf("tpip_input DISCARD\n"); ENDDEBUG IFTRACE(D_TPINPUT) tptrace(TPPTmisc, "tpip_input DISCARD m", m,0,0,0); ENDTRACE m_freem(m); IncStat(ts_recv_drop); splx(s); return 0; } #include <sys/protosw.h> #include <netinet/ip_icmp.h> extern void tp_quench(); /* * NAME: tpin_quench() * * CALLED FROM: tpip_ctlinput() * * FUNCTION and ARGUMENTS: find the tpcb pointer and pass it to tp_quench * * RETURNS: Nada * * SIDE EFFECTS: * * NOTES: */ void tpin_quench(inp) struct inpcb *inp; { tp_quench((struct tp_pcb *)inp->inp_socket->so_pcb, PRC_QUENCH); } /* * NAME: tpip_ctlinput() * * CALLED FROM: * The network layer through the protosw table. * * FUNCTION and ARGUMENTS: * When clnp gets an ICMP msg this gets called. * It either returns an error status to the user or * causes all connections on this address to be aborted * by calling the appropriate xx_notify() routine. * (cmd) is the type of ICMP error. * (sa) the address of the sender * * RETURNS: Nothing * * SIDE EFFECTS: * * NOTES: */ ProtoHook tpip_ctlinput(cmd, sin) int cmd; struct sockaddr_in *sin; { extern u_char inetctlerrmap[]; extern struct in_addr zeroin_addr; void tp_quench __P((struct inpcb *,int)); void tpin_abort __P((struct inpcb *,int)); if (sin->sin_family != AF_INET && sin->sin_family != AF_IMPLINK) return 0; if (sin->sin_addr.s_addr == INADDR_ANY) return 0; if (cmd < 0 || cmd > PRC_NCMDS) return 0; switch (cmd) { case PRC_QUENCH: in_pcbnotify(&tp_inpcb, (struct sockaddr *)sin, 0, zeroin_addr, 0, cmd, tp_quench); break; case PRC_ROUTEDEAD: case PRC_HOSTUNREACH: case PRC_UNREACH_NET: case PRC_IFDOWN: case PRC_HOSTDEAD: in_pcbnotify(&tp_inpcb, (struct sockaddr *)sin, 0, zeroin_addr, 0, cmd, in_rtchange); break; default: /* case PRC_MSGSIZE: case PRC_UNREACH_HOST: case PRC_UNREACH_PROTOCOL: case PRC_UNREACH_PORT: case PRC_UNREACH_NEEDFRAG: case PRC_UNREACH_SRCFAIL: case PRC_REDIRECT_NET: case PRC_REDIRECT_HOST: case PRC_REDIRECT_TOSNET: case PRC_REDIRECT_TOSHOST: case PRC_TIMXCEED_INTRANS: case PRC_TIMXCEED_REASS: case PRC_PARAMPROB: */ in_pcbnotify(&tp_inpcb, (struct sockaddr *)sin, 0, zeroin_addr, 0, cmd, tpin_abort); } return 0; } /* * NAME: tpin_abort() * * CALLED FROM: * xxx_notify() from tp_ctlinput() when * net level gets some ICMP-equiv. type event. * * FUNCTION and ARGUMENTS: * Cause the connection to be aborted with some sort of error * reason indicating that the network layer caused the abort. * Fakes an ER TPDU so we can go through the driver. * * RETURNS: Nothing * * SIDE EFFECTS: * * NOTES: */ ProtoHook tpin_abort(inp) struct inpcb *inp; { struct tp_event e; e.ev_number = ER_TPDU; e.ATTR(ER_TPDU).e_reason = ENETRESET; (void) tp_driver((struct tp_pcb *)inp->inp_ppcb, &e); return 0; } #ifdef ARGO_DEBUG dump_inaddr(addr) register struct sockaddr_in *addr; { printf("INET: port 0x%x; addr 0x%x\n", addr->sin_port, addr->sin_addr); } #endif /* ARGO_DEBUG */ #endif /* INET */
the_stack_data/32949987.c
#include <stdio.h> int main(void) { int i; char ch, smallest; printf("Enter 10 letters.\n"); smallest = 'z'; // make largest to bigin with for (i = 0; i<10; i++) { // ch = getche(); // ch = getchar(); if (ch < smallest) smallest = ch; } printf("\nThe smallest charcter is %c.", smallest); return 0; }
the_stack_data/955517.c
/** * @brief * @details * @date 2016-11-15 **/ /* Includes ------------------------------------------------------------------*/ #if !defined ( _WIN32 ) && !defined ( _WIN64 ) && !defined ( __linux ) #include "viic3.h" #include "delay.h" #if defined (BUILD_REAL_WORLD) #include "stm32f0xx.h" #endif /* Private typedef -----------------------------------------------------------*/ enum __iic_res { IIC_NAK = 0, IIC_ACK, }; /* Private define ------------------------------------------------------------*/ #if defined (BUILD_REAL_WORLD) #define VIIC_SCL_L GPIO_ResetBits(GPIOE,GPIO_Pin_11) #define VIIC_SCL_H GPIO_SetBits(GPIOE,GPIO_Pin_11) #define VIIC_SDA_L GPIO_ResetBits(GPIOE,GPIO_Pin_12) #define VIIC_SDA_H GPIO_SetBits(GPIOE,GPIO_Pin_12) #define VIIC_SDA_DATA (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_12) == Bit_SET) #define VIIC_SDA_DIR_OUT #define VIIC_SDA_DIR_IN GPIO_SetBits(GPIOE,GPIO_Pin_12) #endif /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static enum __dev_status status = DEVICE_NOTINIT; /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /** * @brief */ static enum __dev_status viic_status(void) { return(status); } /** * @brief */ static void viic_init(enum __dev_state state) { #if defined (BUILD_REAL_WORLD) GPIO_InitTypeDef GPIO_InitStruct; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOE, ENABLE); GPIO_InitStruct.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3; GPIO_Init(GPIOE, &GPIO_InitStruct); GPIO_SetBits(GPIOE, GPIO_Pin_11); GPIO_SetBits(GPIOE, GPIO_Pin_12); #endif status = DEVICE_INIT; } /** * @brief */ static void viic_suspend(void) { status = DEVICE_SUSPENDED; } /** * @brief */ static uint32_t viic_rate_get(void) { return(85*1000); } /** * @brief */ static uint32_t viic_rate_set(uint32_t rate) { return(85*1000); } /** * @brief start */ static void viic_low_start(void) { VIIC_SDA_DIR_OUT; VIIC_SDA_H; VIIC_SCL_H; udelay(4); VIIC_SDA_H; udelay(4); VIIC_SDA_L; udelay(4); VIIC_SCL_L; udelay(4); } /** * @brief stop */ static void viic_low_stop(void) { VIIC_SDA_DIR_OUT; VIIC_SDA_L; udelay(4); VIIC_SCL_H; udelay(4); VIIC_SDA_H; udelay(4); } /** * @brief get ack */ static enum __iic_res viic_low_ack_get(void) { enum __iic_res res = IIC_ACK; uint8_t i = 5; VIIC_SDA_DIR_IN; udelay(4); VIIC_SCL_H; udelay(4); while((i--) && VIIC_SDA_DATA); if (i == 0) { res = IIC_NAK; } VIIC_SCL_L; udelay(4); return(res); } /** * @brief set ack */ static void viic_low_ack_set(enum __iic_res res) { VIIC_SDA_DIR_OUT; if(res == IIC_ACK) { VIIC_SDA_L; udelay(4); VIIC_SCL_H; udelay(4); VIIC_SCL_L; udelay(4); VIIC_SDA_H; udelay(4); } else if(res == IIC_NAK) { VIIC_SDA_H; udelay(4); VIIC_SCL_H; udelay(4); VIIC_SCL_L; udelay(4); VIIC_SDA_L; udelay(4); } } static uint8_t viic_raw_getchar(void) { uint8_t loop; uint8_t val = 0; VIIC_SDA_DIR_IN; udelay(2); for(loop=0; loop<8; loop++) { VIIC_SCL_H; udelay(2); val = val << 1; if(VIIC_SDA_DATA) { val |= 0x01; } else { val &= 0xFE; } udelay(2); VIIC_SCL_L; udelay(4); } return val; } static uint8_t viic_raw_putchar(uint8_t ch) { uint8_t loop; uint8_t val = ch; VIIC_SDA_DIR_OUT; for(loop=0; loop<8; loop++) { if(val & 0x80) { VIIC_SDA_H; } else { VIIC_SDA_L; } udelay(2); VIIC_SCL_H; udelay(4); VIIC_SCL_L; udelay(2); val = val << 1; } return(ch); } static uint16_t viic_raw_read(uint16_t count, uint8_t * buffer) { uint16_t loop; uint8_t bits; if(!count || !buffer) { return(0); } VIIC_SDA_DIR_IN; udelay(2); for(loop=0; loop<count; loop++) { for(bits=0; bits<8; bits++) { VIIC_SCL_H; udelay(2); buffer[loop] = buffer[loop] << 1; if(VIIC_SDA_DATA) { buffer[loop] |= 0x01; } else { buffer[loop] &= 0xFE; } udelay(2); VIIC_SCL_L; udelay(4); } } return(count); } static uint16_t viic_raw_write(uint16_t count, const uint8_t *buffer) { uint16_t loop; uint8_t bits; uint8_t val; if(!count || !buffer) { return(0); } VIIC_SDA_DIR_OUT; for(loop=0; loop<count; loop++) { val = buffer[loop]; for(bits=0; bits<8; bits++) { if(val & 0x80) { VIIC_SDA_H; } else { VIIC_SDA_L; } udelay(2); VIIC_SCL_H; udelay(4); VIIC_SCL_L; udelay(2); val = val << 1; } } return(count); } static uint16_t viic_bus_read(uint16_t addr, uint32_t reg, uint8_t reglen, uint16_t count, uint8_t * buffer) { uint16_t loop; if(!count || !buffer) { return(0); } if(reglen > 4) { return(0); } viic_low_start(); viic_raw_putchar((uint8_t)(addr << 1)); if(viic_low_ack_get() != IIC_ACK) { return(0); } while(reglen) { viic_raw_putchar((uint8_t)((reg >> ((reglen - 1) * 8)) & 0xff)); if(viic_low_ack_get() != IIC_ACK) { return(0); } reglen -= 1; } viic_low_start(); viic_raw_putchar((uint8_t)((addr << 1) | 0x01)); if(viic_low_ack_get() != IIC_ACK) { return(0); } for(loop=0; loop<count; loop++) { buffer[loop] = viic_raw_getchar(); if(loop < (count-1)) { viic_low_ack_set(IIC_ACK); } } viic_low_ack_set(IIC_NAK); viic_low_stop(); return(count); } static uint16_t viic_bus_write(uint16_t addr, uint32_t reg, uint8_t reglen, uint16_t count, const uint8_t *buffer) { uint16_t loop; if(count && !buffer) { return(0); } if(reglen > 4) { return(0); } viic_low_start(); udelay(4); viic_raw_putchar((uint8_t)(addr << 1)); if(viic_low_ack_get() != IIC_ACK) { return(0); } while(reglen) { viic_raw_putchar((uint8_t)((reg >> ((reglen - 1) * 8)) & 0xff)); if(viic_low_ack_get() != IIC_ACK) { return(0); } reglen -= 1; } for(loop=0; loop<count; loop++) { viic_raw_putchar(buffer[loop]); if(viic_low_ack_get() != IIC_ACK) { viic_low_stop(); return(loop); } } viic_low_stop(); return(count); } static enum __bus_status viic_bus_status(void) { return(BUS_IDLE); } const struct __iic viic3 = { .control = { .name = "virtual iic 3", .status = viic_status, .init = viic_init, .suspend = viic_suspend, }, .octet = { .read = viic_raw_getchar, .write = viic_raw_putchar, }, .sequent = { .read = viic_raw_read, .write = viic_raw_write, }, .bus = { .read = viic_bus_read, .write = viic_bus_write, }, .status = viic_bus_status, .speed = { .get = viic_rate_get, .set = viic_rate_set, }, }; #endif /* !defined ( _WIN32 ) && !defined ( _WIN64 ) && !defined ( __linux ) */
the_stack_data/187644528.c
/* Ray-Triangle Intersection Test Routines */ /* Different optimizations of my and Ben Trumbore's */ /* code from journals of graphics tools (JGT) */ /* http://www.acm.org/jgt/ */ /* by Tomas Moller, May 2000 */ // Alec: I've added an include guard, made all functions inline and added // IGL_RAY_TRI_ to #define macros #ifndef IGL_RAY_TRI_C #define IGL_RAY_TRI_C #include <math.h> #define IGL_RAY_TRI_EPSILON 0.000001 #define IGL_RAY_TRI_CROSS(dest,v1,v2) \ dest[0]=v1[1]*v2[2]-v1[2]*v2[1]; \ dest[1]=v1[2]*v2[0]-v1[0]*v2[2]; \ dest[2]=v1[0]*v2[1]-v1[1]*v2[0]; #define IGL_RAY_TRI_DOT(v1,v2) (v1[0]*v2[0]+v1[1]*v2[1]+v1[2]*v2[2]) #define IGL_RAY_TRI_SUB(dest,v1,v2) \ dest[0]=v1[0]-v2[0]; \ dest[1]=v1[1]-v2[1]; \ dest[2]=v1[2]-v2[2]; /* the original jgt code */ inline int intersect_triangle(double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v) { double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; double det,inv_det; /* find vectors for two edges sharing vert0 */ IGL_RAY_TRI_SUB(edge1, vert1, vert0); IGL_RAY_TRI_SUB(edge2, vert2, vert0); /* begin calculating determinant - also used to calculate U parameter */ IGL_RAY_TRI_CROSS(pvec, dir, edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = IGL_RAY_TRI_DOT(edge1, pvec); if (det > -IGL_RAY_TRI_EPSILON && det < IGL_RAY_TRI_EPSILON) return 0; inv_det = 1.0 / det; /* calculate distance from vert0 to ray origin */ IGL_RAY_TRI_SUB(tvec, orig, vert0); /* calculate U parameter and test bounds */ *u = IGL_RAY_TRI_DOT(tvec, pvec) * inv_det; if (*u < 0.0 || *u > 1.0) return 0; /* prepare to test V parameter */ IGL_RAY_TRI_CROSS(qvec, tvec, edge1); /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec) * inv_det; if (*v < 0.0 || *u + *v > 1.0) return 0; /* calculate t, ray intersects triangle */ *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; return 1; } /* code rewritten to do tests on the sign of the determinant */ /* the division is at the end in the code */ inline int intersect_triangle1(double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v) { double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; double det,inv_det; /* find vectors for two edges sharing vert0 */ IGL_RAY_TRI_SUB(edge1, vert1, vert0); IGL_RAY_TRI_SUB(edge2, vert2, vert0); /* begin calculating determinant - also used to calculate U parameter */ IGL_RAY_TRI_CROSS(pvec, dir, edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = IGL_RAY_TRI_DOT(edge1, pvec); if (det > IGL_RAY_TRI_EPSILON) { /* calculate distance from vert0 to ray origin */ IGL_RAY_TRI_SUB(tvec, orig, vert0); /* calculate U parameter and test bounds */ *u = IGL_RAY_TRI_DOT(tvec, pvec); if (*u < 0.0 || *u > det) return 0; /* prepare to test V parameter */ IGL_RAY_TRI_CROSS(qvec, tvec, edge1); /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec); if (*v < 0.0 || *u + *v > det) return 0; } else if(det < -IGL_RAY_TRI_EPSILON) { /* calculate distance from vert0 to ray origin */ IGL_RAY_TRI_SUB(tvec, orig, vert0); /* calculate U parameter and test bounds */ *u = IGL_RAY_TRI_DOT(tvec, pvec); /* printf("*u=%f\n",(float)*u); */ /* printf("det=%f\n",det); */ if (*u > 0.0 || *u < det) return 0; /* prepare to test V parameter */ IGL_RAY_TRI_CROSS(qvec, tvec, edge1); /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec) ; if (*v > 0.0 || *u + *v < det) return 0; } else return 0; /* ray is parallell to the plane of the triangle */ inv_det = 1.0 / det; /* calculate t, ray intersects triangle */ *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; (*u) *= inv_det; (*v) *= inv_det; return 1; } /* code rewritten to do tests on the sign of the determinant */ /* the division is before the test of the sign of the det */ inline int intersect_triangle2(double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v) { double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; double det,inv_det; /* find vectors for two edges sharing vert0 */ IGL_RAY_TRI_SUB(edge1, vert1, vert0); IGL_RAY_TRI_SUB(edge2, vert2, vert0); /* begin calculating determinant - also used to calculate U parameter */ IGL_RAY_TRI_CROSS(pvec, dir, edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = IGL_RAY_TRI_DOT(edge1, pvec); /* calculate distance from vert0 to ray origin */ IGL_RAY_TRI_SUB(tvec, orig, vert0); inv_det = 1.0 / det; if (det > IGL_RAY_TRI_EPSILON) { /* calculate U parameter and test bounds */ *u = IGL_RAY_TRI_DOT(tvec, pvec); if (*u < 0.0 || *u > det) return 0; /* prepare to test V parameter */ IGL_RAY_TRI_CROSS(qvec, tvec, edge1); /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec); if (*v < 0.0 || *u + *v > det) return 0; } else if(det < -IGL_RAY_TRI_EPSILON) { /* calculate U parameter and test bounds */ *u = IGL_RAY_TRI_DOT(tvec, pvec); if (*u > 0.0 || *u < det) return 0; /* prepare to test V parameter */ IGL_RAY_TRI_CROSS(qvec, tvec, edge1); /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec) ; if (*v > 0.0 || *u + *v < det) return 0; } else return 0; /* ray is parallell to the plane of the triangle */ /* calculate t, ray intersects triangle */ *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; (*u) *= inv_det; (*v) *= inv_det; return 1; } /* code rewritten to do tests on the sign of the determinant */ /* the division is before the test of the sign of the det */ /* and one IGL_RAY_TRI_CROSS has been moved out from the if-else if-else */ inline int intersect_triangle3(double orig[3], double dir[3], double vert0[3], double vert1[3], double vert2[3], double *t, double *u, double *v) { double edge1[3], edge2[3], tvec[3], pvec[3], qvec[3]; double det,inv_det; /* find vectors for two edges sharing vert0 */ IGL_RAY_TRI_SUB(edge1, vert1, vert0); IGL_RAY_TRI_SUB(edge2, vert2, vert0); /* begin calculating determinant - also used to calculate U parameter */ IGL_RAY_TRI_CROSS(pvec, dir, edge2); /* if determinant is near zero, ray lies in plane of triangle */ det = IGL_RAY_TRI_DOT(edge1, pvec); /* calculate distance from vert0 to ray origin */ IGL_RAY_TRI_SUB(tvec, orig, vert0); inv_det = 1.0 / det; IGL_RAY_TRI_CROSS(qvec, tvec, edge1); if (det > IGL_RAY_TRI_EPSILON) { *u = IGL_RAY_TRI_DOT(tvec, pvec); if (*u < 0.0 || *u > det) return 0; /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec); if (*v < 0.0 || *u + *v > det) return 0; } else if(det < -IGL_RAY_TRI_EPSILON) { /* calculate U parameter and test bounds */ *u = IGL_RAY_TRI_DOT(tvec, pvec); if (*u > 0.0 || *u < det) return 0; /* calculate V parameter and test bounds */ *v = IGL_RAY_TRI_DOT(dir, qvec) ; if (*v > 0.0 || *u + *v < det) return 0; } else return 0; /* ray is parallell to the plane of the triangle */ *t = IGL_RAY_TRI_DOT(edge2, qvec) * inv_det; (*u) *= inv_det; (*v) *= inv_det; return 1; } #endif
the_stack_data/66749.c
#include <stdio.h> #include <stdlib.h> #include <pthread.h> #include <assert.h> #define SIZE (1 << 20) #define MAX_FLAGS 16 int *a, num_threads; volatile char flag[MAX_FLAGS]; void *work (void *param) { int i, j, tid = *(int*)(param); int start_index, end_index; for (i=0; i<num_threads; i++) { start_index = (SIZE/num_threads)*((tid+i)%num_threads); end_index = (SIZE/num_threads)*(((tid+i+1) > num_threads) ? (tid+i+1)%num_threads : (tid+i+1)); for (j=start_index; j<end_index; j++) a[j] += tid; flag[(tid+i)%num_threads]++; if (i < num_threads - 1) while (flag[(tid+i+1)%num_threads] != (i+1)); } } int main (int argc, char *argv[]) { int i, j, *tid; pthread_t *threads; pthread_attr_t attr; long long unsigned sum = 0; if (argc != 2) { printf ("Need number of threads.\n"); exit(1); } num_threads = atoi(argv[1]); threads = (pthread_t*)malloc(num_threads*sizeof(pthread_t)); assert(threads != NULL); tid = (int*)malloc(num_threads*sizeof(int)); assert(tid != NULL); for (i=0; i<num_threads; i++) tid[i] = i; a = (int*)malloc(SIZE*sizeof(int)); assert(a != NULL); for (i=0; i<SIZE; i++) a[i] = i; assert(num_threads <= MAX_FLAGS); for (i=0; i<MAX_FLAGS; i++) flag[i] = 0; pthread_attr_init(&attr); for (i=1; i<num_threads; i++) { /* pthread_create arguments: thread pointer, attribute pointer, function pointer, argument pointer to the function */ pthread_create(&threads[i], &attr, work, &tid[i]); } work((void*)&tid[0]); for (i=1; i<num_threads; i++) { pthread_join(threads[i], NULL); } for (i=0; i<SIZE; i++) sum += a[i]; printf("SUM: %llu\n", sum); return 0; }
the_stack_data/87187.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); extern int __VERIFIER_nondet_int(void); /* Generated by CIL v. 1.3.7 */ /* print_CIL_Input is true */ struct JoinPoint { void **(*fp)(struct JoinPoint * ) ; void **args ; int argsCount ; char const **argsType ; void *(*arg)(int , struct JoinPoint * ) ; char const *(*argType)(int , struct JoinPoint * ) ; void **retValue ; char const *retType ; char const *funcName ; char const *targetName ; char const *fileName ; char const *kind ; void *excep_return ; }; struct __UTAC__CFLOW_FUNC { int (*func)(int , int ) ; int val ; struct __UTAC__CFLOW_FUNC *next ; }; struct __UTAC__EXCEPTION { void *jumpbuf ; unsigned long long prtValue ; int pops ; struct __UTAC__CFLOW_FUNC *cflowfuncs ; }; typedef unsigned int size_t; struct __ACC__ERR { void *v ; struct __ACC__ERR *next ; }; #pragma merger(0,"Test.i","") extern __attribute__((__nothrow__, __noreturn__)) void exit(int __status ) ; int cleanupTimeShifts = 12; int get_nondetMinMax07(void) { int retValue_acc ; int nd ; nd = __VERIFIER_nondet_int(); { if (nd == 0) { retValue_acc = 0; return (retValue_acc); } else { if (nd == 1) { retValue_acc = 1; return (retValue_acc); } else { if (nd == 2) { retValue_acc = 2; return (retValue_acc); } else { if (nd == 3) { retValue_acc = 3; return (retValue_acc); } else { if (nd == 4) { retValue_acc = 4; return (retValue_acc); } else { if (nd == 5) { retValue_acc = 5; return (retValue_acc); } else { if (nd == 6) { retValue_acc = 6; return (retValue_acc); } else { if (nd == 7) { retValue_acc = 7; return (retValue_acc); } else { { exit(0); } } } } } } } } } return (retValue_acc); } } void initPersonOnFloor(int person , int floor ) ; int getOrigin(int person ) ; void bobCall(void) { int tmp ; { { tmp = getOrigin(0); initPersonOnFloor(0, tmp); } return; } } void aliceCall(void) { int tmp ; { { tmp = getOrigin(1); initPersonOnFloor(1, tmp); } return; } } void angelinaCall(void) { int tmp ; { { tmp = getOrigin(2); initPersonOnFloor(2, tmp); } return; } } void chuckCall(void) { int tmp ; { { tmp = getOrigin(3); initPersonOnFloor(3, tmp); } return; } } void monicaCall(void) { int tmp ; { { tmp = getOrigin(4); initPersonOnFloor(4, tmp); } return; } } void bigMacCall(void) { int tmp ; { { tmp = getOrigin(5); initPersonOnFloor(5, tmp); } return; } } void timeShift(void) ; void threeTS(void) { { { timeShift(); timeShift(); timeShift(); } return; } } int isIdle(void) ; int isBlocked(void) ; void cleanup(void) { int i ; int tmp ; int tmp___0 ; int __cil_tmp4 ; { { timeShift(); i = 0; } { while (1) { while_0_continue: /* CIL Label */ ; { __cil_tmp4 = cleanupTimeShifts - 1; if (i < __cil_tmp4) { { tmp___0 = isBlocked(); } if (tmp___0 != 1) { } else { goto while_0_break; } } else { goto while_0_break; } } { tmp = isIdle(); } if (tmp) { return; } else { { timeShift(); } } i = i + 1; } while_0_break: /* CIL Label */ ; } return; } } void initTopDown(void) ; void initBottomUp(void) ; void randomSequenceOfActions(void) { int maxLength ; int tmp ; int counter ; int action ; int tmp___0 ; int origin ; int tmp___1 ; int tmp___2 ; { { maxLength = 4; tmp = __VERIFIER_nondet_int(); } if (tmp) { { initTopDown(); } } else { { initBottomUp(); } } counter = 0; { while (1) { while_1_continue: /* CIL Label */ ; if (counter < maxLength) { } else { goto while_1_break; } { counter = counter + 1; tmp___0 = get_nondetMinMax07(); action = tmp___0; } if (action < 6) { { tmp___1 = getOrigin(action); origin = tmp___1; initPersonOnFloor(action, origin); } } else { if (action == 6) { { timeShift(); } } else { if (action == 7) { { timeShift(); timeShift(); timeShift(); } } else { } } } { tmp___2 = isBlocked(); } if (tmp___2) { return; } else { } } while_1_break: /* CIL Label */ ; } { cleanup(); } return; } } void runTest_Simple(void) { { { bigMacCall(); angelinaCall(); cleanup(); } return; } } void Specification1(void) { { { bigMacCall(); angelinaCall(); cleanup(); } return; } } void Specification2(void) { { { bigMacCall(); cleanup(); } return; } } void Specification3(void) { { { bobCall(); timeShift(); timeShift(); timeShift(); timeShift(); timeShift(); bobCall(); cleanup(); } return; } } void setup(void) { { return; } } void __utac_acc__Specification2_spec__1(void) ; void __utac_acc__Specification2_spec__4(void) ; void test(void) ; void runTest(void) { { { __utac_acc__Specification2_spec__1(); test(); __utac_acc__Specification2_spec__4(); } return; } } void select_helpers(void) ; void select_features(void) ; int valid_product(void) ; int main(void) { int retValue_acc ; int tmp ; { { select_helpers(); select_features(); tmp = valid_product(); } if (tmp) { { setup(); runTest(); } } else { } retValue_acc = 0; return (retValue_acc); return (retValue_acc); } } #pragma merger(0,"Person.i","") int getWeight(int person ) ; int getDestination(int person ) ; int getWeight(int person ) { int retValue_acc ; { if (person == 0) { retValue_acc = 40; return (retValue_acc); } else { if (person == 1) { retValue_acc = 40; return (retValue_acc); } else { if (person == 2) { retValue_acc = 40; return (retValue_acc); } else { if (person == 3) { retValue_acc = 40; return (retValue_acc); } else { if (person == 4) { retValue_acc = 30; return (retValue_acc); } else { if (person == 5) { retValue_acc = 150; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } } } } } return (retValue_acc); } } int getOrigin(int person ) { int retValue_acc ; { if (person == 0) { retValue_acc = 4; return (retValue_acc); } else { if (person == 1) { retValue_acc = 3; return (retValue_acc); } else { if (person == 2) { retValue_acc = 2; return (retValue_acc); } else { if (person == 3) { retValue_acc = 1; return (retValue_acc); } else { if (person == 4) { retValue_acc = 0; return (retValue_acc); } else { if (person == 5) { retValue_acc = 1; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } } } } } return (retValue_acc); } } int getDestination(int person ) { int retValue_acc ; { if (person == 0) { retValue_acc = 0; return (retValue_acc); } else { if (person == 1) { retValue_acc = 0; return (retValue_acc); } else { if (person == 2) { retValue_acc = 1; return (retValue_acc); } else { if (person == 3) { retValue_acc = 3; return (retValue_acc); } else { if (person == 4) { retValue_acc = 1; return (retValue_acc); } else { if (person == 5) { retValue_acc = 3; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } } } } } return (retValue_acc); } } #pragma merger(0,"Specification2_spec.i","") void __automaton_fail(void) ; int areDoorsOpen(void) ; int getCurrentFloorID(void) ; int floorButtons_spc2_0 ; int floorButtons_spc2_1 ; int floorButtons_spc2_2 ; int floorButtons_spc2_3 ; int floorButtons_spc2_4 ; void __utac_acc__Specification2_spec__1(void) { { floorButtons_spc2_0 = 0; floorButtons_spc2_1 = 0; floorButtons_spc2_2 = 0; floorButtons_spc2_3 = 0; floorButtons_spc2_4 = 0; return; } } __inline void __utac_acc__Specification2_spec__2(int floor ) { { if (floor == 0) { floorButtons_spc2_0 = 1; } else { if (floor == 1) { floorButtons_spc2_1 = 1; } else { if (floor == 2) { floorButtons_spc2_2 = 1; } else { if (floor == 3) { floorButtons_spc2_3 = 1; } else { if (floor == 4) { floorButtons_spc2_4 = 1; } else { } } } } } return; } } __inline void __utac_acc__Specification2_spec__3(void) { int floor ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; { { tmp = getCurrentFloorID(); floor = tmp; } if (floor == 0) { if (floorButtons_spc2_0) { { tmp___4 = areDoorsOpen(); } if (tmp___4) { floorButtons_spc2_0 = 0; } else { goto _L___6; } } else { goto _L___6; } } else { _L___6: /* CIL Label */ if (floor == 1) { if (floorButtons_spc2_1) { { tmp___3 = areDoorsOpen(); } if (tmp___3) { floorButtons_spc2_1 = 0; } else { goto _L___4; } } else { goto _L___4; } } else { _L___4: /* CIL Label */ if (floor == 2) { if (floorButtons_spc2_2) { { tmp___2 = areDoorsOpen(); } if (tmp___2) { floorButtons_spc2_2 = 0; } else { goto _L___2; } } else { goto _L___2; } } else { _L___2: /* CIL Label */ if (floor == 3) { if (floorButtons_spc2_3) { { tmp___1 = areDoorsOpen(); } if (tmp___1) { floorButtons_spc2_3 = 0; } else { goto _L___0; } } else { goto _L___0; } } else { _L___0: /* CIL Label */ if (floor == 4) { if (floorButtons_spc2_4) { { tmp___0 = areDoorsOpen(); } if (tmp___0) { floorButtons_spc2_4 = 0; } else { } } else { } } else { } } } } } return; } } void __utac_acc__Specification2_spec__4(void) { { if (floorButtons_spc2_0) { { __automaton_fail(); } } else { if (floorButtons_spc2_1) { { __automaton_fail(); } } else { if (floorButtons_spc2_2) { { __automaton_fail(); } } else { if (floorButtons_spc2_3) { { __automaton_fail(); } } else { if (floorButtons_spc2_4) { { __automaton_fail(); } } else { } } } } } return; } } #pragma merger(0,"Floor.i","") int isFloorCalling(int floorID ) ; void resetCallOnFloor(int floorID ) ; void callOnFloor(int floorID ) ; int isPersonOnFloor(int person , int floor ) ; void removePersonFromFloor(int person , int floor ) ; int isTopFloor(int floorID ) ; void initFloors(void) ; int calls_0 ; int calls_1 ; int calls_2 ; int calls_3 ; int calls_4 ; int personOnFloor_0_0 ; int personOnFloor_0_1 ; int personOnFloor_0_2 ; int personOnFloor_0_3 ; int personOnFloor_0_4 ; int personOnFloor_1_0 ; int personOnFloor_1_1 ; int personOnFloor_1_2 ; int personOnFloor_1_3 ; int personOnFloor_1_4 ; int personOnFloor_2_0 ; int personOnFloor_2_1 ; int personOnFloor_2_2 ; int personOnFloor_2_3 ; int personOnFloor_2_4 ; int personOnFloor_3_0 ; int personOnFloor_3_1 ; int personOnFloor_3_2 ; int personOnFloor_3_3 ; int personOnFloor_3_4 ; int personOnFloor_4_0 ; int personOnFloor_4_1 ; int personOnFloor_4_2 ; int personOnFloor_4_3 ; int personOnFloor_4_4 ; int personOnFloor_5_0 ; int personOnFloor_5_1 ; int personOnFloor_5_2 ; int personOnFloor_5_3 ; int personOnFloor_5_4 ; void initFloors(void) { { calls_0 = 0; calls_1 = 0; calls_2 = 0; calls_3 = 0; calls_4 = 0; personOnFloor_0_0 = 0; personOnFloor_0_1 = 0; personOnFloor_0_2 = 0; personOnFloor_0_3 = 0; personOnFloor_0_4 = 0; personOnFloor_1_0 = 0; personOnFloor_1_1 = 0; personOnFloor_1_2 = 0; personOnFloor_1_3 = 0; personOnFloor_1_4 = 0; personOnFloor_2_0 = 0; personOnFloor_2_1 = 0; personOnFloor_2_2 = 0; personOnFloor_2_3 = 0; personOnFloor_2_4 = 0; personOnFloor_3_0 = 0; personOnFloor_3_1 = 0; personOnFloor_3_2 = 0; personOnFloor_3_3 = 0; personOnFloor_3_4 = 0; personOnFloor_4_0 = 0; personOnFloor_4_1 = 0; personOnFloor_4_2 = 0; personOnFloor_4_3 = 0; personOnFloor_4_4 = 0; personOnFloor_5_0 = 0; personOnFloor_5_1 = 0; personOnFloor_5_2 = 0; personOnFloor_5_3 = 0; personOnFloor_5_4 = 0; return; } } int isFloorCalling(int floorID ) { int retValue_acc ; { if (floorID == 0) { retValue_acc = calls_0; return (retValue_acc); } else { if (floorID == 1) { retValue_acc = calls_1; return (retValue_acc); } else { if (floorID == 2) { retValue_acc = calls_2; return (retValue_acc); } else { if (floorID == 3) { retValue_acc = calls_3; return (retValue_acc); } else { if (floorID == 4) { retValue_acc = calls_4; return (retValue_acc); } else { } } } } } retValue_acc = 0; return (retValue_acc); return (retValue_acc); } } void resetCallOnFloor(int floorID ) { { if (floorID == 0) { calls_0 = 0; } else { if (floorID == 1) { calls_1 = 0; } else { if (floorID == 2) { calls_2 = 0; } else { if (floorID == 3) { calls_3 = 0; } else { if (floorID == 4) { calls_4 = 0; } else { } } } } } return; } } void callOnFloor(int floorID ) { { if (floorID == 0) { calls_0 = 1; } else { if (floorID == 1) { calls_1 = 1; } else { if (floorID == 2) { calls_2 = 1; } else { if (floorID == 3) { calls_3 = 1; } else { if (floorID == 4) { calls_4 = 1; } else { } } } } } return; } } int isPersonOnFloor(int person , int floor ) { int retValue_acc ; { if (floor == 0) { if (person == 0) { retValue_acc = personOnFloor_0_0; return (retValue_acc); } else { if (person == 1) { retValue_acc = personOnFloor_1_0; return (retValue_acc); } else { if (person == 2) { retValue_acc = personOnFloor_2_0; return (retValue_acc); } else { if (person == 3) { retValue_acc = personOnFloor_3_0; return (retValue_acc); } else { if (person == 4) { retValue_acc = personOnFloor_4_0; return (retValue_acc); } else { if (person == 5) { retValue_acc = personOnFloor_5_0; return (retValue_acc); } else { } } } } } } } else { if (floor == 1) { if (person == 0) { retValue_acc = personOnFloor_0_1; return (retValue_acc); } else { if (person == 1) { retValue_acc = personOnFloor_1_1; return (retValue_acc); } else { if (person == 2) { retValue_acc = personOnFloor_2_1; return (retValue_acc); } else { if (person == 3) { retValue_acc = personOnFloor_3_1; return (retValue_acc); } else { if (person == 4) { retValue_acc = personOnFloor_4_1; return (retValue_acc); } else { if (person == 5) { retValue_acc = personOnFloor_5_1; return (retValue_acc); } else { } } } } } } } else { if (floor == 2) { if (person == 0) { retValue_acc = personOnFloor_0_2; return (retValue_acc); } else { if (person == 1) { retValue_acc = personOnFloor_1_2; return (retValue_acc); } else { if (person == 2) { retValue_acc = personOnFloor_2_2; return (retValue_acc); } else { if (person == 3) { retValue_acc = personOnFloor_3_2; return (retValue_acc); } else { if (person == 4) { retValue_acc = personOnFloor_4_2; return (retValue_acc); } else { if (person == 5) { retValue_acc = personOnFloor_5_2; return (retValue_acc); } else { } } } } } } } else { if (floor == 3) { if (person == 0) { retValue_acc = personOnFloor_0_3; return (retValue_acc); } else { if (person == 1) { retValue_acc = personOnFloor_1_3; return (retValue_acc); } else { if (person == 2) { retValue_acc = personOnFloor_2_3; return (retValue_acc); } else { if (person == 3) { retValue_acc = personOnFloor_3_3; return (retValue_acc); } else { if (person == 4) { retValue_acc = personOnFloor_4_3; return (retValue_acc); } else { if (person == 5) { retValue_acc = personOnFloor_5_3; return (retValue_acc); } else { } } } } } } } else { if (floor == 4) { if (person == 0) { retValue_acc = personOnFloor_0_4; return (retValue_acc); } else { if (person == 1) { retValue_acc = personOnFloor_1_4; return (retValue_acc); } else { if (person == 2) { retValue_acc = personOnFloor_2_4; return (retValue_acc); } else { if (person == 3) { retValue_acc = personOnFloor_3_4; return (retValue_acc); } else { if (person == 4) { retValue_acc = personOnFloor_4_4; return (retValue_acc); } else { if (person == 5) { retValue_acc = personOnFloor_5_4; return (retValue_acc); } else { } } } } } } } else { } } } } } retValue_acc = 0; return (retValue_acc); return (retValue_acc); } } void initPersonOnFloor(int person , int floor ) { { if (floor == 0) { if (person == 0) { personOnFloor_0_0 = 1; } else { if (person == 1) { personOnFloor_1_0 = 1; } else { if (person == 2) { personOnFloor_2_0 = 1; } else { if (person == 3) { personOnFloor_3_0 = 1; } else { if (person == 4) { personOnFloor_4_0 = 1; } else { if (person == 5) { personOnFloor_5_0 = 1; } else { } } } } } } } else { if (floor == 1) { if (person == 0) { personOnFloor_0_1 = 1; } else { if (person == 1) { personOnFloor_1_1 = 1; } else { if (person == 2) { personOnFloor_2_1 = 1; } else { if (person == 3) { personOnFloor_3_1 = 1; } else { if (person == 4) { personOnFloor_4_1 = 1; } else { if (person == 5) { personOnFloor_5_1 = 1; } else { } } } } } } } else { if (floor == 2) { if (person == 0) { personOnFloor_0_2 = 1; } else { if (person == 1) { personOnFloor_1_2 = 1; } else { if (person == 2) { personOnFloor_2_2 = 1; } else { if (person == 3) { personOnFloor_3_2 = 1; } else { if (person == 4) { personOnFloor_4_2 = 1; } else { if (person == 5) { personOnFloor_5_2 = 1; } else { } } } } } } } else { if (floor == 3) { if (person == 0) { personOnFloor_0_3 = 1; } else { if (person == 1) { personOnFloor_1_3 = 1; } else { if (person == 2) { personOnFloor_2_3 = 1; } else { if (person == 3) { personOnFloor_3_3 = 1; } else { if (person == 4) { personOnFloor_4_3 = 1; } else { if (person == 5) { personOnFloor_5_3 = 1; } else { } } } } } } } else { if (floor == 4) { if (person == 0) { personOnFloor_0_4 = 1; } else { if (person == 1) { personOnFloor_1_4 = 1; } else { if (person == 2) { personOnFloor_2_4 = 1; } else { if (person == 3) { personOnFloor_3_4 = 1; } else { if (person == 4) { personOnFloor_4_4 = 1; } else { if (person == 5) { personOnFloor_5_4 = 1; } else { } } } } } } } else { } } } } } { callOnFloor(floor); } return; } } void removePersonFromFloor(int person , int floor ) { { if (floor == 0) { if (person == 0) { personOnFloor_0_0 = 0; } else { if (person == 1) { personOnFloor_1_0 = 0; } else { if (person == 2) { personOnFloor_2_0 = 0; } else { if (person == 3) { personOnFloor_3_0 = 0; } else { if (person == 4) { personOnFloor_4_0 = 0; } else { if (person == 5) { personOnFloor_5_0 = 0; } else { } } } } } } } else { if (floor == 1) { if (person == 0) { personOnFloor_0_1 = 0; } else { if (person == 1) { personOnFloor_1_1 = 0; } else { if (person == 2) { personOnFloor_2_1 = 0; } else { if (person == 3) { personOnFloor_3_1 = 0; } else { if (person == 4) { personOnFloor_4_1 = 0; } else { if (person == 5) { personOnFloor_5_1 = 0; } else { } } } } } } } else { if (floor == 2) { if (person == 0) { personOnFloor_0_2 = 0; } else { if (person == 1) { personOnFloor_1_2 = 0; } else { if (person == 2) { personOnFloor_2_2 = 0; } else { if (person == 3) { personOnFloor_3_2 = 0; } else { if (person == 4) { personOnFloor_4_2 = 0; } else { if (person == 5) { personOnFloor_5_2 = 0; } else { } } } } } } } else { if (floor == 3) { if (person == 0) { personOnFloor_0_3 = 0; } else { if (person == 1) { personOnFloor_1_3 = 0; } else { if (person == 2) { personOnFloor_2_3 = 0; } else { if (person == 3) { personOnFloor_3_3 = 0; } else { if (person == 4) { personOnFloor_4_3 = 0; } else { if (person == 5) { personOnFloor_5_3 = 0; } else { } } } } } } } else { if (floor == 4) { if (person == 0) { personOnFloor_0_4 = 0; } else { if (person == 1) { personOnFloor_1_4 = 0; } else { if (person == 2) { personOnFloor_2_4 = 0; } else { if (person == 3) { personOnFloor_3_4 = 0; } else { if (person == 4) { personOnFloor_4_4 = 0; } else { if (person == 5) { personOnFloor_5_4 = 0; } else { } } } } } } } else { } } } } } { resetCallOnFloor(floor); } return; } } int isTopFloor(int floorID ) { int retValue_acc ; { retValue_acc = floorID == 4; return (retValue_acc); return (retValue_acc); } } #pragma merger(0,"featureselect.i","") int select_one(void) ; int select_one(void) { int retValue_acc ; int choice = __VERIFIER_nondet_int(); { retValue_acc = choice; return (retValue_acc); return (retValue_acc); } } void select_features(void) { { return; } } void select_helpers(void) { { return; } } int valid_product(void) { int retValue_acc ; { retValue_acc = 1; return (retValue_acc); return (retValue_acc); } } #pragma merger(0,"wsllib_check.i","") void __automaton_fail(void) { { ERROR: __VERIFIER_error(); return; } } #pragma merger(0,"Elevator.i","") extern int printf(char const * __restrict __format , ...) ; void enterElevator(int p ) ; void printState(void) ; int isEmpty(void) ; int isAnyLiftButtonPressed(void) ; int buttonForFloorIsPressed(int floorID ) ; int currentHeading = 1; int currentFloorID = 0; int persons_0 ; int persons_1 ; int persons_2 ; int persons_3 ; int persons_4 ; int persons_5 ; int doorState = 1; int floorButtons_0 ; int floorButtons_1 ; int floorButtons_2 ; int floorButtons_3 ; int floorButtons_4 ; void initTopDown(void) { { { currentFloorID = 4; currentHeading = 0; floorButtons_0 = 0; floorButtons_1 = 0; floorButtons_2 = 0; floorButtons_3 = 0; floorButtons_4 = 0; persons_0 = 0; persons_1 = 0; persons_2 = 0; persons_3 = 0; persons_4 = 0; persons_5 = 0; initFloors(); } return; } } void initBottomUp(void) { { { currentFloorID = 0; currentHeading = 1; floorButtons_0 = 0; floorButtons_1 = 0; floorButtons_2 = 0; floorButtons_3 = 0; floorButtons_4 = 0; persons_0 = 0; persons_1 = 0; persons_2 = 0; persons_3 = 0; persons_4 = 0; persons_5 = 0; initFloors(); } return; } } int isBlocked(void) { int retValue_acc ; { retValue_acc = 0; return (retValue_acc); return (retValue_acc); } } void enterElevator(int p ) { { if (p == 0) { persons_0 = 1; } else { if (p == 1) { persons_1 = 1; } else { if (p == 2) { persons_2 = 1; } else { if (p == 3) { persons_3 = 1; } else { if (p == 4) { persons_4 = 1; } else { if (p == 5) { persons_5 = 1; } else { } } } } } } return; } } void leaveElevator__wrappee__base(int p ) { { if (p == 0) { persons_0 = 0; } else { if (p == 1) { persons_1 = 0; } else { if (p == 2) { persons_2 = 0; } else { if (p == 3) { persons_3 = 0; } else { if (p == 4) { persons_4 = 0; } else { if (p == 5) { persons_5 = 0; } else { } } } } } } return; } } void leaveElevator(int p ) { int tmp ; { { leaveElevator__wrappee__base(p); tmp = isEmpty(); } if (tmp) { floorButtons_0 = 0; floorButtons_1 = 0; floorButtons_2 = 0; floorButtons_3 = 0; floorButtons_4 = 0; } else { } return; } } void pressInLiftFloorButton(int floorID ) { int __utac__ad__arg1 ; { { __utac__ad__arg1 = floorID; __utac_acc__Specification2_spec__2(__utac__ad__arg1); } if (floorID == 0) { floorButtons_0 = 1; } else { if (floorID == 1) { floorButtons_1 = 1; } else { if (floorID == 2) { floorButtons_2 = 1; } else { if (floorID == 3) { floorButtons_3 = 1; } else { if (floorID == 4) { floorButtons_4 = 1; } else { } } } } } return; } } void resetFloorButton(int floorID ) { { if (floorID == 0) { floorButtons_0 = 0; } else { if (floorID == 1) { floorButtons_1 = 0; } else { if (floorID == 2) { floorButtons_2 = 0; } else { if (floorID == 3) { floorButtons_3 = 0; } else { if (floorID == 4) { floorButtons_4 = 0; } else { } } } } } return; } } int getCurrentFloorID(void) { int retValue_acc ; { retValue_acc = currentFloorID; return (retValue_acc); return (retValue_acc); } } int areDoorsOpen(void) { int retValue_acc ; { retValue_acc = doorState; return (retValue_acc); return (retValue_acc); } } int buttonForFloorIsPressed(int floorID ) { int retValue_acc ; { if (floorID == 0) { retValue_acc = floorButtons_0; return (retValue_acc); } else { if (floorID == 1) { retValue_acc = floorButtons_1; return (retValue_acc); } else { if (floorID == 2) { retValue_acc = floorButtons_2; return (retValue_acc); } else { if (floorID == 3) { retValue_acc = floorButtons_3; return (retValue_acc); } else { if (floorID == 4) { retValue_acc = floorButtons_4; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } } } } return (retValue_acc); } } int getCurrentHeading(void) { int retValue_acc ; { retValue_acc = currentHeading; return (retValue_acc); return (retValue_acc); } } int isEmpty(void) { int retValue_acc ; { if (persons_0 == 1) { retValue_acc = 0; return (retValue_acc); } else { if (persons_1 == 1) { retValue_acc = 0; return (retValue_acc); } else { if (persons_2 == 1) { retValue_acc = 0; return (retValue_acc); } else { if (persons_3 == 1) { retValue_acc = 0; return (retValue_acc); } else { if (persons_4 == 1) { retValue_acc = 0; return (retValue_acc); } else { if (persons_5 == 1) { retValue_acc = 0; return (retValue_acc); } else { } } } } } } retValue_acc = 1; return (retValue_acc); return (retValue_acc); } } int anyStopRequested(void) { int retValue_acc ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; { { tmp___3 = isFloorCalling(0); } if (tmp___3) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_0) { retValue_acc = 1; return (retValue_acc); } else { { tmp___2 = isFloorCalling(1); } if (tmp___2) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_1) { retValue_acc = 1; return (retValue_acc); } else { { tmp___1 = isFloorCalling(2); } if (tmp___1) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_2) { retValue_acc = 1; return (retValue_acc); } else { { tmp___0 = isFloorCalling(3); } if (tmp___0) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_3) { retValue_acc = 1; return (retValue_acc); } else { { tmp = isFloorCalling(4); } if (tmp) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_4) { retValue_acc = 1; return (retValue_acc); } else { } } } } } } } } } } retValue_acc = 0; return (retValue_acc); return (retValue_acc); } } int isIdle(void) { int retValue_acc ; int tmp ; { { tmp = anyStopRequested(); retValue_acc = tmp == 0; } return (retValue_acc); return (retValue_acc); } } int stopRequestedInDirection(int dir , int respectFloorCalls , int respectInLiftCalls ) { int retValue_acc ; int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; { if (dir == 1) { { tmp = isTopFloor(currentFloorID); } if (tmp) { retValue_acc = 0; return (retValue_acc); } else { } if (currentFloorID < 0) { if (respectFloorCalls) { { tmp___4 = isFloorCalling(0); } if (tmp___4) { retValue_acc = 1; return (retValue_acc); } else { goto _L___16; } } else { goto _L___16; } } else { _L___16: /* CIL Label */ if (currentFloorID < 0) { if (respectInLiftCalls) { if (floorButtons_0) { retValue_acc = 1; return (retValue_acc); } else { goto _L___14; } } else { goto _L___14; } } else { _L___14: /* CIL Label */ if (currentFloorID < 1) { if (respectFloorCalls) { { tmp___3 = isFloorCalling(1); } if (tmp___3) { retValue_acc = 1; return (retValue_acc); } else { goto _L___12; } } else { goto _L___12; } } else { _L___12: /* CIL Label */ if (currentFloorID < 1) { if (respectInLiftCalls) { if (floorButtons_1) { retValue_acc = 1; return (retValue_acc); } else { goto _L___10; } } else { goto _L___10; } } else { _L___10: /* CIL Label */ if (currentFloorID < 2) { if (respectFloorCalls) { { tmp___2 = isFloorCalling(2); } if (tmp___2) { retValue_acc = 1; return (retValue_acc); } else { goto _L___8; } } else { goto _L___8; } } else { _L___8: /* CIL Label */ if (currentFloorID < 2) { if (respectInLiftCalls) { if (floorButtons_2) { retValue_acc = 1; return (retValue_acc); } else { goto _L___6; } } else { goto _L___6; } } else { _L___6: /* CIL Label */ if (currentFloorID < 3) { if (respectFloorCalls) { { tmp___1 = isFloorCalling(3); } if (tmp___1) { retValue_acc = 1; return (retValue_acc); } else { goto _L___4; } } else { goto _L___4; } } else { _L___4: /* CIL Label */ if (currentFloorID < 3) { if (respectInLiftCalls) { if (floorButtons_3) { retValue_acc = 1; return (retValue_acc); } else { goto _L___2; } } else { goto _L___2; } } else { _L___2: /* CIL Label */ if (currentFloorID < 4) { if (respectFloorCalls) { { tmp___0 = isFloorCalling(4); } if (tmp___0) { retValue_acc = 1; return (retValue_acc); } else { goto _L___0; } } else { goto _L___0; } } else { _L___0: /* CIL Label */ if (currentFloorID < 4) { if (respectInLiftCalls) { if (floorButtons_4) { retValue_acc = 1; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } else { retValue_acc = 0; return (retValue_acc); } } else { retValue_acc = 0; return (retValue_acc); } } } } } } } } } } } else { if (currentFloorID == 0) { retValue_acc = 0; return (retValue_acc); } else { } if (currentFloorID > 0) { if (respectFloorCalls) { { tmp___9 = isFloorCalling(0); } if (tmp___9) { retValue_acc = 1; return (retValue_acc); } else { goto _L___34; } } else { goto _L___34; } } else { _L___34: /* CIL Label */ if (currentFloorID > 0) { if (respectInLiftCalls) { if (floorButtons_0) { retValue_acc = 1; return (retValue_acc); } else { goto _L___32; } } else { goto _L___32; } } else { _L___32: /* CIL Label */ if (currentFloorID > 1) { if (respectFloorCalls) { { tmp___8 = isFloorCalling(1); } if (tmp___8) { retValue_acc = 1; return (retValue_acc); } else { goto _L___30; } } else { goto _L___30; } } else { _L___30: /* CIL Label */ if (currentFloorID > 1) { if (respectInLiftCalls) { if (floorButtons_1) { retValue_acc = 1; return (retValue_acc); } else { goto _L___28; } } else { goto _L___28; } } else { _L___28: /* CIL Label */ if (currentFloorID > 2) { if (respectFloorCalls) { { tmp___7 = isFloorCalling(2); } if (tmp___7) { retValue_acc = 1; return (retValue_acc); } else { goto _L___26; } } else { goto _L___26; } } else { _L___26: /* CIL Label */ if (currentFloorID > 2) { if (respectInLiftCalls) { if (floorButtons_2) { retValue_acc = 1; return (retValue_acc); } else { goto _L___24; } } else { goto _L___24; } } else { _L___24: /* CIL Label */ if (currentFloorID > 3) { if (respectFloorCalls) { { tmp___6 = isFloorCalling(3); } if (tmp___6) { retValue_acc = 1; return (retValue_acc); } else { goto _L___22; } } else { goto _L___22; } } else { _L___22: /* CIL Label */ if (currentFloorID > 3) { if (respectInLiftCalls) { if (floorButtons_3) { retValue_acc = 1; return (retValue_acc); } else { goto _L___20; } } else { goto _L___20; } } else { _L___20: /* CIL Label */ if (currentFloorID > 4) { if (respectFloorCalls) { { tmp___5 = isFloorCalling(4); } if (tmp___5) { retValue_acc = 1; return (retValue_acc); } else { goto _L___18; } } else { goto _L___18; } } else { _L___18: /* CIL Label */ if (currentFloorID > 4) { if (respectInLiftCalls) { if (floorButtons_4) { retValue_acc = 1; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } else { retValue_acc = 0; return (retValue_acc); } } else { retValue_acc = 0; return (retValue_acc); } } } } } } } } } } } return (retValue_acc); } } int isAnyLiftButtonPressed(void) { int retValue_acc ; { if (floorButtons_0) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_1) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_2) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_3) { retValue_acc = 1; return (retValue_acc); } else { if (floorButtons_4) { retValue_acc = 1; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } } } } return (retValue_acc); } } void continueInDirection(int dir ) { int tmp ; { currentHeading = dir; if (currentHeading == 1) { { tmp = isTopFloor(currentFloorID); } if (tmp) { currentHeading = 0; } else { } } else { if (currentFloorID == 0) { currentHeading = 1; } else { } } if (currentHeading == 1) { currentFloorID = currentFloorID + 1; } else { currentFloorID = currentFloorID - 1; } return; } } int stopRequestedAtCurrentFloor(void) { int retValue_acc ; int tmp ; int tmp___0 ; { { tmp___0 = isFloorCalling(currentFloorID); } if (tmp___0) { retValue_acc = 1; return (retValue_acc); } else { { tmp = buttonForFloorIsPressed(currentFloorID); } if (tmp) { retValue_acc = 1; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } } return (retValue_acc); } } int getReverseHeading(int ofHeading ) { int retValue_acc ; { if (ofHeading == 0) { retValue_acc = 1; return (retValue_acc); } else { retValue_acc = 0; return (retValue_acc); } return (retValue_acc); } } void processWaitingOnFloor(int floorID ) { int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; int tmp___10 ; { { tmp___0 = isPersonOnFloor(0, floorID); } if (tmp___0) { { removePersonFromFloor(0, floorID); tmp = getDestination(0); pressInLiftFloorButton(tmp); enterElevator(0); } } else { } { tmp___2 = isPersonOnFloor(1, floorID); } if (tmp___2) { { removePersonFromFloor(1, floorID); tmp___1 = getDestination(1); pressInLiftFloorButton(tmp___1); enterElevator(1); } } else { } { tmp___4 = isPersonOnFloor(2, floorID); } if (tmp___4) { { removePersonFromFloor(2, floorID); tmp___3 = getDestination(2); pressInLiftFloorButton(tmp___3); enterElevator(2); } } else { } { tmp___6 = isPersonOnFloor(3, floorID); } if (tmp___6) { { removePersonFromFloor(3, floorID); tmp___5 = getDestination(3); pressInLiftFloorButton(tmp___5); enterElevator(3); } } else { } { tmp___8 = isPersonOnFloor(4, floorID); } if (tmp___8) { { removePersonFromFloor(4, floorID); tmp___7 = getDestination(4); pressInLiftFloorButton(tmp___7); enterElevator(4); } } else { } { tmp___10 = isPersonOnFloor(5, floorID); } if (tmp___10) { { removePersonFromFloor(5, floorID); tmp___9 = getDestination(5); pressInLiftFloorButton(tmp___9); enterElevator(5); } } else { } { resetCallOnFloor(floorID); } return; } } void timeShift(void) { int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; int tmp___4 ; int tmp___5 ; int tmp___6 ; int tmp___7 ; int tmp___8 ; int tmp___9 ; { { tmp___9 = stopRequestedAtCurrentFloor(); } if (tmp___9) { doorState = 1; if (persons_0) { { tmp = getDestination(0); } if (tmp == currentFloorID) { { leaveElevator(0); } } else { } } else { } if (persons_1) { { tmp___0 = getDestination(1); } if (tmp___0 == currentFloorID) { { leaveElevator(1); } } else { } } else { } if (persons_2) { { tmp___1 = getDestination(2); } if (tmp___1 == currentFloorID) { { leaveElevator(2); } } else { } } else { } if (persons_3) { { tmp___2 = getDestination(3); } if (tmp___2 == currentFloorID) { { leaveElevator(3); } } else { } } else { } if (persons_4) { { tmp___3 = getDestination(4); } if (tmp___3 == currentFloorID) { { leaveElevator(4); } } else { } } else { } if (persons_5) { { tmp___4 = getDestination(5); } if (tmp___4 == currentFloorID) { { leaveElevator(5); } } else { } } else { } { processWaitingOnFloor(currentFloorID); resetFloorButton(currentFloorID); } } else { if (doorState == 1) { doorState = 0; } else { } { tmp___8 = stopRequestedInDirection(currentHeading, 1, 1); } if (tmp___8) { { continueInDirection(currentHeading); } } else { { tmp___6 = getReverseHeading(currentHeading); tmp___7 = stopRequestedInDirection(tmp___6, 1, 1); } if (tmp___7) { { tmp___5 = getReverseHeading(currentHeading); continueInDirection(tmp___5); } } else { { continueInDirection(currentHeading); } } } } { __utac_acc__Specification2_spec__3(); } return; } } void printState(void) { int tmp ; int tmp___0 ; int tmp___1 ; int tmp___2 ; int tmp___3 ; char const * __restrict __cil_tmp6 ; char const * __restrict __cil_tmp7 ; char const * __restrict __cil_tmp8 ; char const * __restrict __cil_tmp9 ; char const * __restrict __cil_tmp10 ; char const * __restrict __cil_tmp11 ; char const * __restrict __cil_tmp12 ; char const * __restrict __cil_tmp13 ; char const * __restrict __cil_tmp14 ; char const * __restrict __cil_tmp15 ; char const * __restrict __cil_tmp16 ; char const * __restrict __cil_tmp17 ; char const * __restrict __cil_tmp18 ; char const * __restrict __cil_tmp19 ; char const * __restrict __cil_tmp20 ; char const * __restrict __cil_tmp21 ; char const * __restrict __cil_tmp22 ; char const * __restrict __cil_tmp23 ; char const * __restrict __cil_tmp24 ; char const * __restrict __cil_tmp25 ; char const * __restrict __cil_tmp26 ; { { __cil_tmp6 = (char const * __restrict )"Elevator "; printf(__cil_tmp6); } if (doorState) { { __cil_tmp7 = (char const * __restrict )"[_]"; printf(__cil_tmp7); } } else { { __cil_tmp8 = (char const * __restrict )"[] "; printf(__cil_tmp8); } } { __cil_tmp9 = (char const * __restrict )" at "; printf(__cil_tmp9); __cil_tmp10 = (char const * __restrict )"%i"; printf(__cil_tmp10, currentFloorID); __cil_tmp11 = (char const * __restrict )" heading "; printf(__cil_tmp11); } if (currentHeading) { { __cil_tmp12 = (char const * __restrict )"up"; printf(__cil_tmp12); } } else { { __cil_tmp13 = (char const * __restrict )"down"; printf(__cil_tmp13); } } { __cil_tmp14 = (char const * __restrict )" IL_p:"; printf(__cil_tmp14); } if (floorButtons_0) { { __cil_tmp15 = (char const * __restrict )" %i"; printf(__cil_tmp15, 0); } } else { } if (floorButtons_1) { { __cil_tmp16 = (char const * __restrict )" %i"; printf(__cil_tmp16, 1); } } else { } if (floorButtons_2) { { __cil_tmp17 = (char const * __restrict )" %i"; printf(__cil_tmp17, 2); } } else { } if (floorButtons_3) { { __cil_tmp18 = (char const * __restrict )" %i"; printf(__cil_tmp18, 3); } } else { } if (floorButtons_4) { { __cil_tmp19 = (char const * __restrict )" %i"; printf(__cil_tmp19, 4); } } else { } { __cil_tmp20 = (char const * __restrict )" F_p:"; printf(__cil_tmp20); tmp = isFloorCalling(0); } if (tmp) { { __cil_tmp21 = (char const * __restrict )" %i"; printf(__cil_tmp21, 0); } } else { } { tmp___0 = isFloorCalling(1); } if (tmp___0) { { __cil_tmp22 = (char const * __restrict )" %i"; printf(__cil_tmp22, 1); } } else { } { tmp___1 = isFloorCalling(2); } if (tmp___1) { { __cil_tmp23 = (char const * __restrict )" %i"; printf(__cil_tmp23, 2); } } else { } { tmp___2 = isFloorCalling(3); } if (tmp___2) { { __cil_tmp24 = (char const * __restrict )" %i"; printf(__cil_tmp24, 3); } } else { } { tmp___3 = isFloorCalling(4); } if (tmp___3) { { __cil_tmp25 = (char const * __restrict )" %i"; printf(__cil_tmp25, 4); } } else { } { __cil_tmp26 = (char const * __restrict )"\n"; printf(__cil_tmp26); } return; } } int existInLiftCallsInDirection(int d ) { int retValue_acc ; int i ; int i___0 ; { if (d == 1) { i = 0; i = currentFloorID + 1; { while (1) { while_2_continue: /* CIL Label */ ; if (i < 5) { } else { goto while_2_break; } if (i == 0) { if (floorButtons_0) { retValue_acc = 1; return (retValue_acc); } else { goto _L___2; } } else { _L___2: /* CIL Label */ if (i == 1) { if (floorButtons_1) { retValue_acc = 1; return (retValue_acc); } else { goto _L___1; } } else { _L___1: /* CIL Label */ if (i == 2) { if (floorButtons_2) { retValue_acc = 1; return (retValue_acc); } else { goto _L___0; } } else { _L___0: /* CIL Label */ if (i == 3) { if (floorButtons_3) { retValue_acc = 1; return (retValue_acc); } else { goto _L; } } else { _L: /* CIL Label */ if (i == 4) { if (floorButtons_4) { retValue_acc = 1; return (retValue_acc); } else { } } else { } } } } } i = i + 1; } while_2_break: /* CIL Label */ ; } } else { if (d == 0) { i___0 = 0; i___0 = currentFloorID - 1; { while (1) { while_3_continue: /* CIL Label */ ; if (i___0 >= 0) { } else { goto while_3_break; } i___0 = currentFloorID + 1; { while (1) { while_4_continue: /* CIL Label */ ; if (i___0 < 5) { } else { goto while_4_break; } if (i___0 == 0) { if (floorButtons_0) { retValue_acc = 1; return (retValue_acc); } else { goto _L___6; } } else { _L___6: /* CIL Label */ if (i___0 == 1) { if (floorButtons_1) { retValue_acc = 1; return (retValue_acc); } else { goto _L___5; } } else { _L___5: /* CIL Label */ if (i___0 == 2) { if (floorButtons_2) { retValue_acc = 1; return (retValue_acc); } else { goto _L___4; } } else { _L___4: /* CIL Label */ if (i___0 == 3) { if (floorButtons_3) { retValue_acc = 1; return (retValue_acc); } else { goto _L___3; } } else { _L___3: /* CIL Label */ if (i___0 == 4) { if (floorButtons_4) { retValue_acc = 1; return (retValue_acc); } else { } } else { } } } } } i___0 = i___0 + 1; } while_4_break: /* CIL Label */ ; } i___0 = i___0 - 1; } while_3_break: /* CIL Label */ ; } } else { } } retValue_acc = 0; return (retValue_acc); return (retValue_acc); } } #pragma merger(0,"libacc.i","") extern __attribute__((__nothrow__, __noreturn__)) void __assert_fail(char const *__assertion , char const *__file , unsigned int __line , char const *__function ) ; extern __attribute__((__nothrow__)) void *malloc(size_t __size ) __attribute__((__malloc__)) ; extern __attribute__((__nothrow__)) void free(void *__ptr ) ; void __utac__exception__cf_handler_set(void *exception , int (*cflow_func)(int , int ) , int val ) { struct __UTAC__EXCEPTION *excep ; struct __UTAC__CFLOW_FUNC *cf ; void *tmp ; unsigned long __cil_tmp7 ; unsigned long __cil_tmp8 ; unsigned long __cil_tmp9 ; unsigned long __cil_tmp10 ; unsigned long __cil_tmp11 ; unsigned long __cil_tmp12 ; unsigned long __cil_tmp13 ; unsigned long __cil_tmp14 ; int (**mem_15)(int , int ) ; int *mem_16 ; struct __UTAC__CFLOW_FUNC **mem_17 ; struct __UTAC__CFLOW_FUNC **mem_18 ; struct __UTAC__CFLOW_FUNC **mem_19 ; { { excep = (struct __UTAC__EXCEPTION *)exception; tmp = malloc(24UL); cf = (struct __UTAC__CFLOW_FUNC *)tmp; mem_15 = (int (**)(int , int ))cf; *mem_15 = cflow_func; __cil_tmp7 = (unsigned long )cf; __cil_tmp8 = __cil_tmp7 + 8; mem_16 = (int *)__cil_tmp8; *mem_16 = val; __cil_tmp9 = (unsigned long )cf; __cil_tmp10 = __cil_tmp9 + 16; __cil_tmp11 = (unsigned long )excep; __cil_tmp12 = __cil_tmp11 + 24; mem_17 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp10; mem_18 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp12; *mem_17 = *mem_18; __cil_tmp13 = (unsigned long )excep; __cil_tmp14 = __cil_tmp13 + 24; mem_19 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp14; *mem_19 = cf; } return; } } void __utac__exception__cf_handler_free(void *exception ) { struct __UTAC__EXCEPTION *excep ; struct __UTAC__CFLOW_FUNC *cf ; struct __UTAC__CFLOW_FUNC *tmp ; unsigned long __cil_tmp5 ; unsigned long __cil_tmp6 ; struct __UTAC__CFLOW_FUNC *__cil_tmp7 ; unsigned long __cil_tmp8 ; unsigned long __cil_tmp9 ; unsigned long __cil_tmp10 ; unsigned long __cil_tmp11 ; void *__cil_tmp12 ; unsigned long __cil_tmp13 ; unsigned long __cil_tmp14 ; struct __UTAC__CFLOW_FUNC **mem_15 ; struct __UTAC__CFLOW_FUNC **mem_16 ; struct __UTAC__CFLOW_FUNC **mem_17 ; { excep = (struct __UTAC__EXCEPTION *)exception; __cil_tmp5 = (unsigned long )excep; __cil_tmp6 = __cil_tmp5 + 24; mem_15 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp6; cf = *mem_15; { while (1) { while_5_continue: /* CIL Label */ ; { __cil_tmp7 = (struct __UTAC__CFLOW_FUNC *)0; __cil_tmp8 = (unsigned long )__cil_tmp7; __cil_tmp9 = (unsigned long )cf; if (__cil_tmp9 != __cil_tmp8) { } else { goto while_5_break; } } { tmp = cf; __cil_tmp10 = (unsigned long )cf; __cil_tmp11 = __cil_tmp10 + 16; mem_16 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp11; cf = *mem_16; __cil_tmp12 = (void *)tmp; free(__cil_tmp12); } } while_5_break: /* CIL Label */ ; } __cil_tmp13 = (unsigned long )excep; __cil_tmp14 = __cil_tmp13 + 24; mem_17 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp14; *mem_17 = (struct __UTAC__CFLOW_FUNC *)0; return; } } void __utac__exception__cf_handler_reset(void *exception ) { struct __UTAC__EXCEPTION *excep ; struct __UTAC__CFLOW_FUNC *cf ; unsigned long __cil_tmp5 ; unsigned long __cil_tmp6 ; struct __UTAC__CFLOW_FUNC *__cil_tmp7 ; unsigned long __cil_tmp8 ; unsigned long __cil_tmp9 ; int (*__cil_tmp10)(int , int ) ; unsigned long __cil_tmp11 ; unsigned long __cil_tmp12 ; int __cil_tmp13 ; unsigned long __cil_tmp14 ; unsigned long __cil_tmp15 ; struct __UTAC__CFLOW_FUNC **mem_16 ; int (**mem_17)(int , int ) ; int *mem_18 ; struct __UTAC__CFLOW_FUNC **mem_19 ; { excep = (struct __UTAC__EXCEPTION *)exception; __cil_tmp5 = (unsigned long )excep; __cil_tmp6 = __cil_tmp5 + 24; mem_16 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp6; cf = *mem_16; { while (1) { while_6_continue: /* CIL Label */ ; { __cil_tmp7 = (struct __UTAC__CFLOW_FUNC *)0; __cil_tmp8 = (unsigned long )__cil_tmp7; __cil_tmp9 = (unsigned long )cf; if (__cil_tmp9 != __cil_tmp8) { } else { goto while_6_break; } } { mem_17 = (int (**)(int , int ))cf; __cil_tmp10 = *mem_17; __cil_tmp11 = (unsigned long )cf; __cil_tmp12 = __cil_tmp11 + 8; mem_18 = (int *)__cil_tmp12; __cil_tmp13 = *mem_18; (*__cil_tmp10)(4, __cil_tmp13); __cil_tmp14 = (unsigned long )cf; __cil_tmp15 = __cil_tmp14 + 16; mem_19 = (struct __UTAC__CFLOW_FUNC **)__cil_tmp15; cf = *mem_19; } } while_6_break: /* CIL Label */ ; } { __utac__exception__cf_handler_free(exception); } return; } } void *__utac__error_stack_mgt(void *env , int mode , int count ) ; static struct __ACC__ERR *head = (struct __ACC__ERR *)0; void *__utac__error_stack_mgt(void *env , int mode , int count ) { void *retValue_acc ; struct __ACC__ERR *new ; void *tmp ; struct __ACC__ERR *temp ; struct __ACC__ERR *next ; void *excep ; unsigned long __cil_tmp10 ; unsigned long __cil_tmp11 ; unsigned long __cil_tmp12 ; unsigned long __cil_tmp13 ; void *__cil_tmp14 ; unsigned long __cil_tmp15 ; unsigned long __cil_tmp16 ; void *__cil_tmp17 ; void **mem_18 ; struct __ACC__ERR **mem_19 ; struct __ACC__ERR **mem_20 ; void **mem_21 ; struct __ACC__ERR **mem_22 ; void **mem_23 ; void **mem_24 ; { if (count == 0) { return (retValue_acc); } else { } if (mode == 0) { { tmp = malloc(16UL); new = (struct __ACC__ERR *)tmp; mem_18 = (void **)new; *mem_18 = env; __cil_tmp10 = (unsigned long )new; __cil_tmp11 = __cil_tmp10 + 8; mem_19 = (struct __ACC__ERR **)__cil_tmp11; *mem_19 = head; head = new; retValue_acc = (void *)new; } return (retValue_acc); } else { } if (mode == 1) { temp = head; { while (1) { while_7_continue: /* CIL Label */ ; if (count > 1) { } else { goto while_7_break; } { __cil_tmp12 = (unsigned long )temp; __cil_tmp13 = __cil_tmp12 + 8; mem_20 = (struct __ACC__ERR **)__cil_tmp13; next = *mem_20; mem_21 = (void **)temp; excep = *mem_21; __cil_tmp14 = (void *)temp; free(__cil_tmp14); __utac__exception__cf_handler_reset(excep); temp = next; count = count - 1; } } while_7_break: /* CIL Label */ ; } { __cil_tmp15 = (unsigned long )temp; __cil_tmp16 = __cil_tmp15 + 8; mem_22 = (struct __ACC__ERR **)__cil_tmp16; head = *mem_22; mem_23 = (void **)temp; excep = *mem_23; __cil_tmp17 = (void *)temp; free(__cil_tmp17); __utac__exception__cf_handler_reset(excep); retValue_acc = excep; } return (retValue_acc); } else { } if (mode == 2) { if (head) { mem_24 = (void **)head; retValue_acc = *mem_24; return (retValue_acc); } else { retValue_acc = (void *)0; return (retValue_acc); } } else { } return (retValue_acc); } } void *__utac__get_this_arg(int i , struct JoinPoint *this ) { void *retValue_acc ; unsigned long __cil_tmp4 ; unsigned long __cil_tmp5 ; int __cil_tmp6 ; int __cil_tmp7 ; unsigned long __cil_tmp8 ; unsigned long __cil_tmp9 ; void **__cil_tmp10 ; void **__cil_tmp11 ; int *mem_12 ; void ***mem_13 ; { if (i > 0) { { __cil_tmp4 = (unsigned long )this; __cil_tmp5 = __cil_tmp4 + 16; mem_12 = (int *)__cil_tmp5; __cil_tmp6 = *mem_12; if (i <= __cil_tmp6) { } else { { __assert_fail("i > 0 && i <= this->argsCount", "libacc.c", 123U, "__utac__get_this_arg"); } } } } else { { __assert_fail("i > 0 && i <= this->argsCount", "libacc.c", 123U, "__utac__get_this_arg"); } } __cil_tmp7 = i - 1; __cil_tmp8 = (unsigned long )this; __cil_tmp9 = __cil_tmp8 + 8; mem_13 = (void ***)__cil_tmp9; __cil_tmp10 = *mem_13; __cil_tmp11 = __cil_tmp10 + __cil_tmp7; retValue_acc = *__cil_tmp11; return (retValue_acc); return (retValue_acc); } } char const *__utac__get_this_argtype(int i , struct JoinPoint *this ) { char const *retValue_acc ; unsigned long __cil_tmp4 ; unsigned long __cil_tmp5 ; int __cil_tmp6 ; int __cil_tmp7 ; unsigned long __cil_tmp8 ; unsigned long __cil_tmp9 ; char const **__cil_tmp10 ; char const **__cil_tmp11 ; int *mem_12 ; char const ***mem_13 ; { if (i > 0) { { __cil_tmp4 = (unsigned long )this; __cil_tmp5 = __cil_tmp4 + 16; mem_12 = (int *)__cil_tmp5; __cil_tmp6 = *mem_12; if (i <= __cil_tmp6) { } else { { __assert_fail("i > 0 && i <= this->argsCount", "libacc.c", 131U, "__utac__get_this_argtype"); } } } } else { { __assert_fail("i > 0 && i <= this->argsCount", "libacc.c", 131U, "__utac__get_this_argtype"); } } __cil_tmp7 = i - 1; __cil_tmp8 = (unsigned long )this; __cil_tmp9 = __cil_tmp8 + 24; mem_13 = (char const ***)__cil_tmp9; __cil_tmp10 = *mem_13; __cil_tmp11 = __cil_tmp10 + __cil_tmp7; retValue_acc = *__cil_tmp11; return (retValue_acc); return (retValue_acc); } } #pragma merger(0,"scenario.i","") void test(void) { { { bigMacCall(); cleanup(); } return; } } #pragma merger(0,"UnitTests.i","") void spec1(void) { int tmp ; int tmp___0 ; int i ; int tmp___1 ; { { initBottomUp(); tmp = getOrigin(5); initPersonOnFloor(5, tmp); printState(); tmp___0 = getOrigin(2); initPersonOnFloor(2, tmp___0); printState(); i = 0; } { while (1) { while_8_continue: /* CIL Label */ ; if (i < cleanupTimeShifts) { { tmp___1 = isBlocked(); } if (tmp___1 != 1) { } else { goto while_8_break; } } else { goto while_8_break; } { timeShift(); printState(); i = i + 1; } } while_8_break: /* CIL Label */ ; } return; } } void spec14(void) { int tmp ; int tmp___0 ; int i ; int tmp___1 ; { { initTopDown(); tmp = getOrigin(5); initPersonOnFloor(5, tmp); printState(); timeShift(); timeShift(); timeShift(); timeShift(); tmp___0 = getOrigin(0); initPersonOnFloor(0, tmp___0); printState(); i = 0; } { while (1) { while_9_continue: /* CIL Label */ ; if (i < cleanupTimeShifts) { { tmp___1 = isBlocked(); } if (tmp___1 != 1) { } else { goto while_9_break; } } else { goto while_9_break; } { timeShift(); printState(); i = i + 1; } } while_9_break: /* CIL Label */ ; } return; } }
the_stack_data/153267845.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char const *argv[]) { int key = 0; char str[100] = ""; if (argc != 2) //get exactly 1 argument { printf("Usage: ./caesar key\n"); exit(1); } key = atoi(argv[1]); while (1) { printf("plaintext: "); fgets(str, 100, stdin); if (str[0] != '\n') break; } for (size_t i = 0; i < strlen(str); i++) { if (islower(str[i])) str[i] = (str[i] - 'a' + key) % 26 + 'a'; else if (isupper(str[i])) str[i] = (str[i] - 'A' + key) % 26 + 'A'; } printf("ciphertext: %s\n", str); return 0; }
the_stack_data/9513533.c
char stdout[0]; char stderr[0];
the_stack_data/148636.c
// SKIP PARAM: --set solver td3 --set ana.activated "['base','threadid','threadflag','mallocWrapper','apron']" --set ana.base.privatization none --set ana.apron.privatization dummy // Example from https://github.com/sosy-lab/sv-benchmarks/blob/master/c/bitvector-regression/signextension-1.c #include <assert.h> int main() { unsigned short int allbits = -1; short int signedallbits = allbits; int unsignedtosigned = allbits; unsigned int unsignedtounsigned = allbits; int signedtosigned = signedallbits; unsigned int signedtounsigned = signedallbits; if (unsignedtosigned == 65535 && unsignedtounsigned == 65535 && signedtosigned == -1 && signedtounsigned == 4294967295) { assert(1); // reachable } return (0); }
the_stack_data/40387.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <arpa/inet.h> #include <sys/socket.h> #include <sys/stat.h> //----------------------------------------------------------------------------*/ /* 전처리기 선언 //----------------------------------------------------------------------------*/ #ifndef true #define true (1) #endif #ifndef false #define false (0) #endif #define SEVERITY_SUCCESS (0) #define SEVERITY_ERROR (1) #define INVALID_SOCKET ((int)~0) #define PACKET_LENGTH_MAX (1024) //----------------------------------------------------------------------------*/ /* 전역 함수 선언 //----------------------------------------------------------------------------*/ int SetNonBlockSocket(int FileDescriptor); //----------------------------------------------------------------------------*/ /* 엔트리 포인트 //----------------------------------------------------------------------------*/ int main(int argc, char** argv) { if(argc <= 1) { printf("매개변수가 부족함!\n"); return SEVERITY_ERROR; } int ClientFDs[1024] = { 0 }; memset((void*)ClientFDs, 0x00, sizeof(int) * 1024); int ServerSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); if(ServerSocket < 0) { printf("Server socket create failed!\n"); return SEVERITY_ERROR; } struct sockaddr_in ServerAddress; ServerAddress.sin_family = AF_INET; ServerAddress.sin_addr.s_addr = htonl(INADDR_ANY); ServerAddress.sin_port = htons(atoi(argv[1])); int BindResult = bind(ServerSocket, (const struct sockaddr*)&ServerAddress, sizeof(ServerAddress)); if(BindResult == INVALID_SOCKET) { printf("Server socket bind error!\n"); return SEVERITY_ERROR; } int ListenResult = listen(ServerSocket, 5); if(ListenResult == INVALID_SOCKET) { printf("Server socket listen failed!\n"); return SEVERITY_ERROR; } SetNonBlockSocket(ServerSocket); int MaxFD = ServerSocket; int ClientSocket = 0; struct sockaddr_in ClientAddress; int ClientAddressLength = 0; char Buffer[PACKET_LENGTH_MAX] = { 0 }; while(true) { memset(Buffer, 0x00, sizeof(char) * PACKET_LENGTH_MAX); ClientSocket = accept(ServerSocket, (struct sockaddr*)&ClientAddress, &ClientAddressLength); if(ClientSocket == INVALID_SOCKET) { if(errno == EAGAIN) { } else { continue; } } else { SetNonBlockSocket(ClientSocket); ClientFDs[ClientSocket] = 1; if(ClientSocket > MaxFD) { MaxFD = ClientSocket; } continue; } memset(Buffer, 0x00, sizeof(char) * PACKET_LENGTH_MAX); int ReadNumber = 0; for(int Index = 0; Index < MaxFD; ++Index) { if(ClientFDs[Index] != 1) { continue; } ClientSocket = Index; ReadNumber = read(ClientSocket, (void*)Buffer, PACKET_LENGTH_MAX); if(ReadNumber == -1) { if(errno == EAGAIN) { } else { printf("read Error! %d\n", errno); close(ClientSocket); ClientFDs[Index] = -1; break; } } else if(ReadNumber == 0) { printf("close %d\n", errno); close(ClientSocket); ClientFDs[Index] = -1; break; } else { printf("Read data : %s\n", Buffer); write(ClientSocket, Buffer, PACKET_LENGTH_MAX); } } } return SEVERITY_SUCCESS; } //----------------------------------------------------------------------------*/ int SetNonBlockSocket(int FileDescriptor) { int Flags = fcntl(FileDescriptor, F_GETFL, 0); if(Flags == -1) { printf("File control error!\n"); Flags = 0; } return fcntl(FileDescriptor, F_SETFL, Flags | O_NONBLOCK); }
the_stack_data/162644127.c
int main() { int i; int res = 0; goto L1; while (i < 10) { L2: res++; goto L3; L1: i = 0; goto L2; L3: i++; } return res; }
the_stack_data/105661.c
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_convert_base.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mpatrini <[email protected]> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/12/10 16:12:15 by mpatrini #+# #+# */ /* Updated: 2021/12/15 21:50:34 by mpatrini ### ########.fr */ /* */ /* ************************************************************************** */ #include <unistd.h> #include <stdio.h> #include <stdlib.h> int ft_valid_base(char *str); int ft_atoi_base(char *str, char *base); int ft_strlen(char *str); void ft_rev_int_tab(char *tab, int size, int sign) { int i; int s; char temp; if (sign == -1) i = 1; else i = 0; s = size - 1; while (i < s) { temp = tab[i]; tab[i] = tab[s]; tab[s] = temp; i++; s--; } } char *ft_strncpy(char *dest, char *src, unsigned int n) { unsigned int i; i = 0; while (src[i] != '\0' && i < n) { dest[i] = src[i]; i++; } while (i < n) { dest[i] = '\0'; i++; } return (dest); } void ft_putnbr_base_rec(int nbr, char *base, int i, char *final) { int mult; mult = ft_strlen(base); i += 1; if (nbr == -2147483648) { final[i] = '-'; final[i + 1] = (base[-(nbr % mult)]); i += 1; ft_putnbr_base_rec(-(nbr / mult), base, i, final); return ; } if (nbr < 0) { final[i] = '-'; ft_putnbr_base_rec(-nbr, base, i, final); return ; } if (nbr > mult -1) ft_putnbr_base_rec(nbr / mult, base, i, final); final[i] = (base[(nbr % mult)]); } char *ft_convert_base(char *nbr, char *base_from, char *base_to) { char *final; int i; int size; int ma; ma = 300; final = (char *)malloc(ma * sizeof(char)); if (!final) return (NULL); if (ft_valid_base(base_to) == 0) return (NULL); if (ft_valid_base(base_from) == 0) return (NULL); i = -1; ft_putnbr_base_rec(ft_atoi_base(nbr, base_from), base_to, i, final); size = ft_strlen(final); if (final[0] == 45) ft_rev_int_tab(final, size, -1); else ft_rev_int_tab(final, size, 1); return (final); }
the_stack_data/90765439.c
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #define MAX 512 int main(int argc, char *argv[]) { char buf[MAX]; int source_fd, target_fd; int read_bytes; if (argc < 3) { fprintf(stderr, "Too less parameters. Use:\n"); fprintf(stderr, "%s <source file> <target file>\n", argv[0]); exit(1); } source_fd = open(argv[1], O_RDONLY); if (source_fd == -1) { perror("Source file open error"); exit(1); } target_fd = creat(argv[2], 0640); if (target_fd == -1) { perror("Target file open error"); exit(1); } while ((read_bytes = read(source_fd, buf, MAX)) > 0) { if (write(target_fd, buf, read_bytes) == -1) { perror("Target file writing error"); exit(1); } } if (read_bytes == -1) { perror("Source file read error"); exit(1); } if (close(source_fd) == -1 || close(target_fd) == -1) { perror("File close error"); exit(1); } exit(0); }
the_stack_data/122127.c
/* ** EPITECH PROJECT, 2019 ** my_swap.c ** File description: ** fct that swaps the content of 2 int */ void my_swap(int *a, int *b) { int c; c = *a; *a = *b; *b = c; }
the_stack_data/70449873.c
//#include "SPI.h" //void SPI_Init(void) //{ // //} //void SPI_ReadWriteByte(u8 txData) //{ // //}
the_stack_data/231392471.c
#include <stdio.h> #define SWAp(A, B) {A = A+B; B = A-B; A = A - B;} int gcd(int x, int y) { if (y==0) return x; else return gcd(y, x%y); } int lcd(int x, int y) { return (x*y)/gcd(x, y); } int main() { int m, n; while (scanf("%d%d", &m, &n) != EOF) { if(m<n) SWAp(m, n); printf("%d \n", gcd(m, n)); printf("%d \n", lcd(m, n)); if (getchar()=='\n') break; } return 0; }
the_stack_data/65992.c
// Copyright (c) 2020, devgo.club // All rights reserved. #include <stdio.h> #include <stdlib.h> /* (1) auto用于在函数中修饰变量为自动变量,且可省略。 (2) 当省略数据类型,只使用auto修饰变量,在C语言中默认变量为int型 (3) 在函数中没有被声明为其他类型的变量默认都是自动变量,因此auto算是C语言中应用最广泛的一种类型。 (4) auto不能修饰全局变量,因为自动变量只能存在于函数内。 (5) 自动变量属于动态存储类型,只存在于函数内。其存储单元在函数被调用时分配,在函数调用结束后被释放。 这个过程是通过一个堆栈的机制来实现的。为自动变量分配内存就压栈,而函数返回时就退栈。 自动变量如果不赋值,则变量的值是不确定的。这是因为在函数被调用时,会为该变量随机分配一个存储空间,该存储空间的值和地址都是不确定的。 */ // auto n; // error: file-scope declaration of 'n' specifies 'auto' int main(int argc, char const *argv[]) { double f1 = 3.33; double f2 = 9.78; printf("f1=%lf, f2=%lf\n", f1, f2); auto n1 = 5; // warning: type defaults to 'int' in declaration of 'n1' printf("n1: val=%d, size=%lu\n", n1, sizeof(n1)); n1 = (int)(f1 + f2); printf("n1: val=%d, size=%lu\n", n1, sizeof(n1)); double auto f3 = f1 + f2; printf("f3: val=%lf\n", f3); return EXIT_SUCCESS; }
the_stack_data/9511860.c
// SPDX-License-Identifier: GPL-2.0 /* * Example of using hugepage memory in a user application using the mmap * system call with MAP_HUGETLB flag. Before running this program make * sure the administrator has allocated enough default sized huge pages * to cover the 256 MB allocation. * * For ia64 architecture, Linux kernel reserves Region number 4 for hugepages. * That means the addresses starting with 0x800000... will need to be * specified. Specifying a fixed address is not required on ppc64, i386 * or x86_64. */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/mman.h> #include <fcntl.h> #define LENGTH (256UL*1024*1024) #define PROTECTION (PROT_READ | PROT_WRITE) #ifndef MAP_HUGETLB #define MAP_HUGETLB 0x40000 /* arch specific */ #endif #ifndef MAP_HUGE_SHIFT #define MAP_HUGE_SHIFT 26 #endif #ifndef MAP_HUGE_MASK #define MAP_HUGE_MASK 0x3f #endif /* Only ia64 requires this */ #ifdef __ia64__ #define ADDR (void *)(0x8000000000000000UL) #define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_FIXED) #else #define ADDR (void *)(0x0UL) #define FLAGS (MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB) #endif static void check_bytes(char *addr) { printf("First hex is %x\n", *((unsigned int *)addr)); } static void write_bytes(char *addr) { unsigned long i; for (i = 0; i < LENGTH; i++) *(addr + i) = (char)i; } static int read_bytes(char *addr) { unsigned long i; check_bytes(addr); for (i = 0; i < LENGTH; i++) if (*(addr + i) != (char)i) { printf("Mismatch at %lu\n", i); return 1; } return 0; } int main(int argc, char **argv) { void *addr; int ret; size_t length = LENGTH; int flags = FLAGS; int shift = 0; if (argc > 1) length = atol(argv[1]) << 20; if (argc > 2) { shift = atoi(argv[2]); if (shift) flags |= (shift & MAP_HUGE_MASK) << MAP_HUGE_SHIFT; } if (shift) printf("%u kB hugepages\n", 1 << shift); else printf("Default size hugepages\n"); printf("Mapping %lu Mbytes\n", (unsigned long)length >> 20); addr = mmap(ADDR, length, PROTECTION, flags, -1, 0); if (addr == MAP_FAILED) { perror("mmap"); exit(1); } printf("Returned address is %p\n", addr); check_bytes(addr); write_bytes(addr); ret = read_bytes(addr); /* munmap() length of MAP_HUGETLB memory must be hugepage aligned */ if (munmap(addr, LENGTH)) { perror("munmap"); exit(1); } return ret; }
the_stack_data/918540.c
#include <stdio.h> int main(void) { int A = 8; float B = 3.14f; // 형식지정자 d or f ? 다른 것으로 강제로 선택하려면? printf("A + B = % \n", A + B); return 0; }
the_stack_data/811535.c
#include<stdio.h> #include<stdlib.h> typedef struct Node { int data; struct Node *next; } Node_t; Node_t *createList(Node_t *start); void displayList(Node_t *start); void countNodes(Node_t *start); void search(Node_t *start, int x); Node_t *insertAtBeginning(Node_t *start, int data); Node_t * insertAtEnd(Node_t *start, int data); void insertAfter(Node_t *start, int data, int x); Node_t *insertBefore(Node_t *start, int data, int x); Node_t *insertAtPosition(Node_t *start, int data, int index); Node_t *deleteNode(Node_t *start, int data); Node_t *reverseList(Node_t *start); void bubble_sort_xchg_data(Node_t *start); Node_t *bubble_sort_xchg_link(Node_t *start); Node_t *merge_sort(Node_t *start); Node_t *mid_node(Node_t *start); Node_t *divide(Node_t *start); Node_t *merge(Node_t *p1, Node_t *p2); Node_t *find_cycle(Node_t *start); void remove_cycle(Node_t *start, Node_t *intersect_node); int main() { Node_t *start = NULL; start = createList(start); displayList(start); #if 1 Node_t * p = start; while (p->next) { p = p->next; } p->next = start->next->next; #endif printf("Here is the result...\n"); Node_t *temp = find_cycle(start); if (temp) { printf("There is a cycle at %d...\n", temp->data); } else { printf("No cycle\n"); } printf("Now removing cycle...\n"); remove_cycle(start, temp); printf("Removal succesful...The latest list is...\n"); displayList(start); printf("\n"); return 0; } Node_t *createList(Node_t *start) { int i, n, data; printf("Enter the no.of nodes : "); scanf("%d", &n); if (n == 0) { return start; } printf("\nEnter the 1st element to insert : "); scanf("%d", &data); start = insertAtBeginning(start, data); for (i = 1; i < n; i++) { printf("\nEnter the next element to insert : "); scanf("%d", &data); insertAtEnd(start, data); } printf("\n"); return start; } void displayList(Node_t *start) { Node_t *temp; if (start == NULL) { printf("List is empty\n"); return; } for (temp = start; temp != NULL; temp = temp->next) { printf("%d ", temp->data); printf("--> "); } printf("NULL\n"); } void countNodes(Node_t *start) { int count = 0; Node_t *temp = start; while (temp) { count++; temp = temp->next; } printf("No.of nodes = %d\n", count); } void search(Node_t *start, int x) { int pos = 1; Node_t *temp = start; while (temp && temp->data != x) { pos++; temp = temp->next; } if (temp == NULL) { printf("%d not found\n", x); } else { printf("%d is at %d\n", x, pos); } } Node_t *insertAtBeginning(Node_t *start, int data) { Node_t *temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = start; start = temp; return start; } Node_t *insertAtEnd(Node_t *start, int data) { Node_t *temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = NULL; if (start == NULL) { start = temp; return start; } Node_t *p = start; while (p->next != NULL) { p = p->next; } p->next = temp; return start; } void insertAfter(Node_t *start, int data, int x) { Node_t *p = start; while (p) { if (p->data == x) { break; } p = p->next; } if (p == NULL) { printf("Node not found\n"); } else { Node_t *temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = p->next; p->next = temp; } } Node_t *insertBefore(Node_t *start, int data, int x) { Node_t *temp, *p; if (start == NULL) { printf("List is empty\n"); return start; } if (start->data == x) { temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = start; start = temp; return start; } p = start; while (p->next) { if (p->next->data == x) { break; } p = p->next; } if (p->next == NULL) { printf("Node not found\n"); } else { temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = p->next; p->next = temp; } return start; } Node_t *insertAtPosition(Node_t *start, int data, int index) { Node_t *temp, *p; int i; if (index == 1) { temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = start; start = temp; return start; } p = start; for (i = 1; i < (index - 1) && p != NULL; i++) { p = p->next; } if (p == NULL) { printf("Position not found\n"); } else { temp = (Node_t *)malloc(sizeof(Node_t)); temp->data = data; temp->next = p->next; p->next = temp; } return start; } Node_t *deleteNode(Node_t *start, int data) { Node_t *p, *del_node_ptr; if (start == NULL) { printf("Empty List\n"); return start; } if (start->data == data) { del_node_ptr = start; start = start->next; free(del_node_ptr); return start; } p = start; while (p->next) { if (p->next->data == data) { break; } p = p->next; } if (p->next == NULL) { printf("Node not found\n"); } else { del_node_ptr = p->next; p->next = del_node_ptr->next; free(del_node_ptr); } return start; } Node_t *reverseList(Node_t *start) { Node_t *addr, *p, *next_node; p = start; addr = NULL; while (p) { next_node = p->next; p->next = addr; addr = p; p = next_node; } start = addr; return start; } void bubble_sort_xchg_data(Node_t *start) { Node_t *p, *end; if (start == NULL) { return; } end = NULL; while (end != start->next) { p = start; while (p->next != end) { if (p->data > p->next->data) { int temp = p->data; p->data = p->next->data; p->next->data = temp; } p = p->next; } end = p; } } Node_t *bubble_sort_xchg_link(Node_t *start) { Node_t *p, *q, *r, *end, *temp; if (start == NULL) { return NULL; } end = NULL; while (end != start->next) { r = p = start; while (p->next != end) { q = p->next; if (p->data > q->data) { p->next = q->next; q->next = p; if (p != start) { r->next = q; } else { start = q; } temp = p; p = q; q = temp; } r = p; p = p->next; } end = p; } return start; } Node_t *mid_node(Node_t *start) { if (start == NULL) { return NULL; } Node_t *slow_ptr = start; Node_t *fast_ptr = start; while (fast_ptr && fast_ptr->next) { slow_ptr = slow_ptr->next; fast_ptr = fast_ptr->next->next; } return slow_ptr; } Node_t *divide(Node_t *start) { if (start == NULL) { return NULL; } Node_t *start2; Node_t *slow_ptr = start; Node_t *fast_ptr; if (start->next != NULL) { fast_ptr = start->next->next; } else { fast_ptr = start->next; } while (fast_ptr && fast_ptr->next) { slow_ptr = slow_ptr->next; fast_ptr = fast_ptr->next->next; } start2 = slow_ptr->next; slow_ptr->next = NULL; return start2; } Node_t *merge_sort(Node_t *start) { Node_t *mid; if (start==NULL || start->next == NULL) { return start; } mid = divide(start); start = merge_sort(start); mid = merge_sort(mid); return merge(start, mid); } Node_t *merge(Node_t *p1, Node_t *p2) { Node_t *start3, *p3; if (p1 == NULL && p2 == NULL){ return NULL; } if (p1 == NULL) { return p2; } if (p2 == NULL) { return p1; } if (p1->data <= p2->data) { p3 = p1; p1 = p1->next; } else { p3 = p2; p2 = p2->next; } start3 = p3; while (p1 && p2) { if (p1->data <= p2->data) { p3->next = p1; p3 = p1; p1 = p1->next; } else { p3->next = p2; p3 = p2; p2 = p2->next; } } if (p1 == NULL) { p3->next = p2; } else { p3->next = p1; } return start3; } Node_t *find_cycle(Node_t *start) { if (start == NULL || start->next == NULL) { return NULL; } Node_t *slow_ptr = start; Node_t *fast_ptr = start; while (fast_ptr && fast_ptr->next) { slow_ptr = slow_ptr->next; fast_ptr = fast_ptr->next->next; if (slow_ptr == fast_ptr) { return slow_ptr; } } return NULL; } void remove_cycle(Node_t *start, Node_t *intersect_node) { Node_t *p = intersect_node; Node_t *q = start; //Find out the starting node while (p != q) { p = p->next; q = q->next; } //Move to the actual last node while (q->next != p) { q = q->next; } q->next = NULL; }
the_stack_data/836273.c
#include <stdlib.h> #include "expat.h" const XML_LChar *XMLCALL XML_ErrorString_old_b026324c6904b2a(enum XML_Error code); void euf_main(){ #ifdef CBMC enum XML_Error code = nondet_int(); XML_LChar out = XML_ErrorString_old_b026324c6904b2a(code); XML_LChar out2 = XML_ErrorString_old_b026324c6904b2a(code); __CPROVER_assert(out == out2, "true"); #endif }
the_stack_data/87639237.c
#include <stdlib.h> extern int __VERIFIER_nondet_int(void); int gcd(int y1, int y2) { int* y1_ref = alloca(sizeof(int)); int* y2_ref = alloca(sizeof(int)); *y1_ref = y1; *y2_ref = y2; while (*y1_ref != *y2_ref) { if (*y1_ref > *y2_ref) { *y1_ref = *y1_ref - *y2_ref; } else { *y2_ref = *y2_ref - *y1_ref; } } return *y1_ref; } int main() { int y1 = __VERIFIER_nondet_int(); int y2 = __VERIFIER_nondet_int(); if (y1 >= 0 && y2 >= 0) { gcd(y1, y2); } return 0; }
the_stack_data/455274.c
/* * Generated with test/generate_buildtest.pl, to check that such a simple * program builds. */ #include <openssl/opensslconf.h> #ifndef OPENSSL_NO_STDIO # include <stdio.h> #endif #ifndef OPENSSL_NO_PKCS12 # include <openssl/pkcs12.h> #endif int main(void) { return 0; }
the_stack_data/159514571.c
#include <stdio.h> #include <string.h> int main() { char str[101]; scanf("%[^\n]s", str); printf("%s", strupr(str)); }
the_stack_data/13114.c
#include<stdlib.h> char * defangIPaddr(char * address) { int i=0,j=0; char *str; while(address[i]!='\0') i++; str=(char*)malloc(sizeof(char)*(i+7)); i=0; while(address[i]!='\0') { if(address[i]=='.') { str[j++]='['; str[j++]='.'; str[j++]=']'; } else str[j++]=address[i]; i++; } str[j]='\0'; return str; }
the_stack_data/34652.c
extern unsigned int __VERIFIER_nondet_uint(); extern void abort(void); void reach_error(){} unsigned int id(unsigned int x) { if (x==0) return 0; return id(x-1) + 1; } int main(void) { unsigned int input = __VERIFIER_nondet_uint(); unsigned int result = id(input); if (result == 20) { ERROR: {reach_error();abort();} } }
the_stack_data/54823948.c
/* * (c) Copyright 2015 by Einar Saukas. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * The name of its author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <stdio.h> #include <stdlib.h> #include <string.h> #define BUFFER_SIZE 16384 /* must be > MAX_OFFSET */ FILE *ifp; FILE *ofp; char *input_name; char *output_name; unsigned char *input_data; unsigned char *output_data; size_t input_index; size_t output_index; size_t input_size; size_t output_size; size_t partial_counter; int bit_mask; int bit_value; int read_byte() { if (input_index == partial_counter) { input_index = 0; partial_counter = fread(input_data, sizeof(char), BUFFER_SIZE, ifp); input_size += partial_counter; if (partial_counter == 0) { fprintf(stderr, (input_size ? "Error: Truncated input file %s\n" : "Error: Empty input file %s\n"), input_name); exit(1); } } return input_data[input_index++]; } int read_bit() { bit_mask >>= 1; if (bit_mask == 0) { bit_mask = 128; bit_value = read_byte(); } return bit_value & bit_mask ? 1 : 0; } int read_elias_gamma() { int i; int value; i = 0; while (!read_bit()) { i++; } if (i > 15) { return -1; } value = 1; while (i--) { value = value << 1 | read_bit(); } return value; } int read_offset() { int value; int i; value = read_byte(); if (value < 128) { return value; } else { i = read_bit(); i = i << 1 | read_bit(); i = i << 1 | read_bit(); i = i << 1 | read_bit(); return (value & 127 | i << 7) + 128; } } void save_output() { if (output_index != 0) { if (fwrite(output_data, sizeof(char), output_index, ofp) != output_index) { fprintf(stderr, "Error: Cannot write output file %s\n", output_name); exit(1); } output_size += output_index; output_index = 0; } } void write_byte(int value) { output_data[output_index++] = value; if (output_index == BUFFER_SIZE) { save_output(); } } void write_bytes(int offset, int length) { int i; if (offset > output_size+output_index) { fprintf(stderr, "Error: Invalid data in input file %s\n", input_name); exit(1); } while (length-- > 0) { i = output_index-offset; write_byte(output_data[i >= 0 ? i : BUFFER_SIZE+i]); } } void decompress() { int length; input_data = (unsigned char *)malloc(BUFFER_SIZE); output_data = (unsigned char *)malloc(BUFFER_SIZE); if (!input_data || !output_data) { fprintf(stderr, "Error: Insufficient memory\n"); exit(1); } input_size = 0; input_index = 0; partial_counter = 0; output_index = 0; output_size = 0; bit_mask = 0; write_byte(read_byte()); while (1) { if (!read_bit()) { write_byte(read_byte()); } else { length = read_elias_gamma()+1; if (length == 0) { save_output(); if (input_index != partial_counter) { fprintf(stderr, "Error: Input file %s too long\n", input_name); exit(1); } return; } write_bytes(read_offset()+1, length); } } } int main(int argc, char *argv[]) { /* determine output filename */ if (argc == 2) { input_name = argv[1]; input_size = strlen(input_name); if (input_size > 4 && !strcmp(input_name+input_size-4, ".zx7")) { output_name = (char *)malloc(input_size); strcpy(output_name, input_name); output_name[input_size-4] = '\0'; } else { fprintf(stderr, "Error: Cannot infer output filename\n"); exit(1); } } else if (argc == 3) { input_name = argv[1]; output_name = argv[2]; } else { fprintf(stderr, "Usage: %s input.zx7 [output]\n", argv[0]); exit(1); } /* open input file */ ifp = fopen(input_name, "rb"); if (!ifp) { fprintf(stderr, "Error: Cannot access input file %s\n", input_name); exit(1); } /* check output file */ if (fopen(output_name, "rb") != NULL) { fprintf(stderr, "Error: Already existing output file %s\n", output_name); exit(1); } /* create output file */ ofp = fopen(output_name, "wb"); if (!ofp) { fprintf(stderr, "Error: Cannot create output file %s\n", output_name); exit(1); } /* generate output file */ decompress(); /* close input file */ fclose(ifp); /* close output file */ fclose(ofp); /* done! */ printf("LZ77/LZSS decompression by Einar Saukas\nFile converted from %lu to %lu bytes!\n", (unsigned long)input_size, (unsigned long)output_size); return 0; }
the_stack_data/99208.c
typedef int __int32_t; typedef unsigned __uint32_t; typedef long long __int64_t; typedef unsigned long long __uint64_t; typedef __int32_t __psint_t; typedef __uint32_t __psunsigned_t; typedef __int32_t __scint_t; typedef __uint32_t __scunsigned_t; typedef unsigned int size_t; typedef long fpos_t; typedef __int64_t off64_t; typedef __int64_t fpos64_t; typedef char *va_list; typedef struct __file_s { int _cnt; unsigned char *_ptr; unsigned char *_base; unsigned char _flag; unsigned char _file; } FILE; extern FILE __iob[100 ]; extern FILE *_lastbuf; extern unsigned char *_bufendtab[]; extern unsigned char _sibuf[], _sobuf[]; extern int remove(const char *); extern int rename(const char *, const char *); extern FILE *tmpfile(void); extern char *tmpnam(char *); extern int fclose(FILE *); extern int fflush(FILE *); extern FILE *fopen(const char *, const char *); extern FILE *freopen(const char *, const char *, FILE *); extern void setbuf(FILE *, char *); extern int setvbuf(FILE *, char *, int, size_t); extern int fprintf(FILE *, const char *, ...); extern int fscanf(FILE *, const char *, ...); extern int printf(const char *, ...); extern int scanf(const char *, ...); extern int sprintf(char *, const char *, ...); extern int sscanf(const char *, const char *, ...); extern int vfprintf(FILE *, const char *, char *); extern int vprintf(const char *, char *); extern int vsprintf(char *, const char *, char *); extern int fgetc(FILE *); extern char *fgets(char *, int, FILE *); extern int fputc(int, FILE *); extern int fputs(const char *, FILE *); extern int getc(FILE *); extern int getchar(void); extern char *gets(char *); extern int putc(int, FILE *); extern int putchar(int); extern int puts(const char *); extern int ungetc(int, FILE *); extern size_t fread(void *, size_t, size_t, FILE *); extern size_t fwrite(const void *, size_t, size_t, FILE *); extern int fgetpos(FILE *, fpos_t *); extern int fseek(FILE *, long, int); extern int fsetpos(FILE *, const fpos_t *); extern long ftell(FILE *); extern void rewind(FILE *); extern void clearerr(FILE *); extern int feof(FILE *); extern int ferror(FILE *); extern void perror(const char *); extern int __filbuf(FILE *); extern int __flsbuf(int, FILE *); extern FILE *fdopen(int, const char *); extern int fileno(FILE *); extern void flockfile(FILE *); extern int ftrylockfile(FILE *); extern void funlockfile(FILE *); extern int getc_unlocked(FILE *); extern int putc_unlocked(int, FILE *); extern int getchar_unlocked(void); extern int putchar_unlocked(int); extern FILE *popen(const char *, const char *); extern int pclose(FILE *); extern int getopt(int, char *const *, const char *); extern char *optarg; extern int opterr; extern int optind; extern int optopt; extern int getsubopt(char **, char *const *, char **); extern void getoptreset(void); extern char *ctermid(char *); extern char *cuserid(char *); extern char *tempnam(const char *, const char *); extern int getw(FILE *); extern int putw(int, FILE *); extern char *mktemp(char *); extern int mkstemp(char *); extern int setbuffer(FILE *, char *, int); extern int setlinebuf(FILE *); extern int system(const char *); extern int fgetpos64(FILE *, fpos64_t *); extern FILE *fopen64(const char *, const char *); extern FILE *freopen64(const char *, const char *, FILE *); extern int fseek64(FILE *, off64_t, int); extern int fseeko64(FILE *, off64_t, int); extern int fseeko(FILE *, __int64_t, int); extern int fsetpos64(FILE *, const fpos64_t *); extern off64_t ftell64(FILE *); extern __int64_t ftello(FILE *); extern off64_t ftello64(FILE *); extern FILE *tmpfile64(void); extern int __semputc(int, FILE *); extern int __semgetc(FILE *); extern int __us_rsthread_stdio; extern char *ctermid_r(char *); main() { int c, i; i = 0; while((c = (__us_rsthread_stdio ? __semgetc((&__iob[0])) : (--((&__iob[0]))->_cnt < 0 ? __filbuf((&__iob[0])) : (int)*((&__iob[0]))->_ptr++)) ) != (-1) ) { if (++i > 100) { printf("\n"); i = 0; } if (c == '\n') i = 0; (__us_rsthread_stdio ? __semputc((c), (&__iob[1])) : (--( (&__iob[1]))->_cnt < 0 ? __flsbuf(((c)), ( (&__iob[1]))) : (int)(*( (&__iob[1]))->_ptr++ = (unsigned char)((c))))) ; } }
the_stack_data/3263797.c
/* --PROGRAM NAME: knkcch04e05.c --FLAGS: -std=c89 --PROGRAM STATEMENT: What is the value of each of the following expression in C89? (Give all possible values if an expression may have more than one value.) (a) 8%5 (b) -8%5 (c) 8%-5 (d) -8%-5 */ #include<stdio.h> //------------------------START OF MAIN()-------------------------------------- int main(void) { printf("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); printf("(a) 8%%5: %d",8%5); printf("\n(b) -8%%5: %d",-8%5); printf("\n(c) 8%%-5: %d",8%-5); printf("\n(d) -8%%-5: %d",-8%-5); printf("\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"); return 0; } //-------------------------END OF MAIN()--------------------------------------- //--------------------------------------------------------------------------- /* OUTPUT: ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ (a) 8%5: 3 (b) -8%5: -3 (c) 8%-5: 3 (d) -8%-5: -3 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ //---------------------------------------------------------------------------
the_stack_data/7287.c
#include <stdio.h> #include <string.h> int main(int argc, char const *argv[]) { int n, c, s1[105], s2[105], s[210]; char st[210]; scanf("%d", &n); for (int cases = 1; cases <= n; cases++){ scanf("%d", &c); while (getchar() != '\n') ; scanf("%s", st); for (int i = 0; i < c; i++) { s1[i] = st[i] - 'A'; } scanf("%s", st); for (int i = 0; i < c; i++) { s2[i] = st[i] - 'A'; } scanf("%s", st); int flag = 1; for (int i = 0; i < 100; i++) { for (int j = 0; j < c; j++) { s[2 * j] = s2[j]; s[2 * j + 1] = s1[j]; } int equal = 1; for (int j = 0; j < 2 * c; j++) { if (st[j] - 'A' != s[j]) equal = 0; //printf("%d ", s[j]); } //printf("\n"); for (int j = 0; j < c; j++) { s1[j] = s[j]; s2[j] = s[j + c]; } if (equal) { printf("%d %d\n", cases, i + 1); flag = 0; break; } } if (flag) printf("%d -1\n", cases); } return 0; }
the_stack_data/97013907.c
#include <stdio.h> #include <math.h> int main() { int number; printf("Enter a two-digit number: "); scanf("%2d", &number); int firstDigit = (number / 10) % 10; int secondDigit = (number) % 10; if (firstDigit == 1) { switch (secondDigit) { case 0: printf("Ten"); break; case 1: printf("Eleven"); break; case 2: printf("Twelve"); break; case 3: printf("Thirteen"); break; case 4: printf("Fourteen"); break; case 5: printf("Fifteen"); break; case 6: printf("Sixteen"); break; case 7: printf("Seventeen"); break; case 8: printf("Eighteen"); break; case 9: printf("Nineteen"); break; } printf("\n"); return 0; } switch (firstDigit) { case 2: printf("Twenty"); break; case 3: printf("Thirty"); break; case 4: printf("Fourty"); break; case 5: printf("Fifty"); break; case 6: printf("Sixty"); break; case 7: printf("Seventy"); break; case 8: printf("Eighty"); break; case 9: printf("Ninety"); break; } switch (secondDigit) { case 1: printf(" One"); break; case 2: printf(" Two"); break; case 3: printf(" Three"); break; case 4: printf(" Four"); break; case 5: printf(" Five"); break; case 6: printf(" Six"); break; case 7: printf(" Seven"); break; case 8: printf(" Eight"); break; case 9: printf(" Nine"); break; } printf("\n"); return 0; }
the_stack_data/211079390.c
#ifdef XLISP_ONLY long time_stamp; statfinit() { return(0); } statsymbols() { return(0); } set_function_docstring() { return(0); } #endif #define TRUE 1 #define FALSE 0 #ifdef NOGRAPHICS StHasWindows() { return(FALSE); } StScreenHasColor() { return(FALSE); } StInitGraphics() { return(0); } StGWGetCursRefCon() { return(0); } StGWSetCursRefCon() { return(0); } StGWSetColRefCon() { return(0); } StGWSetSymRefCon() { return(0); } #endif /* NOGRAPHICS */
the_stack_data/140765848.c
/* * ================================================================= * * Filename: ROT13.c * * Description: a simple ROT13 server with libevent * yank from * http://www.wangafu.net/~nickm/libevent-book/01_intro.html * as a good example of libevent * WARNING: compile in Cygwin,linker error. * in redhat 5.5 ok. * * Version: 1.0 * Created: 08/21/2012 9:21:01 PM * Revision: none * Compiler: gcc * * Author: liuyang1 (liuy), [email protected] * Company: auto@ustc * * ================================================================= */ #include <netinet/in.h> #include <sys/socket.h> #include <fcntl.h> #include <event2/event.h> #include <event2/buffer.h> #include <event2/bufferevent.h> #include <assert.h> #include <unistd.h> #include <string.h> #include <stdlib.h> #include <stdio.h> #include <errno.h> #define MAX_LINE 16384 void do_read(evutil_socket_t fd,short events,void *arg); void do_write(evutil_socket_t fd,short events,void *arg); char rot13_char(char c){ if((c>='a'&&c<='m') || (c>='A'&&c<='M')) return c+13; else if((c>='n'&&c<='z') || (c>='N'&&c<='Z')) return c-13; else return c; } void readcb(struct bufferevent *bev,void *ctx) { struct evbuffer *input,*output; char *line; size_t n; int i; input = bufferevent_get_input(bev); output = bufferevent_get_output(bev); while((line = evbuffer_readln(input,&n,EVBUFFER_EOL_LF))){ for(i=0;i<n;i++){ line[i] = rot13_char(line[i]); } evbuffer_add(output,line,n); evbuffer_add(output,"\n",1); free(line); } if(evbuffer_get_length(input)>=MAX_LINE){ char buf[1024]; while(evbuffer_get_length(input)){ int n=evbuffer_remove(input,buf,sizeof(buf)); for(i=0;i<n;i++) buf[i] = rot13_char(buf[i]); evbuffer_add(output,buf,n); } evbuffer_add(output,"\n",1); } } void errorcb(struct bufferevent *bev,short error,void *ctx) { if(error & BEV_EVENT_EOF){ // connection has been closed,do any clean up here }else if(error & BEV_EVENT_ERROR){ // check errno to see waht error occurred }else if(error & BEV_EVENT_TIMEOUT){ // must be a timeout event handler,handle iterator } bufferevent_free(bev); } void do_accept(evutil_socket_t listener,short event,void *arg) { struct event_base *base = arg; struct sockaddr_storage ss; socklen_t slen = sizeof(ss); int fd = accept(listener,(struct sockaddr*)&ss,&slen); if(fd<0){ perror("accept"); }else if(fd>FD_SETSIZE){ close(fd); }else{ struct bufferevent *bev; evutil_make_socket_nonblocking(fd); bev = bufferevent_socket_new(base,fd,BEV_OPT_CLOSE_ON_FREE); bufferevent_setcb(bev,readcb,NULL,errorcb,NULL); bufferevent_setwatermark(bev,EV_READ,0,MAX_LINE); bufferevent_enable(bev,EV_READ|EV_WRITE); } } void run(void){ evutil_socket_t listener; struct sockaddr_in sin; struct event_base *base; struct event *listener_event; base = event_base_new(); if(!base) return; sin.sin_family = AF_INET; sin.sin_addr.s_addr = 0; sin.sin_port = htons(40713); listener = socket(AF_INET,SOCK_STREAM,0); evutil_make_socket_nonblocking(listener); #ifndef WIN32 { int one = 1; setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one)); } #endif if(bind(listener,(struct sockaddr*)&sin,sizeof(sin))<0){ perror("bind"); return; } if(listen(listener,16)<0){ perror("listen"); return; } listener_event = event_new(base,listener,EV_READ|EV_PERSIST,do_accept,(void*)base); event_add(listener_event,NULL); event_base_dispatch(base); } int main(int c,char **v){ setvbuf(stdout,NULL,_IONBF,0); run(); return 0; }
the_stack_data/358967.c
// UBSAN: shift-out-of-bounds in netlink_recvmsg // https://syzkaller.appspot.com/bug?id=cdb35bcbfac5f493e2af // status:0 // autogenerated by syzkaller (https://github.com/google/syzkaller) #define _GNU_SOURCE #include <endian.h> #include <errno.h> #include <pthread.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/syscall.h> #include <sys/types.h> #include <time.h> #include <unistd.h> #include <linux/futex.h> static void sleep_ms(uint64_t ms) { usleep(ms * 1000); } static uint64_t current_time_ms(void) { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts)) exit(1); return (uint64_t)ts.tv_sec * 1000 + (uint64_t)ts.tv_nsec / 1000000; } static void thread_start(void* (*fn)(void*), void* arg) { pthread_t th; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 128 << 10); int i = 0; for (; i < 100; i++) { if (pthread_create(&th, &attr, fn, arg) == 0) { pthread_attr_destroy(&attr); return; } if (errno == EAGAIN) { usleep(50); continue; } break; } exit(1); } typedef struct { int state; } event_t; static void event_init(event_t* ev) { ev->state = 0; } static void event_reset(event_t* ev) { ev->state = 0; } static void event_set(event_t* ev) { if (ev->state) exit(1); __atomic_store_n(&ev->state, 1, __ATOMIC_RELEASE); syscall(SYS_futex, &ev->state, FUTEX_WAKE | FUTEX_PRIVATE_FLAG, 1000000); } static void event_wait(event_t* ev) { while (!__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, 0); } static int event_isset(event_t* ev) { return __atomic_load_n(&ev->state, __ATOMIC_ACQUIRE); } static int event_timedwait(event_t* ev, uint64_t timeout) { uint64_t start = current_time_ms(); uint64_t now = start; for (;;) { uint64_t remain = timeout - (now - start); struct timespec ts; ts.tv_sec = remain / 1000; ts.tv_nsec = (remain % 1000) * 1000 * 1000; syscall(SYS_futex, &ev->state, FUTEX_WAIT | FUTEX_PRIVATE_FLAG, 0, &ts); if (__atomic_load_n(&ev->state, __ATOMIC_ACQUIRE)) return 1; now = current_time_ms(); if (now - start > timeout) return 0; } } struct thread_t { int created, call; event_t ready, done; }; static struct thread_t threads[16]; static void execute_call(int call); static int running; static void* thr(void* arg) { struct thread_t* th = (struct thread_t*)arg; for (;;) { event_wait(&th->ready); event_reset(&th->ready); execute_call(th->call); __atomic_fetch_sub(&running, 1, __ATOMIC_RELAXED); event_set(&th->done); } return 0; } static void loop(void) { int i, call, thread; for (call = 0; call < 3; call++) { for (thread = 0; thread < (int)(sizeof(threads) / sizeof(threads[0])); thread++) { struct thread_t* th = &threads[thread]; if (!th->created) { th->created = 1; event_init(&th->ready); event_init(&th->done); event_set(&th->done); thread_start(thr, th); } if (!event_isset(&th->done)) continue; event_reset(&th->done); th->call = call; __atomic_fetch_add(&running, 1, __ATOMIC_RELAXED); event_set(&th->ready); event_timedwait(&th->done, 50); break; } } for (i = 0; i < 100 && __atomic_load_n(&running, __ATOMIC_RELAXED); i++) sleep_ms(1); } uint64_t r[1] = {0xffffffffffffffff}; void execute_call(int call) { intptr_t res = 0; switch (call) { case 0: res = syscall(__NR_socket, 0x10ul, 2ul, 0x10); if (res != -1) r[0] = res; break; case 1: *(uint64_t*)0x20000440 = 0; *(uint32_t*)0x20000448 = 0; *(uint64_t*)0x20000450 = 0; *(uint64_t*)0x20000458 = 0; *(uint64_t*)0x20000460 = 0; *(uint64_t*)0x20000468 = 0; *(uint32_t*)0x20000470 = 0; syscall(__NR_recvmsg, r[0], 0x20000440ul, 2ul, 0); break; case 2: *(uint64_t*)0x20000180 = 0; *(uint32_t*)0x20000188 = 0x4c; *(uint64_t*)0x20000190 = 0x20000080; *(uint64_t*)0x20000080 = 0x200000c0; memcpy((void*)0x200000c0, "\x2e\x00\x00\x00\x37\x00\x09\x11\xd2\x43\x80\x64\x8c\x63\x94\x0d" "\x01\x35\xfc\x60\x06\x00\x12\x40\x0c\x00\x02\x00\x02\x00\x00\x00" "\x37\x15\x3e\x37\x0a\x00\x01\x80\x5a\x25\x64\x00\xd1\xbd", 46); *(uint64_t*)0x20000088 = 0x2e; *(uint64_t*)0x20000198 = 1; *(uint64_t*)0x200001a0 = 0; *(uint64_t*)0x200001a8 = 0; *(uint32_t*)0x200001b0 = 0; syscall(__NR_sendmsg, r[0], 0x20000180ul, 0ul); break; } } int main(void) { syscall(__NR_mmap, 0x1ffff000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x20000000ul, 0x1000000ul, 7ul, 0x32ul, -1, 0ul); syscall(__NR_mmap, 0x21000000ul, 0x1000ul, 0ul, 0x32ul, -1, 0ul); loop(); return 0; }
the_stack_data/98180.c
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<unistd.h> int shell_echo(char * args[]) { if (args[1]==NULL) { printf("\n"); return 1; } else { int i=1; while(args[i]!="") { write(1, args[i], strlen(args[i])); write(1," ",1); i++; } write(1,"\n",1); } } int main() { char * arr[]={"echo","a","b","c","d",""}; shell_echo(arr); char * arr1[]={"echo"}; shell_echo(arr1); }
the_stack_data/154829412.c
/* grab-replacement.c, part of XGrabControl. (c) 2011, en passant development. */ #include <sys/types.h> #include <X11/Xlib.h> int XGrabKeyboard(Display *display, Window grab_window, Bool owner_events, int pointer_mode, int keyboard_mode, Time time) { (void) display; (void) grab_window; (void) owner_events; (void) pointer_mode; (void) keyboard_mode; (void) time; return GrabSuccess; } /* int XGrabPointer(Display *display, Window grab_window, Bool owner_events, unsigned int event_mask, int pointer_mode, int keyboard_mode, Window confine_to, Cursor cursor, Time time) { (void) display; (void) grab_window; (void) owner_events; (void) event_mask; (void) pointer_mode; (void) keyboard_mode; (void) confine_to; (void) cursor; (void) time; return GrabSuccess; } int XChangeActivePointerGrab(Display *display, unsigned int event_mask, Cursor cursor, Time time) { (void) display; (void) event_mask; (void) cursor; (void) time; return GrabSuccess; } */
the_stack_data/1110062.c
// To find out the factorial upto 20 #include<stdio.h> int main(){ long long int i, n, factorial=1; printf("Enter the value which you want to find Factorial : "); scanf("%ld",&n); if(n>=1) for(i=1;i<=n;i++){ factorial *=i; } printf("Factorial of %ld no is = %lld", n, factorial); return factorial; //return (factorial) is shows the factorial value }
the_stack_data/86344.c
#include <stdio.h> #include <stdlib.h> #define WHITE 0 #define GRAY 1 // PENSO VADA BENE (non ho fatto abbastanza test ma sono confident) /* Classificare gli archi di un grafo indiretto. */ typedef struct _edges { int degree; int *adj; } edges; typedef edges* graph; graph read_graph(int N) { graph G = (graph) malloc(sizeof(edges) * N); for(int i = 0; i < N; i++) { scanf("%d", &G[i].degree); G[i].adj = (int*) malloc(sizeof(int) * G[i].degree); for(int j = 0; j < G[i].degree; j++) scanf("%d", &G[i].adj[j]); } return G; } void dfs_visit_classification(graph G, int src, int *colours, int *pi) { colours[src] = GRAY; int dest; // dest = v, src = u for(int i = 0; i < G[src].degree; i++) // for all v ∈ Adj[u] { dest = G[src].adj[i]; if(colours[dest] == WHITE) { pi[dest] = src; printf("(%d,%d) arco d'albero\n", src, dest); dfs_visit_classification(G, dest, colours, pi); } else if(colours[dest] == GRAY) if(pi[src] != dest) printf("(%d,%d) arco all'indietro\n", src, dest); else printf("(%d,%d) arco d'albero\n", src, dest); } } void dfs_cormen(graph G, int N, int src) { int *colours = malloc(N * sizeof(int)), *pi = malloc(N * sizeof(int)); for(int i = 0; i < N; i++) { colours[i] = WHITE; pi[i] = -1; } for(int i = 0; i < N; i++) if(colours[i] == WHITE) dfs_visit_classification(G, src, colours, pi); free(pi); free(colours); } void delete_graph(graph G, int N) { for(int i = 0; i < N; i++) free(G[i].adj); free(G); } int main() { int N; graph G; scanf("%d", &N); G = read_graph(N); dfs_cormen(G, N, 0); delete_graph(G, N); return 0; }
the_stack_data/9513478.c
/*BEGIN_LEGAL Intel Open Source License Copyright (c) 2002-2014 Intel Corporation. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the Intel Corporation nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. END_LEGAL */ /* * this application calls a user-written function that contains a bad code pattern. */ #include <stdio.h> #include <stdlib.h> #include <string.h> extern void high_target(); int main( int argc, char * argv[] ) { char * buffer; buffer = (char *)malloc( 64 ); strcpy( buffer, "abc" ); printf("%s\n", buffer ); high_target(); printf("returned from high_target.\n"); free( buffer ); return 0; }
the_stack_data/660730.c
#include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <errno.h> #include <stdlib.h> //自定义的错误处理函数 void my_err(const char *str , int line) { fprintf(stderr,"line:%d",line); perror(str); exit(1); } //数据读取函数 int my_read(int fd) { int len;//获取文件长度 char read_buf[3000]; int i; int ret; if(lseek(fd,0,SEEK_END) == -1) my_err("lseek",__LINE__); if((len = lseek(fd,0,SEEK_CUR)) == -1) my_err("lseek",__LINE__); if(lseek(fd,0,SEEK_SET) == -1) my_err("lseek",__LINE__); printf("len:%d\n",len); //读数据 if((ret = read(fd,read_buf,len)) < 0) my_err("read",__LINE__); //打印数据 for(i=0;i<len;i++) printf("%c",read_buf[i]); printf("\n"); return ret; } int main() { int fd; if((fd = open("../Plan/文件操作.txt",O_RDONLY)) < 0) my_err("open",__LINE__); my_read(fd); return 0; }
the_stack_data/14199881.c
#include<stdio.h> int main() { //complete this }
the_stack_data/66602.c
/** *Name: Minhas Kamal (IIT, DU) *Date:24.Feb.2013 **/ #include <stdio.h> int main() { int a, b; printf("Enter first serial num: "); scanf("%d", &a); printf("Enter second serial num: "); scanf("%d", &b); int m, n; for (m = a; m <= b; m++) { long long int x = 0, y = 1, z; for (n = 1; n < m; n++) { z = y; y = x + y; x = z; } if (x < 0) { printf("...\n...\nCannot calculate more!\n...\n...\n"); return 0; } else printf("%dth num is: %lld\n", m, x); } return 0; }
the_stack_data/187644463.c
#include <stdio.h> #include <stdlib.h> int in_int() { long i; char* c = (char*)calloc(4096, 1); fgets(c, 4096, stdin); // Return 0 on bad input if (sscanf(c, "%ld", &i) != 1) return 0; if (i > 2147483647 || i < -2147483648) return 0; return i; } void out_int(int i) { printf("%d", i); } char* in_string() { char* c = (char*)calloc(4096, 1); fgets(c, 4096, stdin); return c; } void out_string(char* c) { printf("%s", c); } int main(int argc, char** argv) { int i = in_int(); out_int(i); //printf("\n"); char* c = in_string(); out_string(c); return 0; }
the_stack_data/25138814.c
// RUN: clang-cc -emit-llvm -o - // PR4610 #pragma pack(4) struct ref { struct ref *next; } refs;
the_stack_data/41144.c
#include <stdio.h> int key() { return(getc(stdin)); } int key_avail() { return 0; } int ansi_emit(int c, FILE *fd) { return -1; }
the_stack_data/76699881.c
int MAIN_FUNCTION_f2(); int main(){ return !(MAIN_FUNCTION_f2() == 10); /*exit code 0 means success */ }
the_stack_data/111077183.c
#include "stdlib.h" #include "malloc.h" typedef void thread_run/*@(predicate(void *) pre, predicate() post)@*/(void *data); //@ requires pre(data); //@ ensures post(); struct thread; //@ predicate thread(struct thread *thread, predicate() post); struct thread *thread_start(void *run, void *data); //@ requires [_]is_thread_run(run, ?pre, ?post) &*& pre(data); //@ ensures thread(result, post); void thread_join(struct thread *thread); //@ requires thread(thread, ?post); //@ ensures post(); void increment(int *cell) //@ requires integer(cell, ?value); //@ ensures integer(cell, value + 1); { (*cell)++; } //@ predicate_ctor integer1(int *cell, int value)(int *cell1) = integer(cell, value) &*& cell1 == cell; //@ predicate_ctor integer2(int *cell, int value)() = integer(cell, value); int read_int(); //@ requires true; //@ ensures true; int main() //@ requires true; //@ ensures true; { int *cell = malloc(sizeof(int)); if (cell == 0) abort(); int n = read_int(); *cell = n; /*@ produce_function_pointer_chunk thread_run(increment)(integer1(cell, n), integer2(cell, n + 1))(data) { open integer1(cell, n)(data); call(); close integer2(cell, n + 1)(); } @*/ //@ close integer1(cell, n)(cell); struct thread *t = thread_start(increment, cell); thread_join(t); //@ open integer2(cell, n + 1)(); int n1 = *cell; free(cell); assert(n1 == n + 1); return 0; }
the_stack_data/168893702.c
int EXPRESSION(int, int); int nondet_int(); int main() { int in=nondet_int(), out; out=EXPRESSION(in, 0); __CPROVER_assert(out==in+in, ""); return 0; }
the_stack_data/566813.c
/* (c) 2018 Doug Rogers under Zero Clause BSD License. See LICENSE.txt. */ /* You are free to do whatever you want with this software. Have at it! */ /* * Read lines in pwned-password format from stdin and write them in binary to * stdout. */ #include <assert.h> #include <stdio.h> #include <stdint.h> #include <unistd.h> struct { unsigned char sha[20]; uint32_t count; } line = { "", 0 }; int hex_val(char c) { if (('0' <= c) && (c <= '9')) return c - '0'; if (('A' <= c) && (c <= 'F')) return 10 + c - 'A'; if (('a' <= c) && (c <= 'f')) return 10 + c - 'a'; return -1; } int get_hex_byte(unsigned char* b) { int b1 = hex_val(getchar()); int b0 = hex_val(getchar()); if ((b1 < 0) || (b0 < 0)) return 0; *b = 16 * b1 + b0; return 1; } int copy_line(void) { for (int k = 0; k < 20; ++k) { if (!get_hex_byte(&line.sha[k])) { return 0; } } if (getchar() != ':') return 0; unsigned int count = 0; if (1 != fscanf(stdin, "%u", &count)) { return 0; } line.count = (uint32_t) count; write(1, &line, sizeof(line)); while (getchar() == ' ') ; getchar(); return 1; } int main(int argc, char* argv[]) { assert(sizeof(line) == 24); while (copy_line()) ; return 0; }
the_stack_data/48575671.c
/* * calculate ecc code for nand flash * * Copyright (C) 2008 yajin <[email protected]> * Copyright (C) 2009 Felix Fietkau <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 or * (at your option) version 3 of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <stdlib.h> #include <stdint.h> #include <fcntl.h> #include <stdio.h> #define DEF_NAND_PAGE_SIZE 2048 #define DEF_NAND_OOB_SIZE 64 #define DEF_NAND_ECC_OFFSET 0x28 static int page_size = DEF_NAND_PAGE_SIZE; static int oob_size = DEF_NAND_OOB_SIZE; static int ecc_offset = DEF_NAND_ECC_OFFSET; /* * Pre-calculated 256-way 1 byte column parity */ static const uint8_t nand_ecc_precalc_table[] = { 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00, 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, 0x6a, 0x3f, 0x3c, 0x69, 0x33, 0x66, 0x65, 0x30, 0x30, 0x65, 0x66, 0x33, 0x69, 0x3c, 0x3f, 0x6a, 0x0f, 0x5a, 0x59, 0x0c, 0x56, 0x03, 0x00, 0x55, 0x55, 0x00, 0x03, 0x56, 0x0c, 0x59, 0x5a, 0x0f, 0x0c, 0x59, 0x5a, 0x0f, 0x55, 0x00, 0x03, 0x56, 0x56, 0x03, 0x00, 0x55, 0x0f, 0x5a, 0x59, 0x0c, 0x69, 0x3c, 0x3f, 0x6a, 0x30, 0x65, 0x66, 0x33, 0x33, 0x66, 0x65, 0x30, 0x6a, 0x3f, 0x3c, 0x69, 0x03, 0x56, 0x55, 0x00, 0x5a, 0x0f, 0x0c, 0x59, 0x59, 0x0c, 0x0f, 0x5a, 0x00, 0x55, 0x56, 0x03, 0x66, 0x33, 0x30, 0x65, 0x3f, 0x6a, 0x69, 0x3c, 0x3c, 0x69, 0x6a, 0x3f, 0x65, 0x30, 0x33, 0x66, 0x65, 0x30, 0x33, 0x66, 0x3c, 0x69, 0x6a, 0x3f, 0x3f, 0x6a, 0x69, 0x3c, 0x66, 0x33, 0x30, 0x65, 0x00, 0x55, 0x56, 0x03, 0x59, 0x0c, 0x0f, 0x5a, 0x5a, 0x0f, 0x0c, 0x59, 0x03, 0x56, 0x55, 0x00 }; /** * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256-byte block * @dat: raw data * @ecc_code: buffer for ECC */ int nand_calculate_ecc(const uint8_t *dat, uint8_t *ecc_code) { uint8_t idx, reg1, reg2, reg3, tmp1, tmp2; int i; /* Initialize variables */ reg1 = reg2 = reg3 = 0; /* Build up column parity */ for(i = 0; i < 256; i++) { /* Get CP0 - CP5 from table */ idx = nand_ecc_precalc_table[*dat++]; reg1 ^= (idx & 0x3f); /* All bit XOR = 1 ? */ if (idx & 0x40) { reg3 ^= (uint8_t) i; reg2 ^= ~((uint8_t) i); } } /* Create non-inverted ECC code from line parity */ tmp1 = (reg3 & 0x80) >> 0; /* B7 -> B7 */ tmp1 |= (reg2 & 0x80) >> 1; /* B7 -> B6 */ tmp1 |= (reg3 & 0x40) >> 1; /* B6 -> B5 */ tmp1 |= (reg2 & 0x40) >> 2; /* B6 -> B4 */ tmp1 |= (reg3 & 0x20) >> 2; /* B5 -> B3 */ tmp1 |= (reg2 & 0x20) >> 3; /* B5 -> B2 */ tmp1 |= (reg3 & 0x10) >> 3; /* B4 -> B1 */ tmp1 |= (reg2 & 0x10) >> 4; /* B4 -> B0 */ tmp2 = (reg3 & 0x08) << 4; /* B3 -> B7 */ tmp2 |= (reg2 & 0x08) << 3; /* B3 -> B6 */ tmp2 |= (reg3 & 0x04) << 3; /* B2 -> B5 */ tmp2 |= (reg2 & 0x04) << 2; /* B2 -> B4 */ tmp2 |= (reg3 & 0x02) << 2; /* B1 -> B3 */ tmp2 |= (reg2 & 0x02) << 1; /* B1 -> B2 */ tmp2 |= (reg3 & 0x01) << 1; /* B0 -> B1 */ tmp2 |= (reg2 & 0x01) << 0; /* B7 -> B0 */ /* Calculate final ECC code */ #ifdef CONFIG_MTD_NAND_ECC_SMC ecc_code[0] = ~tmp2; ecc_code[1] = ~tmp1; #else ecc_code[0] = ~tmp1; ecc_code[1] = ~tmp2; #endif ecc_code[2] = ((~reg1) << 2) | 0x03; return 0; } /* * usage: bb-nandflash-ecc start_address size */ void usage(const char *prog) { fprintf(stderr, "Usage: %s [options] <input> <output>\n" "Options:\n" " -p <pagesize> NAND page size (default: %d)\n" " -o <oobsize> NAND OOB size (default: %d)\n" " -e <offset> NAND ECC offset (default: %d)\n" "\n", prog, DEF_NAND_PAGE_SIZE, DEF_NAND_OOB_SIZE, DEF_NAND_ECC_OFFSET); exit(1); } /*start_address/size does not include oob */ int main(int argc, char **argv) { uint8_t *page_data = NULL; uint8_t *ecc_data; int infd = -1, outfd = -1; int ret = 1; ssize_t bytes; int ch; while ((ch = getopt(argc, argv, "e:o:p:")) != -1) { switch(ch) { case 'p': page_size = strtoul(optarg, NULL, 0); break; case 'o': oob_size = strtoul(optarg, NULL, 0); break; case 'e': ecc_offset = strtoul(optarg, NULL, 0); break; default: usage(argv[0]); } } argc -= optind; if (argc < 2) usage(argv[0]); argv += optind; infd = open(argv[0], O_RDONLY, 0); if (infd < 0) { perror("open input file"); goto out; } outfd = open(argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0644); if (outfd < 0) { perror("open output file"); goto out; } page_data = malloc(page_size + oob_size); while ((bytes = read(infd, page_data, page_size)) == page_size) { int j; ecc_data = page_data + page_size + ecc_offset; for (j = 0; j < page_size / 256; j++) { nand_calculate_ecc(page_data + j * 256, ecc_data); ecc_data += 3; } write(outfd, page_data, page_size + oob_size); } ret = 0; out: if (infd >= 0) close(infd); if (outfd >= 0) close(outfd); if (page_data) free(page_data); return ret; }
the_stack_data/90765572.c
//{{BLOCK(map1) //====================================================================== // // map1, 512x256@4, // + palette 32 entries, not compressed // + 37 tiles (t|f|p reduced) not compressed // + regular map (in SBBs), not compressed, 64x32 // Total size: 64 + 1184 + 4096 = 5344 // // Time-stamp: 2021-11-17, 19:28:33 // Exported by Cearn's GBA Image Transmogrifier, v0.8.3 // ( http://www.coranac.com/projects/#grit ) // //====================================================================== const unsigned short map1Tiles[592] __attribute__((aligned(4)))= { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x9999,0x9999,0x9999,0x0000,0x0999,0xAAAA,0xA099,0xAAAA, 0xA099,0xAAAA,0xA099,0xAAAA,0x0099,0x0000,0x9909,0x9999, 0x0009,0x0000,0x8809,0x8888,0x0009,0x0000,0x3309,0x3333, 0xA099,0x33A3,0xA099,0xAAAA,0x0999,0x0000,0x9999,0x9999, 0x0000,0x9000,0x8888,0x9088,0x0000,0x9000,0x3333,0x9033, 0xA3AA,0x9903,0xAAAA,0x990A,0x0000,0x9990,0x9999,0x9999, 0x9999,0x9999,0x9999,0x9999,0x9999,0x9999,0x9999,0x9999, 0x9999,0x9999,0x9999,0x9999,0x9999,0x1111,0x9999,0x4471, 0x9999,0x9999,0x9999,0x9999,0x9999,0x9999,0x9999,0x9999, 0x9999,0x9999,0x9999,0x9999,0x1111,0x9991,0x4444,0x9991, 0x9999,0x4471,0x9999,0x1471,0x9999,0x1471,0x9999,0x7A71, 0x9999,0xAA71,0x9999,0x1771,0x9999,0x1711,0x9999,0x1119, 0x4444,0x9991,0x1441,0x9991,0x1441,0x9911,0x7447,0x991A, 0xA444,0x991A,0x7711,0x9991,0x7119,0x9991,0x1199,0x9991, 0xAAAA,0xAAAA,0x6666,0x6666,0x4664,0x64A6,0x1A61,0x6144, 0x1441,0x4111,0xBB11,0x1111,0x7BB1,0xBB1B,0xBBB1,0x7BBB, 0xAAAA,0xAAAA,0x6666,0x6666,0x4466,0x4A66,0x11A6,0x1444, 0x1144,0x1111,0xB111,0x11BB,0xBB11,0x1B77,0xBB1B,0x1B77, 0xAAAA,0xAAAA,0x6666,0x6666,0x4664,0x44A6,0x1A61,0x1144, 0x1441,0x1111,0x1111,0x1111,0x1BB1,0xBB11,0xB7BB,0x7BB1, 0xAAAA,0xAAAA,0x6666,0xAA66,0x6666,0xA666,0x44A6,0xA666, 0x1144,0xA66A,0x1111,0xA644,0x111B,0xA611,0x11B7,0xA66A, 0xAAAA,0xAAAA,0x66AA,0x6666,0x666A,0x6666,0x666A,0xA644, 0xA66A,0x4411,0x446A,0x1111,0x116A,0xB111,0xA66A,0xBB11, 0xAAAA,0xAAAA,0x6666,0x6666,0xA644,0x4664,0x4411,0x1A61, 0x1111,0x1441,0x1111,0x1111,0x11BB,0x1BB1,0x1B77,0xB7BB, 0xBB11,0xBBB1,0x1111,0xBB11,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0xBB1B,0x1BBB,0xB111,0x11BB,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0xBBBB,0x7BB1,0x1BB1,0xBBB1,0x1111,0xBB11,0x1111,0xB111, 0x1111,0xBB11,0x1111,0xBB11,0x1111,0xB111,0x1111,0x1111, 0x11B7,0xA666,0x11BB,0xA644,0xA11B,0xA666,0x611B,0xA666, 0x41B7,0xA644,0x11BB,0xA611,0x111B,0xA66A,0x1111,0xA666, 0x666A,0xBB11,0x446A,0xBB11,0x666A,0xB11A,0x666A,0xB116, 0x446A,0xBB14,0x116A,0xBB11,0xA66A,0xB111,0x666A,0x1111, 0x1B77,0xBBBB,0x1BBB,0x1BB1,0x11BB,0x1111,0x111B,0x1111, 0x11B7,0x1111,0x11BB,0x1111,0x111B,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0xBB11,0x1111,0x7BB1,0x1111,0xBBB1,0x1111,0xBB11, 0x1111,0x1111,0x1111,0xB111,0x1111,0xBB11,0x1111,0xBB11, 0x1111,0xA644,0xA11B,0xA666,0x611B,0xA666,0x4111,0xA644, 0x1111,0xA66A,0x11BB,0xA666,0x1B77,0xA644,0x1B77,0xA611, 0x446A,0x1111,0x666A,0xB11A,0x666A,0xB116,0x446A,0x1114, 0xA66A,0x1111,0x666A,0xBB11,0x446A,0x7BB1,0x116A,0x7BB1, 0x11BB,0x1111,0x1B7B,0x1111,0x1BBB,0x1111,0x11BB,0x1111, 0x1111,0x1111,0x111B,0x1111,0x11B7,0x1111,0x11B7,0x1111, 0x1111,0xBB11,0x1111,0xB111,0x1111,0x1111,0x1111,0xB111, 0x1111,0xBB11,0x1111,0xBB11,0x1111,0xB111,0x1111,0x1111, 0x1BBB,0xA66A,0x11BB,0xA666,0x1111,0xA644,0xA11B,0xA666, 0x61B7,0xA666,0x61BB,0xA666,0x411B,0xA644,0x1111,0xA611, 0xA66A,0xBBB1,0x666A,0xBB11,0x446A,0x1111,0x666A,0xB11A, 0x666A,0xBB16,0x666A,0xBB16,0x446A,0xB114,0x116A,0x1111, 0x11BB,0x1111,0x111B,0x1111,0x1111,0x1111,0x111B,0x1111, 0x11B7,0x1111,0x11BB,0x1111,0x111B,0x1111,0x1111,0x1111, 0xAAAA,0xAAAA,0x6666,0x6666,0x4664,0x64A6,0x1A61,0x6144, 0x1441,0x4111,0x1111,0x1111,0x1BBB,0x1BB1,0xB77B,0xB7BB, 0xAAAA,0xAAAA,0x6666,0x6666,0x4466,0x4A66,0x11A6,0x1444, 0x1144,0x1111,0x1111,0x1111,0xBB11,0x111B,0x7BB1,0x11B7, 0x666A,0xBB11,0x446A,0xBB11,0x116A,0xBBB1,0x1144,0xB77B, 0xBB15,0x177B,0x7BBB,0xBBBB,0xBBBB,0xBBBB,0xBB72,0x1111, 0x1B77,0xBBBB,0x1BBB,0x1BB1,0x11BB,0x1111,0x1111,0x1111, 0x11BB,0x11BB,0xBB7B,0xBB7B,0xBBBB,0xBBBB,0x11BB,0x11BB, 0xB77B,0xBBBB,0xBBBB,0x1BB1,0x1BB1,0x1111,0x1111,0x1111, 0x1BBB,0x11BB,0xBB7B,0xBB7B,0xBBBB,0xBBBB,0x1BBB,0x11BB, 0x7BB1,0x11B7,0xBBB1,0x11BB,0xBB11,0x111B,0x1111,0x1111, 0x11BB,0x11BB,0xBB7B,0xBB7B,0xBBBB,0xBBBB,0x11BB,0x11BB, 0xBBBB,0x7BB1,0x1BB1,0xBBB1,0x1111,0xBB11,0x1111,0x1111, 0x11BB,0x11BB,0xBB7B,0xBB7B,0xBBBB,0xBBBB,0x11BB,0x11BB, 0x11B7,0xA666,0x11BB,0xA644,0xBB1B,0xA611,0x77B1,0x441B, 0x77BB,0x51BB,0xBB7B,0x5B7B,0xBBBB,0xBBBB,0x11BB,0x22BB, }; const unsigned short map1Map[2048] __attribute__((aligned(4)))= { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0401, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0002,0x0003, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0004,0x0005,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0006,0x0007,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0008,0x0009,0x0008,0x0009,0x0008,0x0009,0x0008,0x0009, 0x000A,0x000B,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x000C,0x000D,0x0008,0x0009,0x0008,0x0009,0x0008,0x0009, 0x0008,0x0009,0x0008,0x0009,0x000A,0x000B,0x0000,0x0000, 0x000E,0x000F,0x000E,0x000F,0x000E,0x000F,0x000E,0x000F, 0x0010,0x0011,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0012,0x0013,0x000E,0x000F,0x000E,0x000F,0x000E,0x000F, 0x000E,0x000F,0x000E,0x000F,0x0010,0x0011,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0017,0x0018,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0015,0x0016,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x001B,0x001C,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0019,0x001A,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0017,0x0018,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0015,0x0016,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x001B,0x001C,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0019,0x001A,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0017,0x0018,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0015,0x0016,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x001B,0x001C,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0019,0x001A,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0017,0x0018,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0015,0x0016,0x0000,0x0000, 0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x001B,0x001C,0x0014,0x0014,0x0014,0x0014,0x0014,0x0014, 0x0014,0x0014,0x0014,0x0014,0x0019,0x001A,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0001,0x0401, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0002,0x0003, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x000C,0x000D,0x001D,0x001E, 0x000A,0x000B,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x001F,0x0020,0x0021,0x0022, 0x0023,0x0024,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0004,0x0005,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0006,0x0007,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000C,0x000D, 0x001D,0x001E,0x001D,0x001E,0x001D,0x001E,0x001D,0x001E, 0x001D,0x001E,0x000A,0x000B,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001F,0x0020, 0x0021,0x0022,0x0021,0x0022,0x0021,0x0022,0x0021,0x0022, 0x0021,0x0022,0x0023,0x0024,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x000C,0x000D, 0x000A,0x000B,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0012,0x0013, 0x0010,0x0011,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0017,0x0018, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001B,0x001C, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0017,0x0018, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001B,0x001C, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0017,0x0018, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001B,0x001C, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0017,0x0018, 0x0015,0x0016,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x001B,0x001C, 0x0019,0x001A,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, }; const unsigned short map1Pal[32] __attribute__((aligned(4)))= { 0x0000,0x1864,0x354A,0x166E,0x1586,0x18C6,0x0DEB,0x2529, 0x290E,0x3151,0x16B0,0x1888,0x0000,0x0000,0x0000,0x0000, 0x0000,0x4259,0x4679,0x3618,0x0000,0x0000,0x0000,0x0000, 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000, }; //}}BLOCK(map1)
the_stack_data/70449938.c
#include <stdio.h> #include <stdlib.h> #define BUFF_SIZE 1024 int main(int argc, char *argv[]){ FILE *src, *dist; char buf[BUFF_SIZE]; int n; if(argc < 3){ printf("Usage: %s src dist \n", argv[0]); exit(1); } if((src = fopen(argv[1], "rb"))== NULL){ printf("open %s failed.\n", argv[1]); fclose(src); exit(1); } if((dist = fopen(argv[2], "wb"))== NULL){ printf("open %s failed.\n", argv[2]); fclose(src); fclose(dist); exit(1); } while((n = fread(buf, 1, BUFF_SIZE, src)) > 0){ fwrite(buf,1,n,dist); } fclose(src); fclose(dist); return 0; }
the_stack_data/829274.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> #include <assert.h> #include <ctype.h> #include <limits.h> #define PROC_MEMORY_SPACE (11) #define UNDEFINED_PID (-999999) int total = 0; int max = 0; int min = INT_MAX; int min_process = UNDEFINED_PID; int max_process = UNDEFINED_PID; int proc_counter = 1; void read_file(const char * path, int pid) { ssize_t read; size_t len; char * line = NULL; char * end = NULL; FILE * f = fopen(path, "r"); int bytes; int space_counter = PROC_MEMORY_SPACE; int memory_index = 0; if (f) { // Read the file contents read = getline(&line, &len, f); // Assert read is successful assert(read != -1); // Find out the start index of the process total memory field while (space_counter > 0) { if (line[memory_index] == ' ') { --space_counter; } memory_index++; } // Convert the string to int bytes = strtol(line + memory_index, NULL, 0); // Increment number of total processes proc_counter++; // Add the memory usage to the total usage total += bytes; // Find out if the current usage is more than current max max = bytes > max ? bytes : max; max_process = bytes == max ? pid : max_process; // Find out if the current usage is less than current min min = bytes < min ? bytes : min; min_process = bytes == min ? pid : min_process; fclose (f); if (line) { free(line); } } } int main(int argc, char* argv[]) { struct dirent * dirent; DIR * dir; int r; int pid; char path[PATH_MAX]; if (!(dir = opendir ("/proc"))) { fprintf (stderr, "%s: couldn't open /proc, errno %d\n", "proc_info", EXIT_FAILURE); perror (NULL); exit (EXIT_FAILURE); } do { dirent = readdir (dir); // The first check works for detecting process ids with positive number // The second check works for negative process ids. if ((isdigit(*dirent->d_name)) || (dirent->d_name[0] == '-' && isdigit(*(dirent->d_name + 1))) ) { memset(path, 0, sizeof(path)); sprintf(path, "/proc/%s/psinfo", dirent->d_name); read_file(path, atoi(dirent->d_name)); } } while (dirent); closedir (dir); printf("Total memory used by all processes: %d bytes\n", total); printf("The average memory used per process: %d bytes\n", (total / proc_counter)); printf("The most memory used by any process (PID:%d): %d bytes\n", max_process, max); printf("The least memory used by any process (PID:%d): %d bytes\n", min_process, min); return EXIT_SUCCESS; }
the_stack_data/6387284.c
// Simple tool to extract unigram counts // Jeffrey Pennington ([email protected]) // From http://nlp.stanford.edu/projects/glove/ covered under APACHE LICENSE, a copy of which follows // // This software is licensed under the Apache 2 license, quoted below. // // Copyright 2014 Jeffrey Pennington <[email protected]> // // Licensed under the Apache License, Version 2.0 (the "License"); you may not // use this file except in compliance with the License. You may obtain a copy of // the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the // License for the specific language governing permissions and limitations under // the License. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_STRING_LENGTH 1000 #define TSIZE 1048576 #define SEED 1159241 #define HASHFN bitwisehash typedef struct vocabulary { char *word; long long count; } VOCAB; typedef struct hashrec { char *word; long long count; struct hashrec *next; } HASHREC; int verbose = 2; // 0, 1, or 2 long long min_count = 1; // min occurrences for inclusion in vocab long long max_vocab = 0; // max_vocab = 0 for no limit /* Efficient string comparison */ int scmp( char *s1, char *s2 ) { while(*s1 != '\0' && *s1 == *s2) {s1++; s2++;} return(*s1 - *s2); } /* Vocab frequency comparison; break ties alphabetically */ int CompareVocabTie(const void *a, const void *b) { long long c; if( (c = ((VOCAB *) b)->count - ((VOCAB *) a)->count) != 0) return ( c > 0 ? 1 : -1 ); else return (scmp(((VOCAB *) a)->word,((VOCAB *) b)->word)); } /* Vocab frequency comparison; no tie-breaker */ int CompareVocab(const void *a, const void *b) { long long c; if( (c = ((VOCAB *) b)->count - ((VOCAB *) a)->count) != 0) return ( c > 0 ? 1 : -1 ); else return 0; } /* Move-to-front hashing and hash function from Hugh Williams, http://www.seg.rmit.edu.au/code/zwh-ipl/ */ /* Simple bitwise hash function */ unsigned int bitwisehash(char *word, int tsize, unsigned int seed) { char c; unsigned int h; h = seed; for(; (c =* word) != '\0'; word++) h ^= ((h << 5) + c + (h >> 2)); return((unsigned int)((h&0x7fffffff) % tsize)); } /* Create hash table, initialise pointers to NULL */ HASHREC ** inithashtable() { int i; HASHREC **ht; ht = (HASHREC **) malloc( sizeof(HASHREC *) * TSIZE ); for(i = 0; i < TSIZE; i++) ht[i] = (HASHREC *) NULL; return(ht); } /* Search hash table for given string, insert if not found */ void hashinsert(HASHREC **ht, char *w) { HASHREC *htmp, *hprv; unsigned int hval = HASHFN(w, TSIZE, SEED); for(hprv = NULL, htmp = ht[hval]; htmp != NULL && scmp(htmp->word, w) != 0; hprv = htmp, htmp = htmp->next); if(htmp == NULL) { htmp = (HASHREC *) malloc( sizeof(HASHREC) ); htmp->word = (char *) malloc( strlen(w) + 1 ); strcpy(htmp->word, w); htmp->count = 1; htmp->next = NULL; if( hprv==NULL ) ht[hval] = htmp; else hprv->next = htmp; } else { /* new records are not moved to front */ htmp->count++; if(hprv != NULL) { /* move to front on access */ hprv->next = htmp->next; htmp->next = ht[hval]; ht[hval] = htmp; } } return; } int get_counts() { long long i = 0, j = 0, vocab_size = 12500; char format[20]; char str[MAX_STRING_LENGTH + 1]; HASHREC **vocab_hash = inithashtable(); HASHREC *htmp; VOCAB *vocab; FILE *fid = stdin; fprintf(stderr, "BUILDING VOCABULARY\n"); if(verbose > 1) fprintf(stderr, "Processed %lld tokens.", i); sprintf(format,"%%%ds",MAX_STRING_LENGTH); while(fscanf(fid, format, str) != EOF) { // Insert all tokens into hashtable hashinsert(vocab_hash, str); if(((++i)%100000) == 0) if(verbose > 1) fprintf(stderr,"\033[11G%lld tokens.", i); } if(verbose > 1) fprintf(stderr, "\033[0GProcessed %lld tokens.\n", i); vocab = malloc(sizeof(VOCAB) * vocab_size); for(i = 0; i < TSIZE; i++) { // Migrate vocab to array htmp = vocab_hash[i]; while (htmp != NULL) { vocab[j].word = htmp->word; vocab[j].count = htmp->count; j++; if(j>=vocab_size) { vocab_size += 2500; vocab = (VOCAB *)realloc(vocab, sizeof(VOCAB) * vocab_size); } htmp = htmp->next; } } if(verbose > 1) fprintf(stderr, "Counted %lld unique words.\n", j); if(max_vocab > 0 && max_vocab < j) // If the vocabulary exceeds limit, first sort full vocab by frequency without alphabetical tie-breaks. // This results in pseudo-random ordering for words with same frequency, so that when truncated, the words span whole alphabet qsort(vocab, j, sizeof(VOCAB), CompareVocab); else max_vocab = j; qsort(vocab, max_vocab, sizeof(VOCAB), CompareVocabTie); //After (possibly) truncating, sort (possibly again), breaking ties alphabetically for(i = 0; i < max_vocab; i++) { if(vocab[i].count < min_count) { // If a minimum frequency cutoff exists, truncate vocabulary if(verbose > 0) fprintf(stderr, "Truncating vocabulary at min count %lld.\n",min_count); break; } printf("%s %lld\n",vocab[i].word,vocab[i].count); } if(i == max_vocab && max_vocab < j) if(verbose > 0) fprintf(stderr, "Truncating vocabulary at size %lld.\n", max_vocab); fprintf(stderr, "Using vocabulary of size %lld.\n\n", i); return 0; } int find_arg(char *str, int argc, char **argv) { int i; for (i = 1; i < argc; i++) { if(!scmp(str, argv[i])) { if (i == argc - 1) { printf("No argument given for %s\n", str); exit(1); } return i; } } return -1; } int main(int argc, char **argv) { int i; if (argc == 1) { printf("Simple tool to extract unigram counts\n"); printf("Author: Jeffrey Pennington ([email protected])\n\n"); printf("Usage options:\n"); printf("\t-verbose <int>\n"); printf("\t\tSet verbosity: 0, 1, or 2 (default)\n"); printf("\t-max-vocab <int>\n"); printf("\t\tUpper bound on vocabulary size, i.e. keep the <int> most frequent words. The minimum frequency words are randomly sampled so as to obtain an even distribution over the alphabet.\n"); printf("\t-min-count <int>\n"); printf("\t\tLower limit such that words which occur fewer than <int> times are discarded.\n"); printf("\nExample usage:\n"); printf("./vocab_count -verbose 2 -max-vocab 100000 -min-count 10 < corpus.txt > vocab.txt\n"); return 0; } if ((i = find_arg((char *)"-verbose", argc, argv)) > 0) verbose = atoi(argv[i + 1]); if ((i = find_arg((char *)"-max-vocab", argc, argv)) > 0) max_vocab = atoll(argv[i + 1]); if ((i = find_arg((char *)"-min-count", argc, argv)) > 0) min_count = atoll(argv[i + 1]); return get_counts(); }
the_stack_data/34719.c
#include <stdlib.h> #include <stdio.h> #include <string.h> #include <signal.h> #ifdef _WIN32 /* GetNamedPipeServerProcessId requires Windows Vista+ */ #undef _WIN32_WINNT #define _WIN32_WINNT 0x600 #include <windows.h> #include <Lmcons.h> #include <process.h> #ifndef STDIN_FILENO #define STDIN_FILENO 0 #endif #ifndef STDOUT_FILENO #define STDOUT_FILENO 1 #endif #ifndef STDERR_FILENO #define STDERR_FILENO 2 #endif #ifdef _MSC_VER typedef SSIZE_T ssize_t; #define PATH_MAX MAX_PATH #ifndef _UCRT #define snprintf _snprintf #endif #endif #else #include <unistd.h> #include <sys/socket.h> #include <sys/un.h> #include <sys/stat.h> #include <sys/wait.h> #include <libgen.h> #endif #include <errno.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <limits.h> #if defined(__linux) #include <sys/param.h> #elif defined(__APPLE__) #include <sys/syslimits.h> #elif defined(__OpenBSD__) #include <sys/param.h> #endif /** Portability information **/ /* Determine OS, http://stackoverflow.com/questions/6649936 __linux__ Defined on Linux __sun Defined on Solaris __FreeBSD__ Defined on FreeBSD __NetBSD__ Defined on NetBSD __OpenBSD__ Defined on OpenBSD __APPLE__ Defined on Mac OS X __hpux Defined on HP-UX __osf__ Defined on Tru64 UNIX (formerly DEC OSF1) __sgi Defined on Irix _AIX Defined on AIX */ /* Compute executable path, http://stackoverflow.com/questions/1023306 Mac OS X _NSGetExecutablePath() (man 3 dyld) Linux readlink /proc/self/exe Solaris getexecname() FreeBSD sysctl CTL_KERN KERN_PROC KERN_PROC_PATHNAME -1 NetBSD readlink /proc/curproc/exe DragonFly BSD readlink /proc/curproc/file Windows GetModuleFileName() with hModule = NULL */ #define NO_EINTR(var, command) \ do { (var) = command; } while ((var) == -1 && errno == EINTR) static void dumpinfo(void); static void failwith_perror(const char *msg) { perror(msg); dumpinfo(); exit(EXIT_FAILURE); } static void failwith(const char *msg) { fprintf(stderr, "%s\n", msg); dumpinfo(); exit(EXIT_FAILURE); } #define PATHSZ (PATH_MAX+1) #define BEGIN_PROTECTCWD \ { char previous_cwd[PATHSZ]; \ if (!getcwd(previous_cwd, PATHSZ)) previous_cwd[0] = '\0'; #define END_PROTECTCWD \ if (previous_cwd[0] != '\0') chdir(previous_cwd); } static const char *path_socketdir(void) { static const char *tmpdir = NULL; if (tmpdir == NULL) tmpdir = getenv("TMPDIR"); if (tmpdir == NULL) tmpdir = "/tmp"; return tmpdir; } #ifdef _WIN32 /** Deal with Windows IPC **/ static void ipc_send(HANDLE hPipe, unsigned char *buffer, size_t len, HANDLE fds[3]) { DWORD dwNumberOfBytesWritten; if (!WriteFile(hPipe, fds, 3 * sizeof(HANDLE), &dwNumberOfBytesWritten, NULL) || dwNumberOfBytesWritten != 3 * sizeof(HANDLE)) failwith_perror("sendmsg"); if (!WriteFile(hPipe, buffer, len, &dwNumberOfBytesWritten, NULL) || dwNumberOfBytesWritten != len) failwith_perror("send"); } #else /** Deal with UNIX IPC **/ static void ipc_send(int fd, unsigned char *buffer, size_t len, int fds[3]) { char msg_control[CMSG_SPACE(3 * sizeof(int))]; struct iovec iov = { .iov_base = buffer, .iov_len = len }; struct msghdr msg = { .msg_iov = &iov, .msg_iovlen = 1, .msg_controllen = CMSG_SPACE(3 * sizeof(int)), }; msg.msg_control = &msg_control; memset(msg.msg_control, 0, msg.msg_controllen); struct cmsghdr *cm = CMSG_FIRSTHDR(&msg); cm->cmsg_level = SOL_SOCKET; cm->cmsg_type = SCM_RIGHTS; cm->cmsg_len = CMSG_LEN(3 * sizeof(int)); int *fds0 = (int*)CMSG_DATA(cm); fds0[0] = fds[0]; fds0[1] = fds[1]; fds0[2] = fds[2]; ssize_t sent; NO_EINTR(sent, sendmsg(fd, &msg, 0)); if (sent == -1) failwith_perror("sendmsg"); while (sent < len) { ssize_t sent_; NO_EINTR(sent_, send(fd, buffer + sent, len - sent, 0)); if (sent_ == -1) failwith_perror("sent"); sent += sent_; } } #endif /* Serialize arguments */ #define byte(x,n) ((unsigned)((x) >> (n * 8)) & 0xFF) static void append_argument(unsigned char *buffer, size_t len, ssize_t *pos, const char *p) { ssize_t j = *pos; while (*p && j < len) { buffer[j] = *p; j += 1; p += 1; } if (j >= len) failwith("maximum number of arguments exceeded"); buffer[j] = 0; j += 1; *pos = j; } #ifdef _MSC_VER extern __declspec(dllimport) char **environ; #else extern char **environ; #endif static ssize_t prepare_args(unsigned char *buffer, size_t len, int argc, char **argv) { int i = 0; ssize_t j = 4; /* First put the current working directory */ char cwd[PATHSZ]; if (!getcwd(cwd, PATHSZ)) cwd[0] = '\0'; append_argument(buffer, len, &j, cwd); /* Then append environ */ for (i = 0; environ[i] != NULL; ++i) { const char *v = environ[i]; if (v[0] == '\0') continue; append_argument(buffer, len, &j, environ[i]); } /* Env var delimiter */ append_argument(buffer, len, &j, ""); /* Append arguments */ for (i = 0; i < argc && j < len; ++i) { append_argument(buffer, len, &j, argv[i]); } /* Put size at the beginning */ buffer[0] = byte(j,0); buffer[1] = byte(j,1); buffer[2] = byte(j,2); buffer[3] = byte(j,3); return j; } #ifdef _WIN32 #define IPC_SOCKET_TYPE HANDLE static HANDLE connect_socket(const char *socketname, int fail) { HANDLE hPipe; hPipe = CreateFile(socketname, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0); if (hPipe == INVALID_HANDLE_VALUE) if (fail) failwith_perror("connect"); return hPipe; } #else #define IPC_SOCKET_TYPE int #define INVALID_HANDLE_VALUE -1 static int connect_socket(const char *socketname, int fail) { int sock = socket(PF_UNIX, SOCK_STREAM, 0); if (sock == -1) failwith_perror("socket"); int err; BEGIN_PROTECTCWD struct sockaddr_un address; int address_len; chdir(path_socketdir()); address.sun_family = AF_UNIX; snprintf(address.sun_path, 104, "./%s", socketname); address_len = strlen(address.sun_path) + sizeof(address.sun_family) + 1; NO_EINTR(err, connect(sock, (struct sockaddr*)&address, address_len)); END_PROTECTCWD if (err == -1) { if (fail) failwith_perror("connect"); close(sock); return -1; } return sock; } #endif #ifdef _WIN32 static void start_server(const char *socketname, const char* eventname, const char *exec_path) { char buf[PATHSZ]; PROCESS_INFORMATION pi; STARTUPINFO si; HANDLE hEvent = CreateEvent(NULL, FALSE, FALSE, eventname); DWORD dwResult; sprintf(buf, "%s server %s %s", exec_path, socketname, eventname); ZeroMemory(&si, sizeof(si)); si.cb = sizeof(si); ZeroMemory(&pi, sizeof(pi)); /* Note that DETACHED_PROCESS means that the process does not appear in Task Manager but the server can still be stopped with ocamlmerlin server stop-server */ if (!CreateProcess(exec_path, buf, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &si, &pi)) failwith_perror("fork"); CloseHandle(pi.hProcess); CloseHandle(pi.hThread); if (WaitForSingleObject(hEvent, 5000) != WAIT_OBJECT_0) failwith_perror("execlp"); } #else static void make_daemon(int sock) { /* On success: The child process becomes session leader */ if (setsid() < 0) failwith_perror("setsid"); /* Close all open file descriptors */ close(0); if (open("/dev/null", O_RDWR, 0) != 0) failwith_perror("open"); dup2(0,1); dup2(0,2); /* Change directory to root, so that process still works if directory * is delete. */ if (chdir("/") != 0) failwith_perror("chdir"); //int x; //for (x = sysconf(_SC_OPEN_MAX); x>2; x--) //{ // if (x != sock) // close(x); //} pid_t child = fork(); signal(SIGHUP, SIG_IGN); /* An error occurred */ if (child < 0) failwith_perror("fork"); /* Success: Let the parent terminate */ if (child > 0) exit(EXIT_SUCCESS); } static void start_server(const char *socketname, const char* ignored, const char *exec_path) { int sock = socket(PF_UNIX, SOCK_STREAM, 0); if (sock == -1) failwith_perror("socket"); int err; BEGIN_PROTECTCWD struct sockaddr_un address; int address_len; chdir(path_socketdir()); address.sun_family = AF_UNIX; snprintf(address.sun_path, 104, "./%s", socketname); address_len = strlen(address.sun_path) + sizeof(address.sun_family) + 1; unlink(address.sun_path); NO_EINTR(err, bind(sock, (struct sockaddr*)&address, address_len)); END_PROTECTCWD if (err == -1) failwith_perror("bind"); if (listen(sock, 5) == -1) failwith_perror("listen"); pid_t child = fork(); if (child == -1) failwith_perror("fork"); if (child == 0) { make_daemon(sock); char socket_fd[50], socket_path[PATHSZ]; sprintf(socket_fd, "%d", sock); snprintf(socket_path, PATHSZ, "%s/%s", path_socketdir(), socketname); //execlp("nohup", "nohup", exec_path, "server", socket_path, socket_fd, NULL); execlp(exec_path, exec_path, "server", socket_path, socket_fd, NULL); failwith_perror("execlp"); } close(sock); wait(NULL); } #endif static IPC_SOCKET_TYPE connect_and_serve(const char *socket_path, const char* event_path, const char *exec_path) { IPC_SOCKET_TYPE sock = connect_socket(socket_path, 0); if (sock == INVALID_HANDLE_VALUE) { start_server(socket_path, event_path, exec_path); sock = connect_socket(socket_path, 1); } if (sock == INVALID_HANDLE_VALUE) abort(); return sock; } /* OCaml merlin path */ static const char *search_in_path(const char *PATH, const char *argv0, char *merlin_path) { static char binary_path[PATHSZ]; #ifdef _WIN32 char *result = NULL; DWORD dwResult; #endif if (PATH == NULL || argv0 == NULL) return NULL; while (*PATH) { int i = 0; // Copy one path from PATH while (i < PATHSZ-1 && *PATH && *PATH != ':') { binary_path[i] = *PATH; i += 1; PATH += 1; } // Append filename { const char *file = argv0; binary_path[i] = '/'; i += 1; while (i < PATHSZ-1 && *file) { binary_path[i] = *file; i += 1; file += 1; } binary_path[i] = 0; i += 1; } // Check path #ifdef _WIN32 dwResult = GetFullPathName(binary_path, PATHSZ, merlin_path, NULL); if (dwResult && dwResult < PATHSZ) if (GetLongPathName(binary_path, NULL, 0)) result = binary_path; #else char *result = realpath(binary_path, merlin_path); #endif if (result != NULL) return result; // Seek next path in PATH while (*PATH && *PATH != ':') PATH += 1; while (*PATH == ':') PATH += 1; } return NULL; } static void prune_binary_name(char * buffer) { size_t strsz = strlen(buffer); while (strsz > 0 && buffer[strsz-1] != '/' && buffer[strsz-1] != '\\') strsz -= 1; buffer[strsz] = 0; } #ifdef _WIN32 static char ocamlmerlin_server[] = "ocamlmerlin-server.exe"; #else static char ocamlmerlin_server[] = "ocamlmerlin-server"; #endif static void compute_merlinpath(char merlin_path[PATHSZ], const char *argv0, struct stat *st) { char argv0_dirname[PATHSZ]; size_t strsz; strcpy(argv0_dirname, argv0); prune_binary_name(argv0_dirname); // Check if we were called with a path or not if (strlen(argv0_dirname) == 0) { if (search_in_path(getenv("PATH"), argv0, merlin_path) == NULL) failwith("cannot resolve path to ocamlmerlin"); } else { #ifdef _WIN32 // GetFullPathName does not resolve symbolic links, which realpath does. // @@DRA GetLongPathName ensures that the file exists (better way?!). // Not sure if this matters. DWORD dwResult = GetFullPathName(argv0, PATHSZ, merlin_path, NULL); if (!dwResult || dwResult >= PATHSZ || !GetLongPathName(merlin_path, NULL, 0)) #else if (realpath(argv0, merlin_path) == NULL) #endif failwith("argv0 does not point to a valid file"); } prune_binary_name(merlin_path); strsz = strlen(merlin_path); // Append ocamlmerlin-server if (strsz + sizeof(ocamlmerlin_server) + 8 > PATHSZ) failwith("path is too long"); strcpy(merlin_path + strsz, ocamlmerlin_server); if (stat(merlin_path, st) != 0) { strcpy(merlin_path + strsz, "ocamlmerlin_server.exe"); if (stat(merlin_path, st) != 0) { strcpy(merlin_path + strsz, ocamlmerlin_server); failwith_perror("stat(ocamlmerlin-server, also tried ocamlmerlin_server.exe)"); } } } #ifdef _WIN32 static void compute_socketname(char socketname[PATHSZ], char eventname[PATHSZ], const char merlin_path[PATHSZ]) #else static void compute_socketname(char socketname[PATHSZ], struct stat *st) #endif { #ifdef _WIN32 CHAR user[UNLEN + 1]; DWORD dwBufSize = UNLEN; BY_HANDLE_FILE_INFORMATION info; HANDLE hFile = CreateFile(merlin_path, FILE_READ_ATTRIBUTES, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (hFile == INVALID_HANDLE_VALUE || !GetFileInformationByHandle(hFile, &info)) failwith_perror("stat (cannot find ocamlmerlin binary)"); CloseHandle(hFile); if (!GetUserName(user, &dwBufSize)) user[0] = '\0'; // @@DRA Need to use Windows API functions to get meaningful values for st_dev and st_ino snprintf(eventname, PATHSZ, "ocamlmerlin_%s_%lx_%llx", user, info.dwVolumeSerialNumber, ((__int64)info.nFileIndexHigh) << 32 | ((__int64)info.nFileIndexLow)); snprintf(socketname, PATHSZ, "\\\\.\\pipe\\%s", eventname); #else snprintf(socketname, PATHSZ, "ocamlmerlin_%llu_%llu_%llu.socket", (unsigned long long)getuid(), (unsigned long long)st->st_dev, (unsigned long long)st->st_ino); #endif } /* Main */ static char merlin_path[PATHSZ] = "<not computed yet>", socketname[PATHSZ] = "<not computed yet>", eventname[PATHSZ] = "<not computed yet>"; static unsigned char argbuffer[262144]; static void dumpinfo(void) { fprintf(stderr, "merlin path: %s\nsocket path: %s/%s\n", merlin_path, path_socketdir(), socketname); } static void unexpected_termination(int argc, char **argv) { int sexp = 0; int i; for (i = 1; i < argc - 1; ++i) { if (strcmp(argv[i], "-protocol") == 0 && strcmp(argv[i+1], "sexp") == 0) sexp = 1; } puts(sexp ? "((assoc) (class . \"failure\") (value . \"abnormal termination\") (notifications))" : "{\"class\": \"failure\", \"value\": \"abnormal termination\", \"notifications\": [] }" ); failwith("abnormal termination"); } int main(int argc, char **argv) { char result = 0; int err = 0; struct stat st; #ifdef _WIN32 HANDLE fds[3]; ULONG pid; HANDLE hProcess, hServerProcess; DWORD dwNumberOfBytesRead; CHAR argv0[PATHSZ]; GetModuleFileName(NULL, argv0, PATHSZ); compute_merlinpath(merlin_path, argv0, &st); #else compute_merlinpath(merlin_path, argv[0], &st); #endif if (argc >= 2 && strcmp(argv[1], "server") == 0) { IPC_SOCKET_TYPE sock; ssize_t len; #ifdef _WIN32 compute_socketname(socketname, eventname, merlin_path); #else compute_socketname(socketname, &st); #endif sock = connect_and_serve(socketname, eventname, merlin_path); len = prepare_args(argbuffer, sizeof(argbuffer), argc-2, argv+2); #ifdef _WIN32 hProcess = GetCurrentProcess(); if (!GetNamedPipeServerProcessId(sock, &pid)) failwith_perror("GetNamedPipeServerProcessId"); hServerProcess = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid); if (hServerProcess == INVALID_HANDLE_VALUE) failwith_perror("OpenProcess"); if (!DuplicateHandle(hProcess, GetStdHandle(STD_INPUT_HANDLE), hServerProcess, &fds[0], 0, FALSE, DUPLICATE_SAME_ACCESS)) failwith_perror("DuplicateHandle(stdin)"); if (!DuplicateHandle(hProcess, GetStdHandle(STD_OUTPUT_HANDLE), hServerProcess, &fds[1], 0, FALSE, DUPLICATE_SAME_ACCESS)) failwith_perror("DuplicateHandle(stdout)"); CloseHandle(GetStdHandle(STD_OUTPUT_HANDLE)); if (!DuplicateHandle(hProcess, GetStdHandle(STD_ERROR_HANDLE), hServerProcess, &fds[2], 0, FALSE, DUPLICATE_SAME_ACCESS)) failwith_perror("DuplicateHandle(stderr)"); #else int fds[3] = { STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO }; #endif ipc_send(sock, argbuffer, len, fds); #ifdef _WIN32 if (ReadFile(sock, &result, 1, &dwNumberOfBytesRead, NULL) && dwNumberOfBytesRead == 1) err = 1; #else NO_EINTR(err, read(sock, &result, 1)); #endif if (err == 1) exit(result); unexpected_termination(argc, argv); } else { argv[0] = ocamlmerlin_server; execvp(merlin_path, argv); failwith_perror("execvp(ocamlmerlin-server)"); } }
the_stack_data/97011454.c
#include <stdio.h> int main (){ int i=10, j=20; int *pti, *ptj; pti = &i; ptj = &j; printf("%d %d\n", pti, *pti); printf("%d %d\n", ptj, *ptj); printf("\n"); printf("j = pti == ptj;\n"); printf("\n"); j = pti == ptj; printf("%d %d\n", pti, *pti); printf("%d %d\n", ptj, *ptj); printf("i => %d \n", i); printf("j => %d \n", j); printf("\n"); printf("i = pti -ptj;\n"); printf("\n"); i = pti - ptj; printf("%d %d\n", pti, *pti); printf("%d %d\n", ptj, *ptj); printf("i => %d \n", i); printf("j => %d \n", j); printf("\n"); printf("pti++\n"); printf("\n"); pti++; printf("%d %d\n", pti, *pti); printf("%d %d\n", ptj, *ptj); printf("i => %d \n", i); printf("j => %d \n", j); return 0; }
the_stack_data/274307.c
#include <math.h> #include <stdlib.h> #include <string.h> #include <stdio.h> #include <complex.h> #ifdef complex #undef complex #endif #ifdef I #undef I #endif #if defined(_WIN64) typedef long long BLASLONG; typedef unsigned long long BLASULONG; #else typedef long BLASLONG; typedef unsigned long BLASULONG; #endif #ifdef LAPACK_ILP64 typedef BLASLONG blasint; #if defined(_WIN64) #define blasabs(x) llabs(x) #else #define blasabs(x) labs(x) #endif #else typedef int blasint; #define blasabs(x) abs(x) #endif typedef blasint integer; typedef unsigned int uinteger; typedef char *address; typedef short int shortint; typedef float real; typedef double doublereal; typedef struct { real r, i; } complex; typedef struct { doublereal r, i; } doublecomplex; #ifdef _MSC_VER static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;} static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;} static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;} static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;} #else static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;} #endif #define pCf(z) (*_pCf(z)) #define pCd(z) (*_pCd(z)) typedef int logical; typedef short int shortlogical; typedef char logical1; typedef char integer1; #define TRUE_ (1) #define FALSE_ (0) /* Extern is for use with -E */ #ifndef Extern #define Extern extern #endif /* I/O stuff */ typedef int flag; typedef int ftnlen; typedef int ftnint; /*external read, write*/ typedef struct { flag cierr; ftnint ciunit; flag ciend; char *cifmt; ftnint cirec; } cilist; /*internal read, write*/ typedef struct { flag icierr; char *iciunit; flag iciend; char *icifmt; ftnint icirlen; ftnint icirnum; } icilist; /*open*/ typedef struct { flag oerr; ftnint ounit; char *ofnm; ftnlen ofnmlen; char *osta; char *oacc; char *ofm; ftnint orl; char *oblnk; } olist; /*close*/ typedef struct { flag cerr; ftnint cunit; char *csta; } cllist; /*rewind, backspace, endfile*/ typedef struct { flag aerr; ftnint aunit; } alist; /* inquire */ typedef struct { flag inerr; ftnint inunit; char *infile; ftnlen infilen; ftnint *inex; /*parameters in standard's order*/ ftnint *inopen; ftnint *innum; ftnint *innamed; char *inname; ftnlen innamlen; char *inacc; ftnlen inacclen; char *inseq; ftnlen inseqlen; char *indir; ftnlen indirlen; char *infmt; ftnlen infmtlen; char *inform; ftnint informlen; char *inunf; ftnlen inunflen; ftnint *inrecl; ftnint *innrec; char *inblank; ftnlen inblanklen; } inlist; #define VOID void union Multitype { /* for multiple entry points */ integer1 g; shortint h; integer i; /* longint j; */ real r; doublereal d; complex c; doublecomplex z; }; typedef union Multitype Multitype; struct Vardesc { /* for Namelist */ char *name; char *addr; ftnlen *dims; int type; }; typedef struct Vardesc Vardesc; struct Namelist { char *name; Vardesc **vars; int nvars; }; typedef struct Namelist Namelist; #define abs(x) ((x) >= 0 ? (x) : -(x)) #define dabs(x) (fabs(x)) #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) #define f2cmax(a,b) ((a) >= (b) ? (a) : (b)) #define dmin(a,b) (f2cmin(a,b)) #define dmax(a,b) (f2cmax(a,b)) #define bit_test(a,b) ((a) >> (b) & 1) #define bit_clear(a,b) ((a) & ~((uinteger)1 << (b))) #define bit_set(a,b) ((a) | ((uinteger)1 << (b))) #define abort_() { sig_die("Fortran abort routine called", 1); } #define c_abs(z) (cabsf(Cf(z))) #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); } #ifdef _MSC_VER #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);} #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);} #else #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);} #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);} #endif #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));} #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));} #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));} //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));} #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));} #define d_abs(x) (fabs(*(x))) #define d_acos(x) (acos(*(x))) #define d_asin(x) (asin(*(x))) #define d_atan(x) (atan(*(x))) #define d_atn2(x, y) (atan2(*(x),*(y))) #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); } #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); } #define d_cos(x) (cos(*(x))) #define d_cosh(x) (cosh(*(x))) #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 ) #define d_exp(x) (exp(*(x))) #define d_imag(z) (cimag(Cd(z))) #define r_imag(z) (cimagf(Cf(z))) #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x))) #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) ) #define d_log(x) (log(*(x))) #define d_mod(x, y) (fmod(*(x), *(y))) #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x))) #define d_nint(x) u_nint(*(x)) #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a))) #define d_sign(a,b) u_sign(*(a),*(b)) #define r_sign(a,b) u_sign(*(a),*(b)) #define d_sin(x) (sin(*(x))) #define d_sinh(x) (sinh(*(x))) #define d_sqrt(x) (sqrt(*(x))) #define d_tan(x) (tan(*(x))) #define d_tanh(x) (tanh(*(x))) #define i_abs(x) abs(*(x)) #define i_dnnt(x) ((integer)u_nint(*(x))) #define i_len(s, n) (n) #define i_nint(x) ((integer)u_nint(*(x))) #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b))) #define pow_dd(ap, bp) ( pow(*(ap), *(bp))) #define pow_si(B,E) spow_ui(*(B),*(E)) #define pow_ri(B,E) spow_ui(*(B),*(E)) #define pow_di(B,E) dpow_ui(*(B),*(E)) #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));} #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));} #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));} #define s_cat(lpp, rpp, rnp, np, llp) { ftnlen i, nc, ll; char *f__rp, *lp; ll = (llp); lp = (lpp); for(i=0; i < (int)*(np); ++i) { nc = ll; if((rnp)[i] < nc) nc = (rnp)[i]; ll -= nc; f__rp = (rpp)[i]; while(--nc >= 0) *lp++ = *(f__rp)++; } while(--ll >= 0) *lp++ = ' '; } #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d)))) #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; } #define sig_die(s, kill) { exit(1); } #define s_stop(s, n) {exit(0);} static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n"; #define z_abs(z) (cabs(Cd(z))) #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} #define myexit_() break; #define mycycle() continue; #define myceiling(w) {ceil(w)} #define myhuge(w) {HUGE_VAL} //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} /* procedure parameter types for -A and -C++ */ #define F2C_proc_par_types 1 #ifdef __cplusplus typedef logical (*L_fp)(...); #else typedef logical (*L_fp)(); #endif static float spow_ui(float x, integer n) { float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static double dpow_ui(double x, integer n) { double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #ifdef _MSC_VER static _Fcomplex cpow_ui(complex x, integer n) { complex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i; for(u = n; ; ) { if(u & 01) pow.r *= x.r, pow.i *= x.i; if(u >>= 1) x.r *= x.r, x.i *= x.i; else break; } } _Fcomplex p={pow.r, pow.i}; return p; } #else static _Complex float cpow_ui(_Complex float x, integer n) { _Complex float pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif #ifdef _MSC_VER static _Dcomplex zpow_ui(_Dcomplex x, integer n) { _Dcomplex pow={1.0,0.0}; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1]; for(u = n; ; ) { if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1]; if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1]; else break; } } _Dcomplex p = {pow._Val[0], pow._Val[1]}; return p; } #else static _Complex double zpow_ui(_Complex double x, integer n) { _Complex double pow=1.0; unsigned long int u; if(n != 0) { if(n < 0) n = -n, x = 1/x; for(u = n; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } #endif static integer pow_ii(integer x, integer n) { integer pow; unsigned long int u; if (n <= 0) { if (n == 0 || x == 1) pow = 1; else if (x != -1) pow = x == 0 ? 1/x : 0; else n = -n; } if ((n > 0) || !(n == 0 || x == 1 || x != -1)) { u = n; for(pow = 1; ; ) { if(u & 01) pow *= x; if(u >>= 1) x *= x; else break; } } return pow; } static integer dmaxloc_(double *w, integer s, integer e, integer *n) { double m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static integer smaxloc_(float *w, integer s, integer e, integer *n) { float m; integer i, mi; for(m=w[s-1], mi=s, i=s+1; i<=e; i++) if (w[i-1]>m) mi=i ,m=w[i-1]; return mi-s+1; } static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i])) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i])) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Fcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0]; zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0]; zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1]; } } pCf(z) = zdotc; } #else _Complex float zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i]) * Cf(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]); } } pCf(z) = zdotc; } #endif static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) { integer n = *n_, incx = *incx_, incy = *incy_, i; #ifdef _MSC_VER _Dcomplex zdotc = {0.0, 0.0}; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0]; zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1]; } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0]; zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1]; } } pCd(z) = zdotc; } #else _Complex double zdotc = 0.0; if (incx == 1 && incy == 1) { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i]) * Cd(&y[i]); } } else { for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */ zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]); } } pCd(z) = zdotc; } #endif /* -- translated by f2c (version 20000121). You must link the resulting object file with the libraries: -lf2c -lm (in that order) */ /* Table of constant values */ static integer c__1 = 1; static real c_b36 = .5f; /* > \brief \b CLATRS solves a triangular system of equations with the scale factor set to prevent overflow. */ /* =========== DOCUMENTATION =========== */ /* Online html documentation available at */ /* http://www.netlib.org/lapack/explore-html/ */ /* > \htmlonly */ /* > Download CLATRS + dependencies */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/clatrs. f"> */ /* > [TGZ]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/clatrs. f"> */ /* > [ZIP]</a> */ /* > <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/clatrs. f"> */ /* > [TXT]</a> */ /* > \endhtmlonly */ /* Definition: */ /* =========== */ /* SUBROUTINE CLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE, */ /* CNORM, INFO ) */ /* CHARACTER DIAG, NORMIN, TRANS, UPLO */ /* INTEGER INFO, LDA, N */ /* REAL SCALE */ /* REAL CNORM( * ) */ /* COMPLEX A( LDA, * ), X( * ) */ /* > \par Purpose: */ /* ============= */ /* > */ /* > \verbatim */ /* > */ /* > CLATRS solves one of the triangular systems */ /* > */ /* > A * x = s*b, A**T * x = s*b, or A**H * x = s*b, */ /* > */ /* > with scaling to prevent overflow. Here A is an upper or lower */ /* > triangular matrix, A**T denotes the transpose of A, A**H denotes the */ /* > conjugate transpose of A, x and b are n-element vectors, and s is a */ /* > scaling factor, usually less than or equal to 1, chosen so that the */ /* > components of x will be less than the overflow threshold. If the */ /* > unscaled problem will not cause overflow, the Level 2 BLAS routine */ /* > CTRSV is called. If the matrix A is singular (A(j,j) = 0 for some j), */ /* > then s is set to 0 and a non-trivial solution to A*x = 0 is returned. */ /* > \endverbatim */ /* Arguments: */ /* ========== */ /* > \param[in] UPLO */ /* > \verbatim */ /* > UPLO is CHARACTER*1 */ /* > Specifies whether the matrix A is upper or lower triangular. */ /* > = 'U': Upper triangular */ /* > = 'L': Lower triangular */ /* > \endverbatim */ /* > */ /* > \param[in] TRANS */ /* > \verbatim */ /* > TRANS is CHARACTER*1 */ /* > Specifies the operation applied to A. */ /* > = 'N': Solve A * x = s*b (No transpose) */ /* > = 'T': Solve A**T * x = s*b (Transpose) */ /* > = 'C': Solve A**H * x = s*b (Conjugate transpose) */ /* > \endverbatim */ /* > */ /* > \param[in] DIAG */ /* > \verbatim */ /* > DIAG is CHARACTER*1 */ /* > Specifies whether or not the matrix A is unit triangular. */ /* > = 'N': Non-unit triangular */ /* > = 'U': Unit triangular */ /* > \endverbatim */ /* > */ /* > \param[in] NORMIN */ /* > \verbatim */ /* > NORMIN is CHARACTER*1 */ /* > Specifies whether CNORM has been set or not. */ /* > = 'Y': CNORM contains the column norms on entry */ /* > = 'N': CNORM is not set on entry. On exit, the norms will */ /* > be computed and stored in CNORM. */ /* > \endverbatim */ /* > */ /* > \param[in] N */ /* > \verbatim */ /* > N is INTEGER */ /* > The order of the matrix A. N >= 0. */ /* > \endverbatim */ /* > */ /* > \param[in] A */ /* > \verbatim */ /* > A is COMPLEX array, dimension (LDA,N) */ /* > The triangular matrix A. If UPLO = 'U', the leading n by n */ /* > upper triangular part of the array A contains the upper */ /* > triangular matrix, and the strictly lower triangular part of */ /* > A is not referenced. If UPLO = 'L', the leading n by n lower */ /* > triangular part of the array A contains the lower triangular */ /* > matrix, and the strictly upper triangular part of A is not */ /* > referenced. If DIAG = 'U', the diagonal elements of A are */ /* > also not referenced and are assumed to be 1. */ /* > \endverbatim */ /* > */ /* > \param[in] LDA */ /* > \verbatim */ /* > LDA is INTEGER */ /* > The leading dimension of the array A. LDA >= f2cmax (1,N). */ /* > \endverbatim */ /* > */ /* > \param[in,out] X */ /* > \verbatim */ /* > X is COMPLEX array, dimension (N) */ /* > On entry, the right hand side b of the triangular system. */ /* > On exit, X is overwritten by the solution vector x. */ /* > \endverbatim */ /* > */ /* > \param[out] SCALE */ /* > \verbatim */ /* > SCALE is REAL */ /* > The scaling factor s for the triangular system */ /* > A * x = s*b, A**T * x = s*b, or A**H * x = s*b. */ /* > If SCALE = 0, the matrix A is singular or badly scaled, and */ /* > the vector x is an exact or approximate solution to A*x = 0. */ /* > \endverbatim */ /* > */ /* > \param[in,out] CNORM */ /* > \verbatim */ /* > CNORM is REAL array, dimension (N) */ /* > */ /* > If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */ /* > contains the norm of the off-diagonal part of the j-th column */ /* > of A. If TRANS = 'N', CNORM(j) must be greater than or equal */ /* > to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */ /* > must be greater than or equal to the 1-norm. */ /* > */ /* > If NORMIN = 'N', CNORM is an output argument and CNORM(j) */ /* > returns the 1-norm of the offdiagonal part of the j-th column */ /* > of A. */ /* > \endverbatim */ /* > */ /* > \param[out] INFO */ /* > \verbatim */ /* > INFO is INTEGER */ /* > = 0: successful exit */ /* > < 0: if INFO = -k, the k-th argument had an illegal value */ /* > \endverbatim */ /* Authors: */ /* ======== */ /* > \author Univ. of Tennessee */ /* > \author Univ. of California Berkeley */ /* > \author Univ. of Colorado Denver */ /* > \author NAG Ltd. */ /* > \date December 2016 */ /* > \ingroup complexOTHERauxiliary */ /* > \par Further Details: */ /* ===================== */ /* > */ /* > \verbatim */ /* > */ /* > A rough bound on x is computed; if that is less than overflow, CTRSV */ /* > is called, otherwise, specific code is used which checks for possible */ /* > overflow or divide-by-zero at every operation. */ /* > */ /* > A columnwise scheme is used for solving A*x = b. The basic algorithm */ /* > if A is lower triangular is */ /* > */ /* > x[1:n] := b[1:n] */ /* > for j = 1, ..., n */ /* > x(j) := x(j) / A(j,j) */ /* > x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */ /* > end */ /* > */ /* > Define bounds on the components of x after j iterations of the loop: */ /* > M(j) = bound on x[1:j] */ /* > G(j) = bound on x[j+1:n] */ /* > Initially, let M(0) = 0 and G(0) = f2cmax{x(i), i=1,...,n}. */ /* > */ /* > Then for iteration j+1 we have */ /* > M(j+1) <= G(j) / | A(j+1,j+1) | */ /* > G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */ /* > <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */ /* > */ /* > where CNORM(j+1) is greater than or equal to the infinity-norm of */ /* > column j+1 of A, not counting the diagonal. Hence */ /* > */ /* > G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */ /* > 1<=i<=j */ /* > and */ /* > */ /* > |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */ /* > 1<=i< j */ /* > */ /* > Since |x(j)| <= M(j), we use the Level 2 BLAS routine CTRSV if the */ /* > reciprocal of the largest M(j), j=1,..,n, is larger than */ /* > f2cmax(underflow, 1/overflow). */ /* > */ /* > The bound on x(j) is also used to determine when a step in the */ /* > columnwise method can be performed without fear of overflow. If */ /* > the computed bound is greater than a large constant, x is scaled to */ /* > prevent overflow, but if the bound overflows, x is set to 0, x(j) to */ /* > 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */ /* > */ /* > Similarly, a row-wise scheme is used to solve A**T *x = b or */ /* > A**H *x = b. The basic algorithm for A upper triangular is */ /* > */ /* > for j = 1, ..., n */ /* > x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */ /* > end */ /* > */ /* > We simultaneously compute two bounds */ /* > G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */ /* > M(j) = bound on x(i), 1<=i<=j */ /* > */ /* > The initial values are G(0) = 0, M(0) = f2cmax{b(i), i=1,..,n}, and we */ /* > add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */ /* > Then the bound on x(j) is */ /* > */ /* > M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */ /* > */ /* > <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */ /* > 1<=i<=j */ /* > */ /* > and we can safely call CTRSV if 1/M(n) and 1/G(n) are both greater */ /* > than f2cmax(underflow, 1/overflow). */ /* > \endverbatim */ /* > */ /* ===================================================================== */ /* Subroutine */ int clatrs_(char *uplo, char *trans, char *diag, char * normin, integer *n, complex *a, integer *lda, complex *x, real *scale, real *cnorm, integer *info) { /* System generated locals */ integer a_dim1, a_offset, i__1, i__2, i__3, i__4, i__5; real r__1, r__2, r__3, r__4; complex q__1, q__2, q__3, q__4; /* Local variables */ integer jinc; real xbnd; integer imax; real tmax; complex tjjs; real xmax, grow; integer i__, j; extern /* Complex */ VOID cdotc_(complex *, integer *, complex *, integer *, complex *, integer *); extern logical lsame_(char *, char *); extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *); real tscal; complex uscal; integer jlast; extern /* Complex */ VOID cdotu_(complex *, integer *, complex *, integer *, complex *, integer *); complex csumj; extern /* Subroutine */ int caxpy_(integer *, complex *, complex *, integer *, complex *, integer *); logical upper; extern /* Subroutine */ int ctrsv_(char *, char *, char *, integer *, complex *, integer *, complex *, integer *), slabad_(real *, real *); real xj; extern integer icamax_(integer *, complex *, integer *); extern /* Complex */ VOID cladiv_(complex *, complex *, complex *); extern real slamch_(char *); extern /* Subroutine */ int csscal_(integer *, real *, complex *, integer *), xerbla_(char *, integer *, ftnlen); real bignum; extern integer isamax_(integer *, real *, integer *); extern real scasum_(integer *, complex *, integer *); logical notran; integer jfirst; real smlnum; logical nounit; real rec, tjj; /* -- LAPACK auxiliary routine (version 3.7.0) -- */ /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ /* December 2016 */ /* ===================================================================== */ /* Parameter adjustments */ a_dim1 = *lda; a_offset = 1 + a_dim1 * 1; a -= a_offset; --x; --cnorm; /* Function Body */ *info = 0; upper = lsame_(uplo, "U"); notran = lsame_(trans, "N"); nounit = lsame_(diag, "N"); /* Test the input parameters. */ if (! upper && ! lsame_(uplo, "L")) { *info = -1; } else if (! notran && ! lsame_(trans, "T") && ! lsame_(trans, "C")) { *info = -2; } else if (! nounit && ! lsame_(diag, "U")) { *info = -3; } else if (! lsame_(normin, "Y") && ! lsame_(normin, "N")) { *info = -4; } else if (*n < 0) { *info = -5; } else if (*lda < f2cmax(1,*n)) { *info = -7; } if (*info != 0) { i__1 = -(*info); xerbla_("CLATRS", &i__1, (ftnlen)6); return 0; } /* Quick return if possible */ if (*n == 0) { return 0; } /* Determine machine dependent parameters to control overflow. */ smlnum = slamch_("Safe minimum"); bignum = 1.f / smlnum; slabad_(&smlnum, &bignum); smlnum /= slamch_("Precision"); bignum = 1.f / smlnum; *scale = 1.f; if (lsame_(normin, "N")) { /* Compute the 1-norm of each column, not including the diagonal. */ if (upper) { /* A is upper triangular. */ i__1 = *n; for (j = 1; j <= i__1; ++j) { i__2 = j - 1; cnorm[j] = scasum_(&i__2, &a[j * a_dim1 + 1], &c__1); /* L10: */ } } else { /* A is lower triangular. */ i__1 = *n - 1; for (j = 1; j <= i__1; ++j) { i__2 = *n - j; cnorm[j] = scasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1); /* L20: */ } cnorm[*n] = 0.f; } } /* Scale the column norms by TSCAL if the maximum element in CNORM is */ /* greater than BIGNUM/2. */ imax = isamax_(n, &cnorm[1], &c__1); tmax = cnorm[imax]; if (tmax <= bignum * .5f) { tscal = 1.f; } else { tscal = .5f / (smlnum * tmax); sscal_(n, &tscal, &cnorm[1], &c__1); } /* Compute a bound on the computed solution vector to see if the */ /* Level 2 BLAS routine CTRSV can be used. */ xmax = 0.f; i__1 = *n; for (j = 1; j <= i__1; ++j) { /* Computing MAX */ i__2 = j; r__3 = xmax, r__4 = (r__1 = x[i__2].r / 2.f, abs(r__1)) + (r__2 = r_imag(&x[j]) / 2.f, abs(r__2)); xmax = f2cmax(r__3,r__4); /* L30: */ } xbnd = xmax; if (notran) { /* Compute the growth in A * x = b. */ if (upper) { jfirst = *n; jlast = 1; jinc = -1; } else { jfirst = 1; jlast = *n; jinc = 1; } if (tscal != 1.f) { grow = 0.f; goto L60; } if (nounit) { /* A is non-unit triangular. */ /* Compute GROW = 1/G(j) and XBND = 1/M(j). */ /* Initially, G(0) = f2cmax{x(i), i=1,...,n}. */ grow = .5f / f2cmax(xbnd,smlnum); xbnd = grow; i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L60; } i__3 = j + j * a_dim1; tjjs.r = a[i__3].r, tjjs.i = a[i__3].i; tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs( r__2)); if (tjj >= smlnum) { /* M(j) = G(j-1) / abs(A(j,j)) */ /* Computing MIN */ r__1 = xbnd, r__2 = f2cmin(1.f,tjj) * grow; xbnd = f2cmin(r__1,r__2); } else { /* M(j) could overflow, set XBND to 0. */ xbnd = 0.f; } if (tjj + cnorm[j] >= smlnum) { /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */ grow *= tjj / (tjj + cnorm[j]); } else { /* G(j) could overflow, set GROW to 0. */ grow = 0.f; } /* L40: */ } grow = xbnd; } else { /* A is unit triangular. */ /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */ /* Computing MIN */ r__1 = 1.f, r__2 = .5f / f2cmax(xbnd,smlnum); grow = f2cmin(r__1,r__2); i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L60; } /* G(j) = G(j-1)*( 1 + CNORM(j) ) */ grow *= 1.f / (cnorm[j] + 1.f); /* L50: */ } } L60: ; } else { /* Compute the growth in A**T * x = b or A**H * x = b. */ if (upper) { jfirst = 1; jlast = *n; jinc = 1; } else { jfirst = *n; jlast = 1; jinc = -1; } if (tscal != 1.f) { grow = 0.f; goto L90; } if (nounit) { /* A is non-unit triangular. */ /* Compute GROW = 1/G(j) and XBND = 1/M(j). */ /* Initially, M(0) = f2cmax{x(i), i=1,...,n}. */ grow = .5f / f2cmax(xbnd,smlnum); xbnd = grow; i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L90; } /* G(j) = f2cmax( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */ xj = cnorm[j] + 1.f; /* Computing MIN */ r__1 = grow, r__2 = xbnd / xj; grow = f2cmin(r__1,r__2); i__3 = j + j * a_dim1; tjjs.r = a[i__3].r, tjjs.i = a[i__3].i; tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs( r__2)); if (tjj >= smlnum) { /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */ if (xj > tjj) { xbnd *= tjj / xj; } } else { /* M(j) could overflow, set XBND to 0. */ xbnd = 0.f; } /* L70: */ } grow = f2cmin(grow,xbnd); } else { /* A is unit triangular. */ /* Compute GROW = 1/G(j), where G(0) = f2cmax{x(i), i=1,...,n}. */ /* Computing MIN */ r__1 = 1.f, r__2 = .5f / f2cmax(xbnd,smlnum); grow = f2cmin(r__1,r__2); i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Exit the loop if the growth factor is too small. */ if (grow <= smlnum) { goto L90; } /* G(j) = ( 1 + CNORM(j) )*G(j-1) */ xj = cnorm[j] + 1.f; grow /= xj; /* L80: */ } } L90: ; } if (grow * tscal > smlnum) { /* Use the Level 2 BLAS solve if the reciprocal of the bound on */ /* elements of X is not too small. */ ctrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1); } else { /* Use a Level 1 BLAS solve, scaling intermediate results. */ if (xmax > bignum * .5f) { /* Scale X so that its components are less than or equal to */ /* BIGNUM in absolute value. */ *scale = bignum * .5f / xmax; csscal_(n, scale, &x[1], &c__1); xmax = bignum; } else { xmax *= 2.f; } if (notran) { /* Solve A * x = b */ i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */ i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), abs(r__2)); if (nounit) { i__3 = j + j * a_dim1; q__1.r = tscal * a[i__3].r, q__1.i = tscal * a[i__3].i; tjjs.r = q__1.r, tjjs.i = q__1.i; } else { tjjs.r = tscal, tjjs.i = 0.f; if (tscal == 1.f) { goto L105; } } tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs( r__2)); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.f) { if (xj > tjj * bignum) { /* Scale x by 1/b(j). */ rec = 1.f / xj; csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } i__3 = j; cladiv_(&q__1, &x[j], &tjjs); x[i__3].r = q__1.r, x[i__3].i = q__1.i; i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]) , abs(r__2)); } else if (tjj > 0.f) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */ /* to avoid overflow when dividing by A(j,j). */ rec = tjj * bignum / xj; if (cnorm[j] > 1.f) { /* Scale by 1/CNORM(j) to avoid overflow when */ /* multiplying x(j) times column j. */ rec /= cnorm[j]; } csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } i__3 = j; cladiv_(&q__1, &x[j], &tjjs); x[i__3].r = q__1.r, x[i__3].i = q__1.i; i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]) , abs(r__2)); } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */ /* scale = 0, and compute a solution to A*x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__; x[i__4].r = 0.f, x[i__4].i = 0.f; /* L100: */ } i__3 = j; x[i__3].r = 1.f, x[i__3].i = 0.f; xj = 1.f; *scale = 0.f; xmax = 0.f; } L105: /* Scale x if necessary to avoid overflow when adding a */ /* multiple of column j of A. */ if (xj > 1.f) { rec = 1.f / xj; if (cnorm[j] > (bignum - xmax) * rec) { /* Scale x by 1/(2*abs(x(j))). */ rec *= .5f; csscal_(n, &rec, &x[1], &c__1); *scale *= rec; } } else if (xj * cnorm[j] > bignum - xmax) { /* Scale x by 1/2. */ csscal_(n, &c_b36, &x[1], &c__1); *scale *= .5f; } if (upper) { if (j > 1) { /* Compute the update */ /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */ i__3 = j - 1; i__4 = j; q__2.r = -x[i__4].r, q__2.i = -x[i__4].i; q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i; caxpy_(&i__3, &q__1, &a[j * a_dim1 + 1], &c__1, &x[1], &c__1); i__3 = j - 1; i__ = icamax_(&i__3, &x[1], &c__1); i__3 = i__; xmax = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag( &x[i__]), abs(r__2)); } } else { if (j < *n) { /* Compute the update */ /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */ i__3 = *n - j; i__4 = j; q__2.r = -x[i__4].r, q__2.i = -x[i__4].i; q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i; caxpy_(&i__3, &q__1, &a[j + 1 + j * a_dim1], &c__1, & x[j + 1], &c__1); i__3 = *n - j; i__ = j + icamax_(&i__3, &x[j + 1], &c__1); i__3 = i__; xmax = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag( &x[i__]), abs(r__2)); } } /* L110: */ } } else if (lsame_(trans, "T")) { /* Solve A**T * x = b */ i__2 = jlast; i__1 = jinc; for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) { /* Compute x(j) = b(j) - sum A(k,j)*x(k). */ /* k<>j */ i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), abs(r__2)); uscal.r = tscal, uscal.i = 0.f; rec = 1.f / f2cmax(xmax,1.f); if (cnorm[j] > (bignum - xj) * rec) { /* If x(j) could overflow, scale x by 1/(2*XMAX). */ rec *= .5f; if (nounit) { i__3 = j + j * a_dim1; q__1.r = tscal * a[i__3].r, q__1.i = tscal * a[i__3] .i; tjjs.r = q__1.r, tjjs.i = q__1.i; } else { tjjs.r = tscal, tjjs.i = 0.f; } tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(r__2)); if (tjj > 1.f) { /* Divide by A(j,j) when scaling x if A(j,j) > 1. */ /* Computing MIN */ r__1 = 1.f, r__2 = rec * tjj; rec = f2cmin(r__1,r__2); cladiv_(&q__1, &uscal, &tjjs); uscal.r = q__1.r, uscal.i = q__1.i; } if (rec < 1.f) { csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } csumj.r = 0.f, csumj.i = 0.f; if (uscal.r == 1.f && uscal.i == 0.f) { /* If the scaling needed for A in the dot product is 1, */ /* call CDOTU to perform the dot product. */ if (upper) { i__3 = j - 1; cdotu_(&q__1, &i__3, &a[j * a_dim1 + 1], &c__1, &x[1], &c__1); csumj.r = q__1.r, csumj.i = q__1.i; } else if (j < *n) { i__3 = *n - j; cdotu_(&q__1, &i__3, &a[j + 1 + j * a_dim1], &c__1, & x[j + 1], &c__1); csumj.r = q__1.r, csumj.i = q__1.i; } } else { /* Otherwise, use in-line code for the dot product. */ if (upper) { i__3 = j - 1; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__ + j * a_dim1; q__3.r = a[i__4].r * uscal.r - a[i__4].i * uscal.i, q__3.i = a[i__4].r * uscal.i + a[ i__4].i * uscal.r; i__5 = i__; q__2.r = q__3.r * x[i__5].r - q__3.i * x[i__5].i, q__2.i = q__3.r * x[i__5].i + q__3.i * x[ i__5].r; q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + q__2.i; csumj.r = q__1.r, csumj.i = q__1.i; /* L120: */ } } else if (j < *n) { i__3 = *n; for (i__ = j + 1; i__ <= i__3; ++i__) { i__4 = i__ + j * a_dim1; q__3.r = a[i__4].r * uscal.r - a[i__4].i * uscal.i, q__3.i = a[i__4].r * uscal.i + a[ i__4].i * uscal.r; i__5 = i__; q__2.r = q__3.r * x[i__5].r - q__3.i * x[i__5].i, q__2.i = q__3.r * x[i__5].i + q__3.i * x[ i__5].r; q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + q__2.i; csumj.r = q__1.r, csumj.i = q__1.i; /* L130: */ } } } q__1.r = tscal, q__1.i = 0.f; if (uscal.r == q__1.r && uscal.i == q__1.i) { /* Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */ /* was not used to scale the dotproduct. */ i__3 = j; i__4 = j; q__1.r = x[i__4].r - csumj.r, q__1.i = x[i__4].i - csumj.i; x[i__3].r = q__1.r, x[i__3].i = q__1.i; i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]) , abs(r__2)); if (nounit) { i__3 = j + j * a_dim1; q__1.r = tscal * a[i__3].r, q__1.i = tscal * a[i__3] .i; tjjs.r = q__1.r, tjjs.i = q__1.i; } else { tjjs.r = tscal, tjjs.i = 0.f; if (tscal == 1.f) { goto L145; } } /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */ tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(r__2)); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.f) { if (xj > tjj * bignum) { /* Scale X by 1/abs(x(j)). */ rec = 1.f / xj; csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } i__3 = j; cladiv_(&q__1, &x[j], &tjjs); x[i__3].r = q__1.r, x[i__3].i = q__1.i; } else if (tjj > 0.f) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */ rec = tjj * bignum / xj; csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } i__3 = j; cladiv_(&q__1, &x[j], &tjjs); x[i__3].r = q__1.r, x[i__3].i = q__1.i; } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */ /* scale = 0 and compute a solution to A**T *x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__; x[i__4].r = 0.f, x[i__4].i = 0.f; /* L140: */ } i__3 = j; x[i__3].r = 1.f, x[i__3].i = 0.f; *scale = 0.f; xmax = 0.f; } L145: ; } else { /* Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */ /* product has already been divided by 1/A(j,j). */ i__3 = j; cladiv_(&q__2, &x[j], &tjjs); q__1.r = q__2.r - csumj.r, q__1.i = q__2.i - csumj.i; x[i__3].r = q__1.r, x[i__3].i = q__1.i; } /* Computing MAX */ i__3 = j; r__3 = xmax, r__4 = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), abs(r__2)); xmax = f2cmax(r__3,r__4); /* L150: */ } } else { /* Solve A**H * x = b */ i__1 = jlast; i__2 = jinc; for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) { /* Compute x(j) = b(j) - sum A(k,j)*x(k). */ /* k<>j */ i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), abs(r__2)); uscal.r = tscal, uscal.i = 0.f; rec = 1.f / f2cmax(xmax,1.f); if (cnorm[j] > (bignum - xj) * rec) { /* If x(j) could overflow, scale x by 1/(2*XMAX). */ rec *= .5f; if (nounit) { r_cnjg(&q__2, &a[j + j * a_dim1]); q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i; tjjs.r = q__1.r, tjjs.i = q__1.i; } else { tjjs.r = tscal, tjjs.i = 0.f; } tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(r__2)); if (tjj > 1.f) { /* Divide by A(j,j) when scaling x if A(j,j) > 1. */ /* Computing MIN */ r__1 = 1.f, r__2 = rec * tjj; rec = f2cmin(r__1,r__2); cladiv_(&q__1, &uscal, &tjjs); uscal.r = q__1.r, uscal.i = q__1.i; } if (rec < 1.f) { csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } csumj.r = 0.f, csumj.i = 0.f; if (uscal.r == 1.f && uscal.i == 0.f) { /* If the scaling needed for A in the dot product is 1, */ /* call CDOTC to perform the dot product. */ if (upper) { i__3 = j - 1; cdotc_(&q__1, &i__3, &a[j * a_dim1 + 1], &c__1, &x[1], &c__1); csumj.r = q__1.r, csumj.i = q__1.i; } else if (j < *n) { i__3 = *n - j; cdotc_(&q__1, &i__3, &a[j + 1 + j * a_dim1], &c__1, & x[j + 1], &c__1); csumj.r = q__1.r, csumj.i = q__1.i; } } else { /* Otherwise, use in-line code for the dot product. */ if (upper) { i__3 = j - 1; for (i__ = 1; i__ <= i__3; ++i__) { r_cnjg(&q__4, &a[i__ + j * a_dim1]); q__3.r = q__4.r * uscal.r - q__4.i * uscal.i, q__3.i = q__4.r * uscal.i + q__4.i * uscal.r; i__4 = i__; q__2.r = q__3.r * x[i__4].r - q__3.i * x[i__4].i, q__2.i = q__3.r * x[i__4].i + q__3.i * x[ i__4].r; q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + q__2.i; csumj.r = q__1.r, csumj.i = q__1.i; /* L160: */ } } else if (j < *n) { i__3 = *n; for (i__ = j + 1; i__ <= i__3; ++i__) { r_cnjg(&q__4, &a[i__ + j * a_dim1]); q__3.r = q__4.r * uscal.r - q__4.i * uscal.i, q__3.i = q__4.r * uscal.i + q__4.i * uscal.r; i__4 = i__; q__2.r = q__3.r * x[i__4].r - q__3.i * x[i__4].i, q__2.i = q__3.r * x[i__4].i + q__3.i * x[ i__4].r; q__1.r = csumj.r + q__2.r, q__1.i = csumj.i + q__2.i; csumj.r = q__1.r, csumj.i = q__1.i; /* L170: */ } } } q__1.r = tscal, q__1.i = 0.f; if (uscal.r == q__1.r && uscal.i == q__1.i) { /* Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j) */ /* was not used to scale the dotproduct. */ i__3 = j; i__4 = j; q__1.r = x[i__4].r - csumj.r, q__1.i = x[i__4].i - csumj.i; x[i__3].r = q__1.r, x[i__3].i = q__1.i; i__3 = j; xj = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]) , abs(r__2)); if (nounit) { r_cnjg(&q__2, &a[j + j * a_dim1]); q__1.r = tscal * q__2.r, q__1.i = tscal * q__2.i; tjjs.r = q__1.r, tjjs.i = q__1.i; } else { tjjs.r = tscal, tjjs.i = 0.f; if (tscal == 1.f) { goto L185; } } /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */ tjj = (r__1 = tjjs.r, abs(r__1)) + (r__2 = r_imag(&tjjs), abs(r__2)); if (tjj > smlnum) { /* abs(A(j,j)) > SMLNUM: */ if (tjj < 1.f) { if (xj > tjj * bignum) { /* Scale X by 1/abs(x(j)). */ rec = 1.f / xj; csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } } i__3 = j; cladiv_(&q__1, &x[j], &tjjs); x[i__3].r = q__1.r, x[i__3].i = q__1.i; } else if (tjj > 0.f) { /* 0 < abs(A(j,j)) <= SMLNUM: */ if (xj > tjj * bignum) { /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */ rec = tjj * bignum / xj; csscal_(n, &rec, &x[1], &c__1); *scale *= rec; xmax *= rec; } i__3 = j; cladiv_(&q__1, &x[j], &tjjs); x[i__3].r = q__1.r, x[i__3].i = q__1.i; } else { /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */ /* scale = 0 and compute a solution to A**H *x = 0. */ i__3 = *n; for (i__ = 1; i__ <= i__3; ++i__) { i__4 = i__; x[i__4].r = 0.f, x[i__4].i = 0.f; /* L180: */ } i__3 = j; x[i__3].r = 1.f, x[i__3].i = 0.f; *scale = 0.f; xmax = 0.f; } L185: ; } else { /* Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot */ /* product has already been divided by 1/A(j,j). */ i__3 = j; cladiv_(&q__2, &x[j], &tjjs); q__1.r = q__2.r - csumj.r, q__1.i = q__2.i - csumj.i; x[i__3].r = q__1.r, x[i__3].i = q__1.i; } /* Computing MAX */ i__3 = j; r__3 = xmax, r__4 = (r__1 = x[i__3].r, abs(r__1)) + (r__2 = r_imag(&x[j]), abs(r__2)); xmax = f2cmax(r__3,r__4); /* L190: */ } } *scale /= tscal; } /* Scale the column norms by 1/TSCAL for return. */ if (tscal != 1.f) { r__1 = 1.f / tscal; sscal_(n, &r__1, &cnorm[1], &c__1); } return 0; /* End of CLATRS */ } /* clatrs_ */
the_stack_data/140766693.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/inotify.h> #include <sys/select.h> #include <sys/time.h> #include <sys/types.h> int main(int argc, char** argv) { int fd = -1; int wd1 = -1; int wd2 = -1; char buf[1024]; int ret; struct inotify_event* event; fd_set fds; struct timeval timeout; fd = inotify_init(); if (fd == -1) { printf("inotify_init() fail\n"); return -1; } wd1 = inotify_add_watch(fd, ".", IN_CREATE | IN_DELETE); if (wd1 == -1) { printf("add_watch1() fail\n"); goto err; } wd2 = inotify_add_watch(fd, ".", IN_CREATE | IN_DELETE); if (wd2 == -1) { printf("add_watch2() fail\n"); goto err; } while (1) { #if 0 ret = read(fd, buf, sizeof(buf)); if (ret == -1) { printf("read() fail\n"); break; } #endif FD_ZERO(&fds); FD_SET(fd, &fds); FD_SET(STDIN_FILENO, &fds); timeout.tv_sec = 5; timeout.tv_usec = 0; ret = select(fd > STDIN_FILENO ? fd + 1 : STDIN_FILENO + 1, &fds, NULL, NULL, &timeout); if (ret == -1) { goto err; } else if (ret == 0) { printf("select() timeout occur!!\n"); } else if (ret > 0) { if (FD_ISSET(fd, &fds)) { ret = read(fd, buf, sizeof(buf)); if (ret == -1) { printf("read() fail\n"); break; } event = (struct inotify_event*)&buf[0]; while (ret > 0) { if (event->mask & IN_CREATE) { printf("file %s is created\n", event->name); } if (event->mask & IN_DELETE) { printf("file %s is deleted\n", event->name); } event = (struct inotify_event*)((char*)event + sizeof(struct inotify_event) + event->len); ret -= sizeof(struct inotify_event) + event->len; } } else if (FD_ISSET(STDIN_FILENO, &fds)) { memset(buf, 0, sizeof(buf)); ret = read(STDIN_FILENO, buf, sizeof(buf)); if (ret == -1) { printf("read() fail\n"); break; } printf("user input [%s]\n", buf); } } } close(wd2); close(wd1); close(fd); return 0; err: if (fd >= 0) { close(fd); } if (wd1 >= 0) { close(wd1); } if (wd2 >= 0) { close(wd2); } return -1; }
the_stack_data/35491.c
static int INSERT_HERE; // a marker used by the injectSnippet test // This function declaration must be present in order to insert a function call that would reference this function. // void fputs(v1, stderr); // typedef int FILE; // struct __FILE {}; // typedef struct __FILE FILE; // int fputs(const char *s, FILE *stream); // int *stderr; int ipoint1() { int x = 1; INSERT_HERE; return 0; } int main() { return 0; }
the_stack_data/1142179.c
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #define MAXOP 100 #define NUMBER '0' #define MAXVAL 100 #define BUFSIZE 100 int sp = 0; double val[MAXVAL]; int getop(char []); void push(double); double pop(void); int getch(void); void ungetch(int); int main() { int type; double op2; char s[MAXOP]; int end = 0; while (end != 1 && (type = getop(s)) != EOF) { switch(type) { case NUMBER: push(atof(s)); break; case '+': push(pop() + pop()); break; case '*': push(pop() * pop()); break; case '-': op2 = pop(); push(pop() - op2); break; case '/': op2 = pop(); if (op2 != 0.0) { push(pop() / op2); } break; case '=': printf("\t%.8g\n", pop()); end = 1; break; case '%': op2 = pop(); push((int)pop() % (int)op2); break; default: printf("error: unkown command %s\n", s); break; } } return 0; } void push(double f) { if (sp < MAXVAL) { val[sp++] = f; } } double pop(void) { if (sp > 0) { return val[--sp]; } } int getop(char s[]) { scanf("%s", s); if (isdigit(s[0])) { return NUMBER; } else { return s[0]; } } char buf[BUFSIZE]; int bufp = 0; int getch(void) { return (bufp > 0) ? buf[--bufp] : getchar(); } void ungetch(int c) { if (bufp < BUFSIZE) { buf[bufp++] = c; } }
the_stack_data/198579586.c
#include <stdio.h> #define IN 1 /* inside a word */ #define OUT 0 /* outside a word */ int main() { int c, previous, state; state = OUT; while ((c = getchar()) != EOF) { if (c == ' ' || c == '\n' || c == '\t') { state = OUT; if (previous == IN) putchar('\n'); } else if (state == OUT) { putchar(c); state = IN; } else { putchar(c); } previous = state; } return 0; }
the_stack_data/1204348.c
//+depends fgets fgetc fileno read //+macro gets(F) fgets(F,0xfffffff,stdin)
the_stack_data/1082092.c
#include <stdio.h> #include <unistd.h> #include <sys/wait.h> #include <sys/time.h> #include <sys/mman.h> // static double *glob_var; // for use on the last two parts int main(void) { char *rcvrs[] = {"./fast_receiver", "./slow_receiver", "./unreliable_receiver"}; char *sndrs[] = {"./fast_sender", "./slow_sender", "./unreliable_sender"}; int nrcvrs = 2; int nsndrs = 2; for (int i=0; i<nrcvrs; i++) { for (int j=0; j<nsndrs; j++) { struct timeval start, end; double dt; gettimeofday(&start, NULL); printf("I would like to test %s with %s\n", rcvrs[i], sndrs[j]); sleep(1); gettimeofday(&end, NULL); dt = end.tv_sec-start.tv_sec+(end.tv_usec-start.tv_usec)/1000000.0; printf("Done testing %s with %s, %f sec required\n", sndrs[j], rcvrs[i], dt); } } return 0; }
the_stack_data/150140225.c
#include <stdio.h> int main(int argc, char *argv[]) { int i; // printf("This program is named '%s'.\n", argv[0]); if (argc == 1) { // only name printf("NO_ARGS\n"); } for (i = 1; i < argc; ++i) { printf("%s\n", argv[i]); } return 0; }
the_stack_data/161080887.c
#include <stdio.h> #include <stdlib.h> int main(){ int i, j, k; system("cls"); for(i=1;i<=4;i++){ k = 1; for(j=1;j<=7;j++){ if(j>=5-i && j<=3+i){ printf("%d", k); if(j < 4){ k++; }else{ k--; } }else{ printf(" "); } } printf("\n"); } return 0; }
the_stack_data/115670.c
#include <stdio.h> #include <stdlib.h> int main() { int i; int array[5]={9,2,3,4,1}; InsertionSort(array,5); for(i=0;i<5;i++) { printf("%d ",array[i]); } return 0; } void InsertionSort(int arr[],int size) { int x,temp,k; for(x=1;x<size;x++) { temp=arr[x]; for(k=x;k>0 && temp<arr[k-1];k--) { arr[k]=arr[k-1]; } arr[k]=temp; } }
the_stack_data/132136.c
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdlib.h> #include <stdbool.h> #include <errno.h> #include <sys/time.h> #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <fcntl.h> #include <sys/ioctl.h> #include <net/route.h> #define LOCAL_IP "127.0.0.1" int main(int argc, char* argv[]) { bool wait = false; int opt, port; while ((opt = getopt(argc, argv, "w")) != -1) { switch (opt) { case 'w': wait = true; break; default: break; } } if (argc > optind) { port = atoi(argv[optind]); if (port <= 0) { printf("unsupported port %d\n", port); return -1; } } else { port = 15003; } printf("日志监听端口: %d\n", port); struct sockaddr_in addr; memset(&addr, 0x00, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; addr.sin_addr.s_addr = inet_addr(LOCAL_IP); addr.sin_port = htons(port); char buffer[1024*10]; memset(buffer, 0x00, sizeof(buffer)); size_t len; int fd = -1, ret; recreate: if (fd > 0) { close(fd); } fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (fd == -1) { perror("socket"); return -1; } reconnect: ret = connect(fd, (struct sockaddr*)&addr, sizeof(addr)); if (ret == -1 && errno != EISCONN) { if (wait) { usleep(100); goto reconnect; } perror("connect"); return -1; } printf("\n\n"); while (true) { len = recv(fd, buffer, sizeof(buffer) - 16, 0); if (len == -1) { if (wait) { goto reconnect; } else { perror("recv"); return -1; } } else if (len > 0) { buffer[len] = '\0'; printf("%s", buffer); } else if (len == 0) { printf("\nDisconnected.\n\n"); if (wait) { goto recreate; } else { break; } } } close(fd); return 0; }
the_stack_data/132953587.c
extern void __VERIFIER_error() __attribute__ ((__noreturn__)); void __VERIFIER_assert(int cond) { if(!(cond)) { ERROR: __VERIFIER_error(); } } #define N 250 int main( ) { int a[N]; int i; int r = 1; for ( i = 1 ; i < N && r ; i++ ) { int j; for ( j = i-1 ; j >= 0 && r ; j-- ) { if ( a[i] == a[j] ) { r = 1; } } } if ( r ) { int x; int y; for ( x = 0 ; x < N ; x++ ) { for ( y = x+1 ; y < N ; y++ ) { __VERIFIER_assert( a[x] != a[y] ); } } } return 0; }
the_stack_data/1222786.c
#include <stdio.h> #include <stdlib.h> struct lista { char info; struct lista *prox; }; typedef struct lista TLista; TLista* inicializa() { return NULL; } TLista* insere(TLista* l, char c) { TLista* novo = (TLista*) malloc(sizeof(TLista)); novo->info = c; novo->prox = l; return novo; } void imprime(TLista* l) { TLista* aux; for (aux=l; aux != NULL; aux = aux->prox) { printf("info = %c\n", aux->info); } } void imprimeInvertido(TLista* l) { if (!l->prox) { printf("info = %c\n", l->info); return; } imprimeInvertido(l->prox); printf("info = %c\n", l->info); } int tamanho(TLista* l) { int tamanho = 0; TLista *pl = l; #ifdef HARDCORE for (; pl; pl = pl->prox, tamanho++); #else while (pl) { tamanho++; pl = pl->prox; } #endif return tamanho; } TLista* retira(TLista* l, char c) { TLista *pl = l, *aux = l; if (!pl) { return NULL; } else if (pl->info == c) { pl = pl->prox; free(aux); return pl; } else { while ((aux = pl->prox) != NULL) { if (aux->info == c) { pl->prox = aux->prox; free(aux); break; } pl = aux; } } return l; } TLista* limpar(TLista* l) { #ifdef HARDCORE while ((l = retira(l, l->info))); #else while (l) { l = retira(l, l->info); } #endif return NULL; } int main (int argc, char* argv[]) { TLista* Listax; Listax = inicializa(); Listax = insere(Listax, 'D'); Listax = insere(Listax, 'I'); Listax = insere(Listax, 'O'); Listax = insere(Listax, 'L'); Listax = insere(Listax, 'A'); Listax = insere(Listax, 'X'); Listax = insere(Listax, 'O'); printf("Tamanho: %d\n", tamanho(Listax)); Listax = retira(Listax,'D'); Listax = retira(Listax,'I'); Listax = retira(Listax,'X'); Listax = retira(Listax,'O'); printf("Tamanho: %d\n", tamanho(Listax)); Listax = retira(Listax,'Z'); printf("Tamanho: %d\n", tamanho(Listax)); imprime(Listax); imprimeInvertido(Listax); Listax = limpar(Listax); printf("Tamanho: %d\n", tamanho(Listax)); return 0; }
the_stack_data/75983.c
#include <stdio.h> #include <stdlib.h> #include <fcntl.h> #include <unistd.h> #include <linux/cdrom.h> #include <sys/ioctl.h> int main(int argc, char* argv[]) { int fd = open(argv[1], O_RDONLY); // Eject CDROM ioctl(fd, CDROMEJECT); close(fd); return (EXIT_SUCCESS); }
the_stack_data/170451920.c
/* * Sean Fischer * 9/21/2019 * * By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see * that the 6th prime is 13. * * What is the 10 001st prime number? */ #include <math.h> #include <stdio.h> #include <stdlib.h> #define TRUE 1 #define FALSE 0 #define MAX_N 10001 int is_prime(long n) { // https://en.wikipedia.org/wiki/Primality_test#Pseudocode if (n <= 3) { return n > 1; } else if (n % 2 == 0 || n % 3 == 0) { return FALSE; } long i = 5; while (i * i <= n) { if (n % i == 0 || n % (i + 2) == 0) { return FALSE; } i = i + 6; } return TRUE; return 0; } void first_n_primes(long *set, int n) { long k = 1; int i = 2; long tmp; set[0] = 2; set[1] = 3; while (i < n) { tmp = 6 * k; if (is_prime(tmp - 1)) { set[i] = tmp - 1; i++; } if (is_prime(tmp + 1)) { set[i] = tmp + 1; i++; } k++; } } int main(int argc, char *argv[]) { long *set = malloc(MAX_N * sizeof(long)); first_n_primes(set, MAX_N); printf("%li\n", set[MAX_N - 1]); return 0; }
the_stack_data/6388292.c
#include <stdio.h> #define N 8 int idx(int row, int col) { return col + N * row; } int is_attacking_diag(int* board, int row, int col, int dx, int dy) { while (1) { row += dx; col += dy; if (row < 0 || N <= row || col < 0 || N <= col) { break; } if (board[idx(row, col)]) { return 1; } } return 0; } int is_attacking(int* board, int row, int col) { for (int i = 0; i < N; ++i) { if (board[idx(i, col)] || board[idx(row, i)]) { return 1; } } return is_attacking_diag(board, row, col, 1, 1) || is_attacking_diag(board, row, col, 1, -1) || is_attacking_diag(board, row, col, -1, 1) || is_attacking_diag(board, row, col, -1, -1); } void print_board(int* board) { for (int col = 0; col < N; ++col) { for (int row = 0; row < N; ++row) { putchar(board[idx(row, col)] ? 'O' : '.'); } putchar('\n'); } } void solve(int* board, int* num_solutions, int row) { for (int col = 0; col < N; ++col) { if (!is_attacking(board, row, col)) { board[idx(row, col)] = 1; if (row == N - 1) { printf("#%d\n", ++*num_solutions); print_board(board); putchar('\n'); } solve(board, num_solutions, row + 1); for (int i = idx(row, col); i < N * N; ++i) { board[i] = 0; } } } } int main(void) { int board[N * N] = {0}; int num_solutions = 0; solve(board, &num_solutions, 0); return 0; }
the_stack_data/45451015.c
double function_test(const double **a, const double **b){ double loss = 0; loss = (loss) - ((b[0][0]) * (log((a[0][0]) + (0.00001)))); loss = (loss) - ((b[0][1]) * (log((a[0][1]) + (0.00001)))); loss = (loss) - ((b[1][0]) * (log((a[1][0]) + (0.00001)))); loss = (loss) - ((b[1][1]) * (log((a[1][1]) + (0.00001)))); return loss; }
the_stack_data/178265466.c
#include<stdio.h> #define MAX 100 int queue[MAX], front=-1, rear=-1, i, op, val; void push(int [],int); void pop(int []); void display(int []); void main() { printf("\"1\" To push\n\"2\" To pop\n\"3\" To display your queue\n\"4\" To exit"); do { printf("\nEnter the operation: "); scanf("%d",&op); switch(op) { case 1: printf("Enter the number to be pushed on queue: "); scanf("%d",&val); push(queue,val); break; case 2: pop(queue); break; case 3: display(queue); break; case 4: break; default: printf("Option doesn\'t exist try again"); } }while(op!=4); } void push(int queue[],int val) { if(rear==MAX-1) printf("Queue Overflow\n"); else { if(front==-1) front=0; rear++; queue[rear] = val; } } void pop(int queue[]) { if(front==-1||front>rear) printf("Queue Underflow\n"); else { front++; if(front>rear) front = rear = -1; } } void display(int queue[]) { if(front==-1||front>rear) printf("Queue is empty\n"); else { for(i=front;i<=rear;i++) printf("%d ",queue[i]); } }
the_stack_data/445265.c
#include <stdio.h> #include <unistd.h> #include <string.h> /* for strncpy */ // for access to the ip and netmask #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netinet/in.h> #include <net/if.h> #include <arpa/inet.h> int getip(const char *iface, char *addr) { int fd; struct ifreq ifr; fd = socket(AF_INET, SOCK_DGRAM, 0); /* I want to get an IPv4 IP address */ ifr.ifr_addr.sa_family = AF_INET; /* Supply interface name, e.g. "eth0" */ strncpy(ifr.ifr_name, iface, IFNAMSIZ-1); if(ioctl(fd, SIOCGIFADDR, &ifr) == 0) { strcpy(addr, inet_ntoa(((struct sockaddr_in *) & ifr.ifr_addr)->sin_addr)); } else perror("Error"); close(fd); // printf("%s\n", addr); // display addr return 0; } int getmask(const char *iface, char *mask) { int fd; struct ifreq ifr; fd = socket(AF_INET, SOCK_DGRAM, 0); /* I want to get an IPv4 IP address */ ifr.ifr_addr.sa_family = AF_INET; /* Supply interface name, e.g. "eth0" */ strncpy(ifr.ifr_name, iface, IFNAMSIZ-1); if(ioctl(fd, SIOCGIFNETMASK, &ifr) == 0) { strcpy(mask, inet_ntoa(((struct sockaddr_in *) & ifr.ifr_addr)->sin_addr)); } else perror("Error"); close(fd); // printf("%s\n", mask); // display mask return 0; }
the_stack_data/242693.c
/* * Copyright (c) 2007, Kohsuke Ohtani * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include <time.h> struct tm * localtime(const time_t *timep) { static struct tm tm; return localtime_r(timep, &tm); }
the_stack_data/24643.c
/* * FITSIO.C -- Routines to load and save simple FITS files. * * ival = isFITS (fname) * loadFITS (fname, pixels, w, h, r, g, b, ncolors, * zsc, zr, &z1, &z2, nsample) * writeFITS (fp, pixels, pixtype, w,h, r,g,b, ncolors) * str = getFITSHdr (fname) * LoadFITS(fname, numcols) - loads a FITS file * WriteFITS(fp, pic, w, h, rmap, gmap, bmap, numcols) * * isFITS -- returns nonzero if the named file is a FITS file. * loadFITS -- reads a FITS file and returns the decoded pixel array and gray- * scale 8 bit colormap. The caller is responsible for freeing * the pixels buffer. * writeFITS -- performs the converse operation, writing the given pixel array * and colormap to the output Sun rasterfile. * Based on contributed FITS I/O software for XV by David Robinson. */ #include <stdio.h> #include <math.h> #include <ctype.h> #define NCARDS 36 #define BLOCKSIZE 2880 #define EPSILON 1.192e-7 #define CONTRAST 0.25 /* zscaling parameters */ #define NSAMPLE 1000 /* MONO returns total intensity of r,g,b components */ #define MONO(rd,gn,bl) (((rd)*11 + (gn)*16 + (bl)*5) >> 5) /*.33R+ .5G+ .17B*/ /* data types */ enum datatype { T_INT, T_LOG, T_REAL, T_NOVAL, T_STRING }; typedef unsigned char byte; #ifndef AIXV3 #ifndef OSF1 typedef unsigned char uchar; #endif #endif typedef struct { FILE *fp; /* file pointer */ int bitpix, size; /* bits per pixel, sizeof(unit) */ int naxis; /* number of axes */ long int axes[2]; /* size of each axis */ long int ndata; /* number of elements in data */ long int cpos; /* current position in data file */ char title[80]; /* image title */ int extend; /* image has extensions? */ int nextend; /* number of extensions */ float bscale, bzero; /* scaling parameters */ } FITS; /* Function prototypes */ #ifdef __STDC__ #include <stddef.h> #include <stdlib.h> static char *ftopen2d (FITS *fs, char *file, int *nx, int *ny, int *bitpix); static void ftclose (FITS *fs); static char *ftgbyte (FITS *fs, uchar *buffer, int nelem, int zsc, int zr, float *z1, float *z2, int nsample); static char *rdheader (FITS *fs); static char *wrheader (FILE *fp, int nx, int ny); static char *rdcard (char *card, char *name, enum datatype dtype, long int *kvalue, float *rvalue); static void wrcard (char *card, char *name, enum datatype dtype, int kvalue); static char *ftgdata (FITS *fs, void *buffer, int nelem); static char *ftfixdata (FITS *fs, void *buffer, int nelem); #else static char *ftopen2d (); static void ftclose (); static char *ftgbyte (); static char *rdheader (); static char *wrheader (); static char *rdcard (); static void wrcard (); static char *ftgdata (); static char *ftfixdata (); #endif /* ---------------- * Public routines. * ----------------*/ /* loadFits - Load a simple FITS file. */ char * loadFITS (fname, pix, nx, ny, r,g,b, ncolors, zsc, zr, z1, z2, nsample) char *fname; /* input filename */ uchar **pix; /* output pixels */ int *nx, *ny; /* dimensions */ uchar *r, *g, *b; /* colormap */ int *ncolors; /* number of colors */ int zsc, zr; /* z-scaling flags */ float *z1, *z2; /* zscale values */ int nsample; /* number of sample pts */ { FITS fs; int i, w = 0, h = 0, bitpix, np; byte *image; char *error; error = ftopen2d (&fs, fname, &w, &h, &bitpix); if (error) return error; if (fs.extend) return "Load support for MEF files\nis not currently implemented"; /* allocate memory for image and read it in */ np = w * h; image = (byte *) malloc (np); if (image == NULL) return "Insufficient memory"; error = ftgbyte (&fs, image, np, zsc, zr, z1, z2, nsample); ftclose (&fs); if (error) { free (image); return error; } /* There seems to be a convention that fits files be displayed using * a cartesian coordinate system. Thus the first pixel is in the lower * left corner. Fix this by reflecting in the line y=h/2. */ flip (image, w, h); /* sucess ! */ *pix = (unsigned char *) image; *nx = w; *ny = h; *ncolors = 256; for (i = 0; i < 256; i++) r[i] = g[i] = b[i] = i; return NULL; } /* writeFITS -- Write the current frame buffer out as a FITS image. */ char * writeFITS (fp, image, w, h, rmap, gmap, bmap, numcols) FILE *fp; byte *image; int w, h; byte *rmap, *gmap, *bmap; int numcols; { register int i, j, np, nend; register byte *ptr; char *error; byte rgb[256]; error = wrheader(fp, w, h); if (error != NULL) return error; for (i = 0; i < numcols; i++) rgb[i] = MONO(rmap[i], gmap[i], bmap[i]); /* flip line ordering when writing out */ for (i = h - 1; i >= 0; i--) { ptr = &image[i*w]; for (j = 0; j < w; j++, ptr++) putc(rgb[*ptr], fp); } np = w * h; /* nend is the number of padding characters at the end of the last * block. */ nend = ((np + BLOCKSIZE - 1) / BLOCKSIZE) * BLOCKSIZE - np; if (nend) for (i = 0; i < nend; i++) putc('\0', fp); return NULL; } /* IsFITS -- Test a file to see if it is a FITS file. */ int isFITS (fname) char *fname; /* input filename */ { register FILE *fp; int value = 0; char keyw[8], val; if (fp = fopen (fname, "r")) { fscanf (fp, "%6s = %c", keyw, &val); if (strcmp ("SIMPLE", keyw) == 0 && val == 'T') value = 1; fclose (fp); } return value; } /* getFITSHdr -- Get some set of header information for the GUI. */ char * getFITSHdr (fname) char *fname; { FITS fs; char *error, *title, *line; int w, h, bitpix; line = (char *) malloc (80); error = ftopen2d (&fs, fname, &w, &h, &bitpix); if (error) { strcpy (line, error); return (line); } if (fs.extend) { sprintf (line, "%-16.16s %3d (%2d extns) %s", fname, bitpix, fs.nextend, fs.title); } else { sprintf (line, "%-16.16s %3d %5dx%-5d %s", fname, bitpix, w,h, fs.title); } ftclose (&fs); return (line); } /* * Private Procedures * ------------------ */ /* Writes a minimalist FITS file header */ static char *wrheader (fp, nx, ny) FILE *fp; int nx, ny; { char *block; int i; block = (char *) malloc (BLOCKSIZE); if (block == NULL) return "Insufficient memory for workspace"; memset(block, ' ', BLOCKSIZE); i = 0; wrcard(&block[80*i++], "SIMPLE", T_LOG, 1); /* SIMPLE keyword */ wrcard(&block[80*i++], "BITPIX", T_INT, 8); /* BITPIX keyword */ wrcard(&block[80*i++], "NAXIS", T_INT, 2); /* NAXIS keyword */ wrcard(&block[80*i++], "NAXIS1", T_INT, nx); /* NAXIS1 keyword */ wrcard(&block[80*i++], "NAXIS2", T_INT, ny); /* NAXIS2 keyword */ wrcard(&block[80*i++], "END", T_NOVAL, 0); /* END keyword */ i = fwrite(block, sizeof(char), BLOCKSIZE, fp); if (i != BLOCKSIZE) return "Error writing FITS file"; return NULL; } /* open a 2-dimensional fits file. * Stores the dimensions of the file in nx and ny, and updates the FITS * structure passed in fs. * If successful, returns NULL otherwise returns an error message. * Will return an error message if the primary data unit is not a 2-dimensional * array. */ static char *ftopen2d(fs, file, nx, ny, bitpix) FITS *fs; char *file; int *nx, *ny, *bitpix; { FILE *fp; int naxis, i; char *error; fp = fopen(file, "rb"); if (fp == NULL) return "Unable to open FITS file"; fs->fp = fp; fs->bitpix = 0; fs->naxis = 0; fs->cpos = 0; /* read header */ error = rdheader(fs); if (error != NULL) { ftclose(fs); return error; } /* get number of data */ fs->ndata = 1; for (i = 0; i < fs->naxis; i++) fs->ndata = fs->ndata * fs->axes[i]; naxis = fs->naxis; *nx = fs->axes[0]; *ny = fs->axes[1]; *bitpix = fs->bitpix; return error; } /* closes a fits file */ static void ftclose (fs) FITS *fs; { if (fs == NULL) return; if (fs->fp != NULL) fclose(fs->fp); } /* reads the fits header, and updates the FITS structure fs. * Returns NULL on success, or an error message otherwise. */ static char * rdheader (fs) FITS *fs; { int i, j, res; char name[9]; char *block; char *error; long int val; /* the value */ float rval; /* floating point value */ block = (char *) malloc(BLOCKSIZE); if (block == NULL) return "Insufficient memory for workspace"; res = fread(block, sizeof(char), BLOCKSIZE, fs->fp); if (res != BLOCKSIZE) return "Error reading FITS file"; i = 0; /* read SIMPLE key */ error = rdcard(block, "SIMPLE", T_LOG, &val, &rval); if (error != NULL) return error; /* if (val == 0) return "Not a SIMPLE FITS file"; */ i++; /* read BITPIX key */ error = rdcard(&block[80], "BITPIX", T_INT, &val, &rval); if (error != NULL) return error; if (val != 8 && val != 16 && val != 32 && val != 64 && val != -32 && val != -64) return "Bad BITPIX value in FITS file"; fs->bitpix = val; j = fs->bitpix; if (j < 0) j = -j; fs->size = j / 8; i++; /* read NAXIS key */ error = rdcard(&block[2*80], "NAXIS", T_INT, &val, &rval); if (error != NULL) return error; if (val < 0 || val > 999) return "Bad NAXIS value in FITS file"; if (val == 1 || val > 2) return "FITS file is not a two-dimensional image"; fs->naxis = val; i++; /* Check for an EXTEND/NEXTEND keyword pair. */ error = rdcard(&block[3*80], "EXTEND", T_LOG, &val, &rval); if (error == NULL) { fs->extend = val; i++; } else fs->extend = 0; error = rdcard(&block[4*80], "NEXTEND", T_INT, &val, &rval); if (error == NULL) { fs->nextend = val; i++; } else fs->nextend = 0; /* read NAXISnnn keys. * We allow NAXIS to be > 2 iff the dimensions of the extra axes are 1 */ for (j = 0; j < fs->naxis; j++) { if (i == NCARDS) { res = fread(block, sizeof(char), BLOCKSIZE, fs->fp); if (res != BLOCKSIZE) return "Error reading FITS file"; i = 0; } sprintf(name, "NAXIS%d", j + 1); error = rdcard(&block[i*80], name, T_INT, &val, &rval); if (error != NULL) return error; if (val < 0) return "Bad NAXISn value in FITS file"; if (j < 2) fs->axes[j] = val; else if (val != 1) return "FITS file is not a two-dimensional image"; i++; } fs->naxis = 2; /* do remainder */ fs->bscale = 1.0; fs->bzero = 0.0; memset(fs->title, '\0', 80); strcpy (fs->title, "No Title"); for (; ; ) { if (block[i*80] == 'B') { /* Try reading a BSCALE or BZERO keyword from this card. */ error = rdcard(&block[i*80], "BSCALE", T_REAL, &val, &rval); if (error == NULL) fs->bscale = rval; error = rdcard(&block[i*80], "BZERO", T_REAL, &val, &rval); if (error == NULL) fs->bzero = rval; } if (i == NCARDS) { res = fread(block, sizeof(char), BLOCKSIZE, fs->fp); if (res != BLOCKSIZE) return "Unexpected eof in FITS file"; i = 0; } if (strncmp(&block[i*80], "OBJECT ", 8) == 0) { char *ip = &block[i*80]; int i = 0, j = 0; /* Skip ahead to opening quote. */ while (*ip != '\'' && i < 80) ip++, i++; ip++, i++; for (j=0; j < 80 && *ip != '\''; j++) { fs->title[j] = *ip; ip++; } fs->title[j] = '\0'; } if (strncmp(&block[i*80], "END ", 8) == 0) break; i++; } free(block); return NULL; } /* write a header record into the 80 byte buffer card. * The keyword name is passed in name. The value type is in dtype; this * can have the following values: * dtype = T_NOVAL * no keyword value is written * dtype = T_LOG * a logical value, either 'T' or 'F' in column 30 is written * dtype = T_INT * an integer is written, right justified in columns 11-30 */ static void wrcard (card, name, dtype, kvalue) char *card, *name; enum datatype dtype; /* type of value */ int kvalue; { int l; memset(card, ' ', 80); l = strlen(name); if (l) memcpy(card, name, l); /* copy name */ if (dtype == T_NOVAL) return; card[8] = '='; if (dtype == T_LOG) card[29] = kvalue ? 'T' : 'F'; else /* an integer */ { sprintf(&card[10], "%20d", kvalue); card[30] = ' '; } } /* Read a header record, from the 80 byte buffer card. * the keyword name must match 'name'; and parse its value according to * dtype. This can have the following values: * dtype = T_LOG * value is logical, either 'T' or 'F' in column 30. * dtype = T_INT * value is an integer, right justified in columns 11-30. * dtype = T_REAL * value is a real * * The value is stored in kvalue. * It returns NULL on success, or an error message otherwise. */ static char * rdcard (card, name, dtype, kvalue, rvalue) char *card, *name; enum datatype dtype; /* type of value */ long int *kvalue; float *rvalue; { int i, ptr; char namestr[9]; static char error[45]; memcpy(namestr, card, 8); i = 8; do i--; while (i >= 0 && namestr[i] == ' '); namestr[i+1] = '\0'; if (strcmp(namestr, name) != 0) { sprintf(error, "Keyword %s not found in FITS file", name); return error; } /* get start of value */ ptr = 10; while (ptr < 80 && card[ptr] == ' ') ptr++; if (ptr == 80 || card[ptr] == '/') return "FITS file has missing keyword value"; /* no value */ if (dtype == T_LOG) { if ((card[ptr] != 'T' && card[ptr] != 'F')) return "Keyword has bad logical value in FITS file"; *kvalue = (card[ptr] == 'T'); } else /* an integer or real */ { int j, end; long int ival; float fval; char num[21]; /* if (ptr > 29) return "Keyword has bad integer value in FITS file"; */ end = ptr; while (end < 80 && (card[end] != ' ' && card[end] != '/')) end++; memcpy(num, &card[ptr], end - ptr); num[end-ptr] = '\0'; if (dtype == T_INT) { j = sscanf(num, "%ld", &ival); if (j != 1) return "Keyword has bad integer value in FITS file"; *kvalue = ival; *rvalue = 0.0; } else if (dtype == T_REAL) { j = sscanf(num, "%g", &fval); if (j != 1) return "Keyword has bad real value in FITS file"; *kvalue = 0; *rvalue = fval; } } return NULL; } /* reads nelem values into the buffer. * returns NULL for success or an error message. * Copes with the fact that the last 2880 byte record of the FITS file * may be truncated, and should be padded out with zeros. */ static char * ftgdata (fs, buffer, nelem) FITS *fs; void *buffer; int nelem; { int res; if (nelem == 0) return NULL; res = fread(buffer, fs->size, nelem, fs->fp); /* if failed to read all the data */ if (res != nelem) { /* nblock is the number of elements in a record. size is * always a factor of BLOCKSIZE */ int loffs, nblock = BLOCKSIZE / fs->size; if (!feof(fs->fp)) return "I/O error reading FITS file"; /* The last record might be short; check this. * loffs is the offset of the start of the last record from * the current position. */ loffs = ((fs->ndata + nblock - 1) / nblock - 1) * nblock - fs->cpos; /* if we didn't read to the end of the penultimate record */ if (res < loffs) return "Unexpected EOF reading FITS file"; /* pad with zeros */ memset((char *)buffer + res * fs->size, '\0', (nelem - res) * fs->size); } fs->cpos += res; return ftfixdata(fs, buffer, nelem); } /* convert the raw data, as stored in the FITS file, to the format * appropiate for the data representation of the host computer. * Assumes that * short int = 2 byte integer * int = 4 byte integer */ static char * ftfixdata (fs, buffer, nelem) FITS *fs; void *buffer; int nelem; { register int i, n = nelem; register uchar *ptr = buffer; /* conversions. Although the data may be signed, reverse using unsigned * variables. Convert from big-endian two-byte signed integer to * native form */ if (fs->bitpix == 16) for (i = 0; i < n; i++, ptr += 2) *(unsigned short int *)ptr = (((int)*ptr) << 8) | (int)(ptr[1]); /* convert from big-endian four-byte signed integer to native form */ else if (fs->bitpix == 32) for (i = 0; i < n; i++, ptr += 4) *(unsigned int *)ptr = (((unsigned int)*ptr) << 24) | ((unsigned int)ptr[1] << 16) | ((unsigned int)ptr[2] << 8) | (unsigned int)ptr[3]; /* convert from IEE 754 single precision to native form */ else if (fs->bitpix == -32) { register int j, k, expo; static float *exps = NULL; if (exps == NULL) { exps = (float *)calloc(256, sizeof(float)); if (exps == NULL) return "Insufficient memory for workspace"; exps[150] = 1.; for (i = 151; i < 256; i++) exps[i] = 2. * exps[i-1]; for (i = 149; i >= 0; i--) exps[i] = 0.5 * exps[i+1]; } for (i = 0; i < n; i++, ptr += 4) { k = (int)*ptr; j = ((int)ptr[1] << 16) | ((int)ptr[2] << 8) | (int)ptr[3]; expo = ((k & 127) << 1) | (j >> 23); if ((expo | j) == 0) *(float *)ptr = 0.; else *(float *)ptr = exps[expo] * (float)(j | 0x800000); if (k & 128) *(float *)ptr = -*(float *)ptr; } /* convert from IEE 754 double precision to native form */ } else if (fs->bitpix == -64) { register int expo, k, l; register unsigned int j; static double *exps = NULL; if (exps == NULL) { exps = (double *)calloc(2048, sizeof(double)); if (exps == NULL) return "Insufficient memory for workspace"; exps[1075] = 1.; for (i = 1076; i < 2048; i++) exps[i] = 2. * exps[i-1]; for (i = 1074; i >= 0; i--) exps[i] = 0.5 * exps[i+1]; } for (i = 0; i < n; i++, ptr += 8) { k = (int)*ptr; j = ((unsigned int)ptr[1] << 24) | ((unsigned int)ptr[2] << 16) | ((unsigned int)ptr[3] << 8) | (unsigned int)ptr[4]; l = ((int)ptr[5] << 16) | ((int)ptr[6] << 8) | (int)ptr[7]; expo = ((k & 127) << 4) | (j >> 28); if ((expo | j | l) == 0) *(double *)ptr = 0.; else *(double *)ptr = exps[expo] * (16777216. * (double)((j & 0x0FFFFFFF) | 0x10000000) + (double)l); if (k & 128) *(double *)ptr = -*(double *)ptr; } } return NULL; } #undef max #define f_max(a,b) ((a) > (b) ? (a) : (b)) #undef min #define f_min(a,b) ((a) < (b) ? (a) : (b)) /* Reads a byte image from the FITS file fs. The image contains nelem pixels. * If bitpix = 8, then the image is loaded as stored in the file if not scaled. * Otherwise, it is rescaled so that the minimum value is stored as 0, and * the maximum is stored as 255 */ static char * ftgbyte(fs, cbuff, nelem, zsc, zr, z1, z2, nsample) FITS *fs; uchar *cbuff; int nelem; int zsc, zr; float *z1, *z2; int nsample; { char * voidbuff; register int i, n = nelem; char *error; int pmin = 0, pmax = 255; int npts, stdline; extern void zscale(); /* if the data is uchar, then read it directly */ if (fs->bitpix == 8 && (fs->bscale == 1.0 && fs->bzero == 0.0)) { *z1 = 0.0; *z2 = 255.0; return ftgdata(fs, cbuff, nelem); } /* allocate a buffer to store the image */ if (fabs((double)fs->bscale-1.0) > EPSILON || fabs((double)fs->bzero) > EPSILON) voidbuff = (char * )malloc(nelem * f_max(fs->size,4)); else voidbuff = (char * )malloc(nelem * fs->size); if (voidbuff == NULL) return "Insufficient memory for workspace"; error = ftgdata(fs, voidbuff, nelem); if (error != NULL) { printf ("ftgbyte: %s\n", error); return error; } /* If we've got BSCALE/BZERO values compute the original pixel values * and convert the buffer to floating point before processing it. * The voidbuff was allocated above with this in mind so it should be * large enough that we can fix the pixels in place. */ npts = fs->axes[0] * fs->axes[1]; stdline = (int)((float)fs->axes[1] / sqrt((float)npts/(float)nsample)); if (fs->bscale != 1.0 || fs->bzero != 0.0) { register float *buf; buf = (float *)voidbuff; if (fs->bitpix == 8) { for (i=(nelem-1); i >= 0; i--) buf[i] = (float) voidbuff[i] * fs->bscale + fs->bzero; } else if (fs->bitpix == 16) { register short *old; for (i=(nelem-1); i >= 0; i--) { old = (short *) &voidbuff[i * 2]; buf[i] = (float) *old * fs->bscale + fs->bzero; } } else if (fs->bitpix == 32) { register int *old; for (i=(nelem-1); i >= 0; i--) { old = (int *) &voidbuff[i * 4]; buf[i] = (float) *old * fs->bscale + fs->bzero; } } else if (fs->bitpix == -32) { register float *old; for (i=(nelem-1); i >= 0; i--) { old = (float *) &voidbuff[i * 4]; buf[i] = (float) *old * fs->bscale + fs->bzero; } } else if (fs->bitpix == -64) { register double *old, *dbuf; register float *fpix; dbuf = (double *) malloc (nelem * sizeof(double)); for (i=(nelem-1); i >= 0; i--) { old = (double *) &voidbuff[i * 8]; dbuf[i] = (float) *old * fs->bscale + fs->bzero; } fpix = (float *) voidbuff; for (i=0; i<nelem; i++) buf[i] = fpix[i] = (float) dbuf[i]; free ((double *) dbuf); } fs->size = 4; fs->bitpix = -32; /* compute the optimal zscale values */ if (zsc) zscale ((char *)buf, fs->axes[0], fs->axes[1], fs->bitpix, z1, z2, CONTRAST, nsample, stdline); else if (zr) min_max ((float *)buf, nelem, fs->bitpix, z1, z2); } else { /* compute the optimal zscale values */ if (zsc) zscale (voidbuff, fs->axes[0], fs->axes[1], fs->bitpix, z1, z2, CONTRAST, nsample, stdline); else if (zr) min_max ((float *)voidbuff, nelem, fs->bitpix, z1, z2); } /* convert short int to uchar */ if (fs->bitpix == 16) { register short int *buffer = (short *)voidbuff; register int max, min; register float scale; min = (int) *z1; max = (int) *z2; scale = (max == min) ? 0. : 255. / (*z2 -*z1); /* rescale and convert */ for (i = 0, buffer = (short *)voidbuff; i < n; i++) cbuff[i] = f_max (pmin, f_min (pmax, (int)(scale * (float)((int)buffer[i] - min)) )); /* convert long int to uchar */ } else if (fs->bitpix == 32) { register int *buffer = (int *)voidbuff; register int max, min; register float scale; min = (int) *z1; max = (int) *z2; scale = (max == min) ? 0. : 255. / (*z2 - *z1); /* rescale and convert */ for (i = 0, buffer = (int *)voidbuff; i < n; i++) cbuff[i] = f_max (pmin, f_min (pmax, (int)(scale * (float)((int)buffer[i] - min)) )); /* convert float to uchar */ } else if (fs->bitpix == -32) { register float *buffer = (float *)voidbuff; register float max, min, scale; min = *z1; max = *z2; scale = (max == min) ? 0. : 255. / (*z2 - *z1); /* rescale and convert */ for (i = 0, buffer = (float *)voidbuff; i < n; i++) cbuff[i] = f_max (pmin, f_min (pmax, (int)(scale * ((float)buffer[i] - min)) )); /* convert double to uchar */ } else if (fs->bitpix == -64) { register double *buffer = (double *)voidbuff; register double max, min, scale; min = (double) *z1; max = (double) *z2; scale = (max == min) ? 0. : 255. / (*z2 - *z1); /* rescale and convert */ for (i = 0, buffer = (double *)voidbuff; i < n; i++) cbuff[i] = f_max (pmin, f_min (pmax, (int)(scale * ((double)buffer[i] - min)) )); } free( (char *)voidbuff); return NULL; }
the_stack_data/111078195.c
/* * This file is used to test dsymutil support for call site entries * (DW_TAG_call_site / DW_AT_call_return_pc). * * Instructions for regenerating binaries (on Darwin/x86_64): * * 1. Copy the source to a top-level directory to work around having absolute * paths in the symtab's OSO entries. * * mkdir -p /Inputs/ && cp call-site-entry.c /Inputs && cd /Inputs * * 2. Compile with call site info enabled. * * clang -g -O1 -Xclang -disable-llvm-passes call-site-entry.c -c -o call-site-entry.macho.x86_64.o * clang call-site-entry.macho.x86_64.o -o call-site-entry.macho.x86_64 * * 3. Copy the binaries back into the repo's Inputs directory. You'll need * -oso-prepend-path=%p to link. */ __attribute__((optnone)) int f() {} int main() { f(); }
the_stack_data/27898.c
#include<stdio.h> int main() { int i,j,k,n; for(i=1;i<20;i++) for(j=1;j<33;j++) for(k=3;k<100;k=k+3) if(i+j+k==100 && 15*i+9*j+k==300) printf("cock=%d,hen=%d,chicken=%d\n",i,j,k); // Chicken_and_rabbit_cocage_problem return 0; }
the_stack_data/184516915.c
/* Datentypen-Test */ #include <stdio.h> int main(void) { int a; printf ("%d (5)\n", (4,5)); a = 1; printf ("%d (3)\n", a+=1+1); printf ("%d (0)\n", a == 3 ? 1 : 0); printf ("%d (1)\n", -- a < 3 ? 0 : 1); printf ("%d (6)\n", 2*2+2); printf ("%d (0)\n", 0 && 1 || 0); printf ("%d (1)\n", 1 && 0 || 1 ); printf ("%d (15)\n", 8 | 7 ^ 7 & 8); /* printf ("%d ()\n", ); */ return 0; } #ifdef EiCTeStS main(); :show main #endif
the_stack_data/25137802.c
#include <stdio.h> void main() { printf("Hello, World!"); }
the_stack_data/69614.c
#include <math.h> #include <stdio.h> float a2(float x){ float resalt=((sqrt(pow(x,2)+1)-1)/2)+x; return(resalt); } int main(void){ return 0; }
the_stack_data/67326307.c
/* How to use manipulate pointers in functions. */ #include <stdio.h> #include <stdlib.h> #include <string.h> int has_bad_format(const char *date) { if (strlen(date) != 10) return 1; const char *ptr = date; while (*ptr) { if (ptr == date+2 || ptr == date+5) { if (*ptr != '/') return 1; } else if (*ptr-'0' < 0 || *ptr-'0' > 9) { return 1; } ptr++; } return 0; } void parse_date(const char *date, int *restrict day, int *restrict month, int *restrict year) { char buffer[strlen(date)+1]; strcpy(buffer, date); char *s_day = strtok(buffer, "/"); char *s_month = strtok(NULL, "/"); char *s_year = strtok(NULL, "/"); *day = strtol(s_day, NULL, 0); *month = strtol(s_month, NULL, 0); *year = strtol(s_year, NULL, 0); } int main() { char *date = "23/03/2014"; if (has_bad_format(date)) { puts("Incorrect date format."); return 1; } int day, month, year; parse_date(date, &day, &month, &year); printf("day = %d\n", day); printf("month = %d\n", month); printf("year = %d\n", year); }
the_stack_data/175142399.c
#include <stdio.h> #include <ctype.h> int main(void) { char chr; int count = 0; printf("Enter a sentence: "); do { chr = toupper(getchar()); switch (chr) { case 'A': case 'E': case 'I': case 'O': case 'U': count++; break; } } while (chr != '\n'); printf("Your sentence contains %d vowels.\n", count); return 0; }
the_stack_data/61074314.c
#include<stdio.h> #include<strings.h> #define Q "His Hamlet was funny without being vulgar." int main(void) { printf("He sold the painting for $%2.2f.\n", 2.345e2); // 234.50 printf("%c%c%c\n", 'H', 105, '\41'); // Hi! printf("%s\nhas %d characters.\n", Q, strlen(Q)); // "His..." length printf("\"%s\"\nhas %d characters.\n", Q, strlen(Q)); // "His..." length printf("Is %2.3e the same as %2.2f\n", 1201.0, 1201.0); // 1.201e+03 1201.00 return 0; }
the_stack_data/89352.c
#include <stdio.h> #define NO_NODES 23 unsigned char classes[NO_NODES] = {1,1,2,2,2,1,1,1,2,1,2,1,1,1,1,0,0,2,2,1,0,0,1}; int FEATURE_IDX_NODE[NO_NODES] = {12,11,10,6,-2,-2,2,-2,-2,6,-2,0,-2,1,-2,-2,6,10,-2,-2,4,-2,-2}; int RIGHT_CHILDS[NO_NODES] = {16,9,6,5,0,0,8,0,0,11,0,13,0,15,0,0,20,19,0,0,22,0,0}; float THRESHOLDS[NO_NODES] = {755.0,2.1149998903274536,0.9350000023841858,1.5800000429153442,-2.0,-2.0,2.4499999284744263,-2.0,-2.0,0.7950000166893005,-2.0,13.174999713897705,-2.0,2.1249999403953552,-2.0,-2.0,2.165000081062317,0.8030000030994415,-2.0,-2.0,135.5,-2.0,-2.0}; int predict(double * sample){ unsigned int current_node = 0; int feature_idx = FEATURE_IDX_NODE[0]; while(feature_idx >= 0){ if(sample[feature_idx] <= THRESHOLDS[current_node]){ current_node++; } else{ current_node = RIGHT_CHILDS[current_node]; } feature_idx = FEATURE_IDX_NODE[current_node]; } return classes[current_node]; } int main(){ double sample[] = {12.33,1.1,2.28,16.0,101.0,2.05,1.09,0.63,0.41,3.27,1.25,1.67,680.0}; int class = 0; class = predict(sample); // 1 printf("%d\n", class); return 0; }
the_stack_data/86074990.c
/* <TAGS>stats</TAGS> DESCRIPTION: Calculate the Pearson's correlation and return details including F and p statistics - this version for integer values of x and y Fills a "results" array with details from a Pearson's correlation Allows definition of an arbitrary "invalid" value to be ignored Assumes all data is stored in memory For faster processing with less analysis detail, use xf_correlate_simple_d USES: Detailed correlation statistics on parallel arrays of data DEPENDENCIES: float xf_prob_F(float F,int df1,int df2) ARGUMENTS: int *x : input, x-data array int *y : input, y-data array long nn : input, number of elements in x & y int setinv : input, user-specified invalid value double *result : output, pre-allocated array to hold results - must allow at least 18 elements char *message : output, pre-allocated array to hold error message RETURN VALUE: 0 on success, -1 on error result array will hold statistics char array will hold message (if any) if r==0: check message (minimum correlation) - likely a vertical or horizontal line probability of "nan" will confirm this if F==99: indicates that r was nearly exxactly -1 or +1: F is arbitrarily assigned a large value SAMPLE CALL: x= xf_correlate_i(x,y,n,-1,result,message); if(x==-1) { fprintf(stderr,"\n\t--- %s/%s\n\n",thisprog,message); exit(1); } else if (!isfinite(result[1])) { fprintf(stderr,"*** %s/%s\n\n",thisprog,message);} */ #include<stdlib.h> #include<stdio.h> #include<math.h> int xf_correlate_i(int *x, int *y, long nn, int setinv, double *result, char *message) { /* define external dependency */ float xf_prob_F(float F,int df1,int df2); /* define internal variables */ char *thisfunc="xf_correlate_i\0"; long ii,dfa,dfb,N_valid=0; double tempx,tempy,aa,bb,prob,b0,b1; double SUMx=0.0,SUMy=0.0,SUMx2=0.0,SUMy2=0.0,SUMxy=0.0,MEANx=0.0,MEANy=0.0; double SSx=0.0,SSy=0.0,SDx=0.0,SDy=0.0,SSreg=0.0,SSres=0.0,SPxy=0.0; double r=0.0,r2=0.0,r2adj=0.0,F=0.0; for(ii=0;ii<=18;ii++) result[ii]=0.0; /********************************************************************************/ /* SCAN THE INPUT DATA */ /********************************************************************************/ aa=(double)setinv; for(ii=0;ii<nn;ii++) { tempx= (double)x[ii]; tempy= (double)y[ii]; if(tempx!=aa && tempy!=aa) { N_valid++; SUMx += tempx; SUMy += tempy; SUMx2 += tempx*tempx; SUMy2 += tempy*tempy; SUMxy += tempx*tempy; }} /********************************************************************************/ /* MAKE SURE THERE WERE AT LEAST 4 VALID DATA POINTS */ /********************************************************************************/ if(N_valid<4) { sprintf(message,"%s [ERROR: less than 4 valid data points - no correlation possible]",thisfunc); return(-1); } /********************************************************************************/ /* CALCULATE BASIC STATISTICS */ /********************************************************************************/ MEANx = SUMx/N_valid; MEANy = SUMy/N_valid; SSx = SUMx2-((SUMx*SUMx)/N_valid); SSy = SUMy2-((SUMy*SUMy)/N_valid); SPxy = SUMxy-((SUMx*SUMy)/N_valid); SDx = sqrt(SSx/(N_valid-1.0)); SDy = sqrt(SSy/(N_valid-1.0)); dfa = 1; dfb = N_valid-2; /********************************************************************************/ /* CALCULATE R AND REGRESSION COEFFICIENTS b1 (SLOPE) AND b0 (INTERCEPT) */ /* - apply corrections for vertical or horizontal lines */ /********************************************************************************/ /* if data describes horizontal line... */ if(SSy==0.0) { r=0; b1=0.0; // slope b0=MEANy; // y-intercept sprintf(message,"%s [WARNING: data defines a horizontal line]\n",thisfunc); } /* if data describes vertical line (or single point) ... */ else if(SSx==0.0) { r=0; b1=NAN; b0=NAN; sprintf(message,"%s [WARNING: data defines a vertical]\n",thisfunc); } /* otherwise, if there is variability in both x and y... */ else { r = SPxy/(sqrt(SSx)*sqrt(SSy)); b1= SPxy/SSx; b0= (SUMy/nn)-(b1*(SUMx/nn)); } /* now calculate the remaining principal statistics */ r2 = r*r; r2adj = 1.0-((1.0-r2)*(double)(N_valid-1)/(double)(N_valid-2)); F = (r2*dfb)/(1-r2); /********************************************************************************/ /* CALCULATE PROBABILITY */ /********************************************************************************/ /* do not pass extreme values to the probability function - just assume it's a perfect correlation */ if(r>=.999999||r<=-.999999) { F=999999.0; prob=0.0; } /* make sure the F-value is non-zero, there are valid degrees-of-freedom,and there is variance in x */ else { if(F>0 && dfa>0 && dfb>0 && SDx!=0) { /* call the external probability function */ prob = xf_prob_F(F,dfa,dfb); } else { prob=NAN; } } /********************************************************************************/ /* FILL THE RESULTS ARRAY */ /********************************************************************************/ result[0] = (double) N_valid; result[1] = (double) r; /* Pearson's r */ result[2] = (double) r2; /* r-squared */ result[3] = (double) r2adj; /* adjusted r-squared */ result[4] = (double) F; result[5] = (double) dfa; result[6] = (double) dfb; result[7] = (double) prob; /* p-value (probability) */ result[8] = (double) MEANx; result[9] = (double) MEANy; result[10] = (double) SSx; result[11] = (double) SSy; result[12] = (double) SPxy; result[13] = (double) SDx; result[14] = (double) SDy; result[15] = (double) b1; /* slope */ result[16] = (double) b0; /* intercept */ result[17] = (double) N_valid; return(0); }
the_stack_data/153268918.c
#include <stdio.h> int main() { //declarar variaveis int num1, num2; int soma; int subtracao; int mult; float divisao; //float para poder ter num decimal //ler do teclado printf("\nEntre com um numero:"); scanf("%d", &num1); printf("\nEntre com outro numero:"); scanf("%d", &num2); soma = num1 + num2; printf("\nSoma de %d + %d = %d", num1, num2, soma); subtracao = num1 - num2; printf("\nSubtracao de %d - %d = %d", num1, num2, subtracao); mult = num1 * num2; printf("\nMultiplicacao de %d * %d = %d", num1, num2, mult); divisao = (float)num1 / num2; printf("\nDivisao de %d / %d = %f\n", num1, num2, divisao); return 0; }
the_stack_data/237643016.c
// Test calling of device math functions. ///==========================================================================/// // REQUIRES: nvptx-registered-target // RUN: %clang_cc1 -internal-isystem %S/Inputs/include -include math.h -fopenmp -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc // RUN: %clang_cc1 -internal-isystem %S/../../lib/Headers/openmp_wrappers -include __clang_openmp_math_declares.h -internal-isystem %S/../../lib/Headers/openmp_wrappers -include math.h -fopenmp -triple nvptx64-nvidia-cuda -aux-triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck -check-prefix CHECK-YES %s #include <math.h> void test_sqrt(double a1) { #pragma omp target { // CHECK-YES: call double @__nv_sqrt(double double l1 = sqrt(a1); // CHECK-YES: call double @__nv_pow(double double l2 = pow(a1, a1); // CHECK-YES: call double @__nv_modf(double double l3 = modf(a1 + 3.5, &a1); // CHECK-YES: call double @__nv_fabs(double double l4 = fabs(a1); // CHECK-YES: call i32 @__nv_abs(i32 double l5 = abs((int)a1); } }
the_stack_data/175143011.c
#include "stdio.h" void readProcessingTime(int a[][10],int n) { int i = 0, j = 0; for (i = 0; i <= 1; i++) { for ( j = 0; j <n ; j++) { printf("\n Enter processing time of station S[%d][%d] : ",(i+1),(j+1)); scanf("%d",&a[i][j]); } } } void readTransferTime(int t[][10],int n) { int i = 0, j = 0; for (i = 0; i <= 1; i++) { for ( j = 1; j <n ; j++) { printf("\n Enter transfer time from station S[%d][%d] : ",(i+1),(j)); scanf("%d",&t[i][j]); } } } void print2dArray(int a[][10], int n, char *str) { int i=0,j; for (; i <= 1; i++) { //printf("Assembly line %d:\t",(i+1)); printf("%s %d:\t",str,(i+1)); if (str == "Assembly line") j=0; else j=1; for ( ; j <n ; j++) { printf("%d\t",a[i][j]); } printf("\n"); } printf("\n"); } void read1darray(int e[], char *str,int n) { for(int i =0 ; i<2; i++) { printf("Enter %s %d",str,(i+1)); scanf("%d",&e[i]); } } void display1darray(int e[], char *str,int n) { printf("%s :\t",str); for(int i =0 ; i<n; i++) { printf("%d\t",e[i]); } printf("\n\n"); } void printschedule(int L,int l[][10],int n) { int i = L; printf("\nS%d%d",i,n); for(int j = n-1; j >= 1; j--) { if(i==1) i = l[0][j]; else i = l[1][j]; printf(" <--- S%d%d",i,j); } } void calculate(int e[], int x[],int a[][10], int t[][10], int n) { int l[2][10],F=0,L=0; int f[2][10]; //total processing time till station 1 on both assembly line for(int i = 0; i < 2; i++) f[i][0] = e[i] + a[i][0]; // going from station 2 till last station n int i =0; for(int j = 1; j < n; j++) { if((f[i][j-1] + a[i][j]) <= (f[i+1][j-1] + a[i][j] + t[i+1][j])) { f[i][j] = f[i][j-1] + a[i][j]; l[i][j] = 1; } else { f[i][j] = f[i+1][j-1] + a[i][j] + t[i+1][j]; l[i][j] = 2; } if((f[i+1][j-1] + a[i+1][j]) <= (f[i][j-1] + a[i+1][j] + t[i][j])) { f[i+1][j] = f[i+1][j-1] + a[i+1][j]; l[i+1][j] = 2; } else { f[i+1][j] = f[i][j-1] + a[i+1][j] + t[i][j]; l[i+1][j] = 1; } } i=0; if(f[i][n-1]+x[i] <= f[i+1][n-1]+x[i+1]) { F = f[i][n-1]+x[i]; L = 1; } else { F = f[i+1][n-1]+x[i+1]; L = 2; } /* for(int i=0;i<2;++i) { for (int j = 0;j < n; j++) printf("%d",f[i][j]); printf("\n"); }*/ printf("Optimal Value(Fastest Time) is %d",F); printschedule(L,l,n); } int main(void) { int a[2][10],t[2][10],e[2],x[2],f[2][10]; int n; printf("\nEnter number of station on each assembly line : "); scanf("%d",&n); readProcessingTime(a,n); printf("\n\nProcessing Times are : \n"); print2dArray(a,n,"Assembly line"); readTransferTime(t,n); printf("\n\nTransfer Times are : \n"); print2dArray(t,n,"transfer time"); read1darray(e,"Entry time",2); display1darray(e,"Entry Time",2); read1darray(x,"Exit time",2); display1darray(x,"Exit Time",2); calculate(e,x,a,t,n); }
the_stack_data/97196.c
#include <stdio.h> #include <stdlib.h> #include <time.h> #include <math.h> #define N 256 __attribute__ ((__aligned__(16))) double a[N]; int main(int argc, char **argv) { srand(time(NULL)); for(int i = 0;i < N;i++) a[i] = rand(); for(int i = 0;i < N;i++) a[i] = sin(a[i]); for(int i = 0;i < N;i++) printf("%g\n", a[i]); }
the_stack_data/9119.c
#ifdef lint util_restart_save_state() { return 0; } util_restart_restore_state() { } #else #ifdef vax int util_restart_state[32]; util_restart_save_state() { asm("movl sp,_util_save_sp"); asm("movl r1,_util_restart_state"); asm("movl r2,_util_restart_state+4"); asm("movl r3,_util_restart_state+8"); asm("movl r4,_util_restart_state+12"); asm("movl r5,_util_restart_state+16"); asm("movl r6,_util_restart_state+20"); asm("movl r7,_util_restart_state+24"); asm("movl r8,_util_restart_state+28"); asm("movl r9,_util_restart_state+32"); asm("movl r10,_util_restart_state+36"); asm("movl r11,_util_restart_state+40"); asm("movl 8(fp),_util_restart_state+44"); asm("movl 12(fp),_util_restart_state+48"); asm("movl 16(fp),_util_restart_state+52"); asm("movl $0,r0"); } util_restart_restore_state() { asm("movl _util_restart_state,r1"); asm("movl _util_restart_state+4,r2"); asm("movl _util_restart_state+8,r3"); asm("movl _util_restart_state+12,r4"); asm("movl _util_restart_state+16,r5"); asm("movl _util_restart_state+20,r6"); asm("movl _util_restart_state+24,r7"); asm("movl _util_restart_state+28,r8"); asm("movl _util_restart_state+32,r9"); asm("movl _util_restart_state+36,r10"); asm("movl _util_restart_state+40,r11"); asm("movl _util_restart_state+44,ap"); asm("movl _util_restart_state+48,fp"); asm("addl3 fp,$4,sp"); asm("movl _util_restart_state+52,r0"); asm("jmp (r0)"); } #endif #if defined(sun) && ! defined(sparc) int util_restart_state[32]; util_restart_save_state() { asm("movel sp,_util_save_sp"); asm("movel sp@,_util_restart_state"); asm("movel sp@(0x4),_util_restart_state+4"); asm("moveml #0xFFFF,_util_restart_state+8"); return 0; } util_restart_restore_state() { asm("moveml _util_restart_state+8,#0xFFFF"); asm("movel _util_restart_state+4,sp@(0x4)"); asm("movel _util_restart_state,sp@"); return 1; } #endif #endif