file
stringlengths 18
26
| data
stringlengths 3
1.04M
|
---|---|
the_stack_data/20437.c | /*
* ARM signal handling routines
*
* Copyright 2002 Marcus Meissner, SuSE Linux AG
* Copyright 2010-2013, 2015 André Hentschel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#if 0
#pragma makedep unix
#endif
#ifdef __arm__
#include "config.h"
#include "wine/port.h"
#include <assert.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#endif
#ifdef HAVE_SYSCALL_H
# include <syscall.h>
#else
# ifdef HAVE_SYS_SYSCALL_H
# include <sys/syscall.h>
# endif
#endif
#ifdef HAVE_SYS_SIGNAL_H
# include <sys/signal.h>
#endif
#ifdef HAVE_SYS_UCONTEXT_H
# include <sys/ucontext.h>
#endif
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "windef.h"
#include "winnt.h"
#include "winternl.h"
#include "wine/exception.h"
#include "wine/asm.h"
#include "unix_private.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(seh);
static pthread_key_t teb_key;
/***********************************************************************
* signal context platform-specific definitions
*/
#ifdef linux
#if defined(__ANDROID__) && !defined(HAVE_SYS_UCONTEXT_H)
typedef struct ucontext
{
unsigned long uc_flags;
struct ucontext *uc_link;
stack_t uc_stack;
struct sigcontext uc_mcontext;
sigset_t uc_sigmask;
unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
} ucontext_t;
#endif
/* All Registers access - only for local access */
# define REG_sig(reg_name, context) ((context)->uc_mcontext.reg_name)
# define REGn_sig(reg_num, context) ((context)->uc_mcontext.arm_r##reg_num)
/* Special Registers access */
# define SP_sig(context) REG_sig(arm_sp, context) /* Stack pointer */
# define LR_sig(context) REG_sig(arm_lr, context) /* Link register */
# define PC_sig(context) REG_sig(arm_pc, context) /* Program counter */
# define CPSR_sig(context) REG_sig(arm_cpsr, context) /* Current State Register */
# define IP_sig(context) REG_sig(arm_ip, context) /* Intra-Procedure-call scratch register */
# define FP_sig(context) REG_sig(arm_fp, context) /* Frame pointer */
/* Exceptions */
# define ERROR_sig(context) REG_sig(error_code, context)
# define TRAP_sig(context) REG_sig(trap_no, context)
struct extended_ctx
{
unsigned long magic;
unsigned long size;
};
struct vfp_sigframe
{
struct extended_ctx ctx;
unsigned long long fpregs[32];
unsigned long fpscr;
};
static void *get_extended_sigcontext( const ucontext_t *sigcontext, unsigned int magic )
{
struct extended_ctx *ctx = (struct extended_ctx *)sigcontext->uc_regspace;
while ((char *)ctx < (char *)(sigcontext + 1) && ctx->magic && ctx->size)
{
if (ctx->magic == magic) return ctx;
ctx = (struct extended_ctx *)((char *)ctx + ctx->size);
}
return NULL;
}
static void save_fpu( CONTEXT *context, const ucontext_t *sigcontext )
{
struct vfp_sigframe *frame = get_extended_sigcontext( sigcontext, 0x56465001 );
if (!frame) return;
memcpy( context->u.D, frame->fpregs, sizeof(context->u.D) );
context->Fpscr = frame->fpscr;
}
static void restore_fpu( const CONTEXT *context, ucontext_t *sigcontext )
{
struct vfp_sigframe *frame = get_extended_sigcontext( sigcontext, 0x56465001 );
if (!frame) return;
memcpy( frame->fpregs, context->u.D, sizeof(context->u.D) );
frame->fpscr = context->Fpscr;
}
#elif defined(__FreeBSD__)
/* All Registers access - only for local access */
# define REGn_sig(reg_num, context) ((context)->uc_mcontext.__gregs[reg_num])
/* Special Registers access */
# define SP_sig(context) REGn_sig(_REG_SP, context) /* Stack pointer */
# define LR_sig(context) REGn_sig(_REG_LR, context) /* Link register */
# define PC_sig(context) REGn_sig(_REG_PC, context) /* Program counter */
# define CPSR_sig(context) REGn_sig(_REG_CPSR, context) /* Current State Register */
# define IP_sig(context) REGn_sig(_REG_R12, context) /* Intra-Procedure-call scratch register */
# define FP_sig(context) REGn_sig(_REG_FP, context) /* Frame pointer */
static void save_fpu( CONTEXT *context, const ucontext_t *sigcontext ) { }
static void restore_fpu( const CONTEXT *context, ucontext_t *sigcontext ) { }
#endif /* linux */
enum arm_trap_code
{
TRAP_ARM_UNKNOWN = -1, /* Unknown fault (TRAP_sig not defined) */
TRAP_ARM_PRIVINFLT = 6, /* Invalid opcode exception */
TRAP_ARM_PAGEFLT = 14, /* Page fault */
TRAP_ARM_ALIGNFLT = 17, /* Alignment check exception */
};
struct syscall_frame
{
struct syscall_frame *prev_frame;
DWORD cpsr;
DWORD r5;
DWORD r6;
DWORD r7;
DWORD r8;
DWORD r9;
DWORD r10;
DWORD r11;
DWORD thunk_addr;
DWORD r4;
DWORD ret_addr;
};
struct arm_thread_data
{
void *exit_frame; /* 1d4 exit frame pointer */
struct syscall_frame *syscall_frame; /* 1d8 frame pointer on syscall entry */
};
C_ASSERT( sizeof(struct arm_thread_data) <= sizeof(((struct ntdll_thread_data *)0)->cpu_data) );
C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct arm_thread_data, exit_frame ) == 0x1d4 );
C_ASSERT( offsetof( TEB, GdiTebBatch ) + offsetof( struct arm_thread_data, syscall_frame ) == 0x1d8 );
static inline struct arm_thread_data *arm_thread_data(void)
{
return (struct arm_thread_data *)ntdll_get_thread_data()->cpu_data;
}
/***********************************************************************
* unwind_builtin_dll
*/
NTSTATUS CDECL unwind_builtin_dll( ULONG type, struct _DISPATCHER_CONTEXT *dispatch, CONTEXT *context )
{
return STATUS_UNSUCCESSFUL;
}
/***********************************************************************
* get_trap_code
*
* Get the trap code for a signal.
*/
static inline enum arm_trap_code get_trap_code( int signal, const ucontext_t *sigcontext )
{
#ifdef TRAP_sig
enum arm_trap_code trap = TRAP_sig(sigcontext);
if (trap)
return trap;
#endif
switch (signal)
{
case SIGILL:
return TRAP_ARM_PRIVINFLT;
case SIGSEGV:
return TRAP_ARM_PAGEFLT;
case SIGBUS:
return TRAP_ARM_ALIGNFLT;
default:
return TRAP_ARM_UNKNOWN;
}
}
/***********************************************************************
* get_error_code
*
* Get the error code for a signal.
*/
static inline WORD get_error_code( const ucontext_t *sigcontext )
{
#ifdef ERROR_sig
return ERROR_sig(sigcontext);
#else
return 0;
#endif
}
/***********************************************************************
* save_context
*
* Set the register values from a sigcontext.
*/
static void save_context( CONTEXT *context, const ucontext_t *sigcontext )
{
#define C(x) context->R##x = REGn_sig(x,sigcontext)
/* Save normal registers */
C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
#undef C
context->ContextFlags = CONTEXT_FULL;
context->Sp = SP_sig(sigcontext); /* Stack pointer */
context->Lr = LR_sig(sigcontext); /* Link register */
context->Pc = PC_sig(sigcontext); /* Program Counter */
context->Cpsr = CPSR_sig(sigcontext); /* Current State Register */
context->R11 = FP_sig(sigcontext); /* Frame pointer */
context->R12 = IP_sig(sigcontext); /* Intra-Procedure-call scratch register */
save_fpu( context, sigcontext );
}
/***********************************************************************
* restore_context
*
* Build a sigcontext from the register values.
*/
static void restore_context( const CONTEXT *context, ucontext_t *sigcontext )
{
#define C(x) REGn_sig(x,sigcontext) = context->R##x
/* Restore normal registers */
C(0); C(1); C(2); C(3); C(4); C(5); C(6); C(7); C(8); C(9); C(10);
#undef C
SP_sig(sigcontext) = context->Sp; /* Stack pointer */
LR_sig(sigcontext) = context->Lr; /* Link register */
PC_sig(sigcontext) = context->Pc; /* Program Counter */
CPSR_sig(sigcontext) = context->Cpsr; /* Current State Register */
FP_sig(sigcontext) = context->R11; /* Frame pointer */
IP_sig(sigcontext) = context->R12; /* Intra-Procedure-call scratch register */
restore_fpu( context, sigcontext );
}
/***********************************************************************
* set_cpu_context
*
* Set the new CPU context.
*/
void DECLSPEC_HIDDEN set_cpu_context( const CONTEXT *context );
__ASM_GLOBAL_FUNC( set_cpu_context,
".arm\n\t"
"ldr r2, [r0, #0x44]\n\t" /* context->Cpsr */
"tst r2, #0x20\n\t" /* thumb? */
"ldr r1, [r0, #0x40]\n\t" /* context->Pc */
"orrne r1, r1, #1\n\t" /* Adjust PC according to thumb */
"biceq r1, r1, #1\n\t" /* Adjust PC according to arm */
"msr CPSR_f, r2\n\t"
"ldr lr, [r0, #0x3c]\n\t" /* context->Lr */
"ldr sp, [r0, #0x38]\n\t" /* context->Sp */
"push {r1}\n\t"
"ldmib r0, {r0-r12}\n\t" /* context->R0..R12 */
"pop {pc}" )
/***********************************************************************
* get_server_context_flags
*
* Convert CPU-specific flags to generic server flags
*/
static unsigned int get_server_context_flags( DWORD flags )
{
unsigned int ret = 0;
flags &= ~CONTEXT_ARM; /* get rid of CPU id */
if (flags & CONTEXT_CONTROL) ret |= SERVER_CTX_CONTROL;
if (flags & CONTEXT_INTEGER) ret |= SERVER_CTX_INTEGER;
if (flags & CONTEXT_FLOATING_POINT) ret |= SERVER_CTX_FLOATING_POINT;
if (flags & CONTEXT_DEBUG_REGISTERS) ret |= SERVER_CTX_DEBUG_REGISTERS;
return ret;
}
/***********************************************************************
* context_to_server
*
* Convert a register context to the server format.
*/
NTSTATUS context_to_server( context_t *to, const CONTEXT *from )
{
DWORD i, flags = from->ContextFlags & ~CONTEXT_ARM; /* get rid of CPU id */
memset( to, 0, sizeof(*to) );
to->cpu = CPU_ARM;
if (flags & CONTEXT_CONTROL)
{
to->flags |= SERVER_CTX_CONTROL;
to->ctl.arm_regs.sp = from->Sp;
to->ctl.arm_regs.lr = from->Lr;
to->ctl.arm_regs.pc = from->Pc;
to->ctl.arm_regs.cpsr = from->Cpsr;
}
if (flags & CONTEXT_INTEGER)
{
to->flags |= SERVER_CTX_INTEGER;
to->integer.arm_regs.r[0] = from->R0;
to->integer.arm_regs.r[1] = from->R1;
to->integer.arm_regs.r[2] = from->R2;
to->integer.arm_regs.r[3] = from->R3;
to->integer.arm_regs.r[4] = from->R4;
to->integer.arm_regs.r[5] = from->R5;
to->integer.arm_regs.r[6] = from->R6;
to->integer.arm_regs.r[7] = from->R7;
to->integer.arm_regs.r[8] = from->R8;
to->integer.arm_regs.r[9] = from->R9;
to->integer.arm_regs.r[10] = from->R10;
to->integer.arm_regs.r[11] = from->R11;
to->integer.arm_regs.r[12] = from->R12;
}
if (flags & CONTEXT_FLOATING_POINT)
{
to->flags |= SERVER_CTX_FLOATING_POINT;
for (i = 0; i < 32; i++) to->fp.arm_regs.d[i] = from->u.D[i];
to->fp.arm_regs.fpscr = from->Fpscr;
}
if (flags & CONTEXT_DEBUG_REGISTERS)
{
to->flags |= SERVER_CTX_DEBUG_REGISTERS;
for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->debug.arm_regs.bvr[i] = from->Bvr[i];
for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->debug.arm_regs.bcr[i] = from->Bcr[i];
for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->debug.arm_regs.wvr[i] = from->Wvr[i];
for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->debug.arm_regs.wcr[i] = from->Wcr[i];
}
return STATUS_SUCCESS;
}
/***********************************************************************
* context_from_server
*
* Convert a register context from the server format.
*/
NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
{
DWORD i;
if (from->cpu != CPU_ARM) return STATUS_INVALID_PARAMETER;
to->ContextFlags = CONTEXT_ARM;
if (from->flags & SERVER_CTX_CONTROL)
{
to->ContextFlags |= CONTEXT_CONTROL;
to->Sp = from->ctl.arm_regs.sp;
to->Lr = from->ctl.arm_regs.lr;
to->Pc = from->ctl.arm_regs.pc;
to->Cpsr = from->ctl.arm_regs.cpsr;
}
if (from->flags & SERVER_CTX_INTEGER)
{
to->ContextFlags |= CONTEXT_INTEGER;
to->R0 = from->integer.arm_regs.r[0];
to->R1 = from->integer.arm_regs.r[1];
to->R2 = from->integer.arm_regs.r[2];
to->R3 = from->integer.arm_regs.r[3];
to->R4 = from->integer.arm_regs.r[4];
to->R5 = from->integer.arm_regs.r[5];
to->R6 = from->integer.arm_regs.r[6];
to->R7 = from->integer.arm_regs.r[7];
to->R8 = from->integer.arm_regs.r[8];
to->R9 = from->integer.arm_regs.r[9];
to->R10 = from->integer.arm_regs.r[10];
to->R11 = from->integer.arm_regs.r[11];
to->R12 = from->integer.arm_regs.r[12];
}
if (from->flags & SERVER_CTX_FLOATING_POINT)
{
to->ContextFlags |= CONTEXT_FLOATING_POINT;
for (i = 0; i < 32; i++) to->u.D[i] = from->fp.arm_regs.d[i];
to->Fpscr = from->fp.arm_regs.fpscr;
}
if (from->flags & SERVER_CTX_DEBUG_REGISTERS)
{
to->ContextFlags |= CONTEXT_DEBUG_REGISTERS;
for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->Bvr[i] = from->debug.arm_regs.bvr[i];
for (i = 0; i < ARM_MAX_BREAKPOINTS; i++) to->Bcr[i] = from->debug.arm_regs.bcr[i];
for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->Wvr[i] = from->debug.arm_regs.wvr[i];
for (i = 0; i < ARM_MAX_WATCHPOINTS; i++) to->Wcr[i] = from->debug.arm_regs.wcr[i];
}
return STATUS_SUCCESS;
}
/***********************************************************************
* NtSetContextThread (NTDLL.@)
* ZwSetContextThread (NTDLL.@)
*/
NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
{
NTSTATUS ret;
BOOL self;
context_t server_context;
context_to_server( &server_context, context );
ret = set_thread_context( handle, &server_context, &self );
if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
return ret;
}
/***********************************************************************
* NtGetContextThread (NTDLL.@)
* ZwGetContextThread (NTDLL.@)
*/
NTSTATUS WINAPI NtGetContextThread( HANDLE handle, CONTEXT *context )
{
NTSTATUS ret;
struct syscall_frame *frame = arm_thread_data()->syscall_frame;
DWORD needed_flags = context->ContextFlags & ~CONTEXT_ARM;
BOOL self = (handle == GetCurrentThread());
if (!self)
{
context_t server_context;
unsigned int server_flags = get_server_context_flags( context->ContextFlags );
if ((ret = get_thread_context( handle, &server_context, server_flags, &self ))) return ret;
if ((ret = context_from_server( context, &server_context ))) return ret;
needed_flags &= ~context->ContextFlags;
}
if (self)
{
if (needed_flags & CONTEXT_INTEGER)
{
context->R0 = 0;
context->R1 = 0;
context->R2 = 0;
context->R3 = 0;
context->R4 = frame->r4;
context->R5 = frame->r5;
context->R6 = frame->r6;
context->R7 = frame->r7;
context->R8 = frame->r8;
context->R9 = frame->r9;
context->R10 = frame->r10;
context->R11 = frame->r11;
context->R12 = 0;
context->ContextFlags |= CONTEXT_INTEGER;
}
if (needed_flags & CONTEXT_CONTROL)
{
context->Sp = (DWORD)&frame->r4;
context->Lr = frame->thunk_addr;
context->Pc = frame->thunk_addr;
context->Cpsr = frame->cpsr;
context->ContextFlags |= CONTEXT_CONTROL;
}
if (needed_flags & CONTEXT_FLOATING_POINT) FIXME( "floating point not implemented\n" );
}
return STATUS_SUCCESS;
}
extern void raise_func_trampoline_thumb( EXCEPTION_RECORD *rec, CONTEXT *context, void *func );
__ASM_GLOBAL_FUNC( raise_func_trampoline_thumb,
".thumb\n\t"
"bx r2\n\t"
"bkpt")
extern void raise_func_trampoline_arm( EXCEPTION_RECORD *rec, CONTEXT *context, void *func );
__ASM_GLOBAL_FUNC( raise_func_trampoline_arm,
".arm\n\t"
"bx r2\n\t"
"bkpt")
/***********************************************************************
* setup_exception
*
* Modify the signal context to call the exception raise function.
*/
static void setup_exception( ucontext_t *sigcontext, EXCEPTION_RECORD *rec )
{
struct
{
CONTEXT context;
EXCEPTION_RECORD rec;
} *stack;
void *stack_ptr = (void *)(SP_sig(sigcontext) & ~3);
CONTEXT context;
NTSTATUS status;
rec->ExceptionAddress = (void *)PC_sig(sigcontext);
save_context( &context, sigcontext );
status = send_debug_event( rec, &context, TRUE );
if (status == DBG_CONTINUE || status == DBG_EXCEPTION_HANDLED)
{
restore_context( &context, sigcontext );
return;
}
stack = virtual_setup_exception( stack_ptr, sizeof(*stack), rec );
stack->rec = *rec;
stack->context = context;
/* now modify the sigcontext to return to the raise function */
SP_sig(sigcontext) = (DWORD)stack;
if (CPSR_sig(sigcontext) & 0x20)
PC_sig(sigcontext) = (DWORD)raise_func_trampoline_thumb;
else
PC_sig(sigcontext) = (DWORD)raise_func_trampoline_arm;
REGn_sig(0, sigcontext) = (DWORD)&stack->rec; /* first arg for KiUserExceptionDispatcher */
REGn_sig(1, sigcontext) = (DWORD)&stack->context; /* second arg for KiUserExceptionDispatcher */
REGn_sig(2, sigcontext) = (DWORD)pKiUserExceptionDispatcher;
}
void WINAPI call_user_exception_dispatcher( EXCEPTION_RECORD *rec, CONTEXT *context,
NTSTATUS (WINAPI *dispatcher)(EXCEPTION_RECORD*,CONTEXT*) )
{
dispatcher( rec, context );
}
/**********************************************************************
* segv_handler
*
* Handler for SIGSEGV and related errors.
*/
static void segv_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
EXCEPTION_RECORD rec = { 0 };
ucontext_t *context = sigcontext;
switch (get_trap_code(signal, context))
{
case TRAP_ARM_PRIVINFLT: /* Invalid opcode exception */
rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
break;
case TRAP_ARM_PAGEFLT: /* Page fault */
rec.NumberParameters = 2;
rec.ExceptionInformation[0] = (get_error_code(context) & 0x800) != 0;
rec.ExceptionInformation[1] = (ULONG_PTR)siginfo->si_addr;
rec.ExceptionCode = virtual_handle_fault( siginfo->si_addr, rec.ExceptionInformation[0],
(void *)SP_sig(context) );
if (!rec.ExceptionCode) return;
break;
case TRAP_ARM_ALIGNFLT: /* Alignment check exception */
rec.ExceptionCode = EXCEPTION_DATATYPE_MISALIGNMENT;
break;
case TRAP_ARM_UNKNOWN: /* Unknown fault code */
rec.ExceptionCode = EXCEPTION_ACCESS_VIOLATION;
rec.NumberParameters = 2;
rec.ExceptionInformation[0] = 0;
rec.ExceptionInformation[1] = 0xffffffff;
break;
default:
ERR("Got unexpected trap %d\n", get_trap_code(signal, context));
rec.ExceptionCode = EXCEPTION_ILLEGAL_INSTRUCTION;
break;
}
setup_exception( context, &rec );
}
/**********************************************************************
* trap_handler
*
* Handler for SIGTRAP.
*/
static void trap_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
EXCEPTION_RECORD rec = { 0 };
switch (siginfo->si_code)
{
case TRAP_TRACE:
rec.ExceptionCode = EXCEPTION_SINGLE_STEP;
break;
case TRAP_BRKPT:
default:
rec.ExceptionCode = EXCEPTION_BREAKPOINT;
rec.NumberParameters = 1;
break;
}
setup_exception( sigcontext, &rec );
}
/**********************************************************************
* fpe_handler
*
* Handler for SIGFPE.
*/
static void fpe_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
EXCEPTION_RECORD rec = { 0 };
switch (siginfo->si_code & 0xffff )
{
#ifdef FPE_FLTSUB
case FPE_FLTSUB:
rec.ExceptionCode = EXCEPTION_ARRAY_BOUNDS_EXCEEDED;
break;
#endif
#ifdef FPE_INTDIV
case FPE_INTDIV:
rec.ExceptionCode = EXCEPTION_INT_DIVIDE_BY_ZERO;
break;
#endif
#ifdef FPE_INTOVF
case FPE_INTOVF:
rec.ExceptionCode = EXCEPTION_INT_OVERFLOW;
break;
#endif
#ifdef FPE_FLTDIV
case FPE_FLTDIV:
rec.ExceptionCode = EXCEPTION_FLT_DIVIDE_BY_ZERO;
break;
#endif
#ifdef FPE_FLTOVF
case FPE_FLTOVF:
rec.ExceptionCode = EXCEPTION_FLT_OVERFLOW;
break;
#endif
#ifdef FPE_FLTUND
case FPE_FLTUND:
rec.ExceptionCode = EXCEPTION_FLT_UNDERFLOW;
break;
#endif
#ifdef FPE_FLTRES
case FPE_FLTRES:
rec.ExceptionCode = EXCEPTION_FLT_INEXACT_RESULT;
break;
#endif
#ifdef FPE_FLTINV
case FPE_FLTINV:
#endif
default:
rec.ExceptionCode = EXCEPTION_FLT_INVALID_OPERATION;
break;
}
setup_exception( sigcontext, &rec );
}
/**********************************************************************
* int_handler
*
* Handler for SIGINT.
*/
static void int_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
EXCEPTION_RECORD rec = { CONTROL_C_EXIT };
setup_exception( sigcontext, &rec );
}
/**********************************************************************
* abrt_handler
*
* Handler for SIGABRT.
*/
static void abrt_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
EXCEPTION_RECORD rec = { EXCEPTION_WINE_ASSERTION, EH_NONCONTINUABLE };
setup_exception( sigcontext, &rec );
}
/**********************************************************************
* quit_handler
*
* Handler for SIGQUIT.
*/
static void quit_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
abort_thread(0);
}
/**********************************************************************
* usr1_handler
*
* Handler for SIGUSR1, used to signal a thread that it got suspended.
*/
static void usr1_handler( int signal, siginfo_t *siginfo, void *sigcontext )
{
CONTEXT context;
save_context( &context, sigcontext );
wait_suspend( &context );
restore_context( &context, sigcontext );
}
/**********************************************************************
* get_thread_ldt_entry
*/
NTSTATUS get_thread_ldt_entry( HANDLE handle, void *data, ULONG len, ULONG *ret_len )
{
return STATUS_NOT_IMPLEMENTED;
}
/******************************************************************************
* NtSetLdtEntries (NTDLL.@)
* ZwSetLdtEntries (NTDLL.@)
*/
NTSTATUS WINAPI NtSetLdtEntries( ULONG sel1, LDT_ENTRY entry1, ULONG sel2, LDT_ENTRY entry2 )
{
return STATUS_NOT_IMPLEMENTED;
}
/**********************************************************************
* signal_init_threading
*/
void signal_init_threading(void)
{
pthread_key_create( &teb_key, NULL );
}
/**********************************************************************
* signal_alloc_thread
*/
NTSTATUS signal_alloc_thread( TEB *teb )
{
return STATUS_SUCCESS;
}
/**********************************************************************
* signal_free_thread
*/
void signal_free_thread( TEB *teb )
{
}
/**********************************************************************
* signal_init_thread
*/
void signal_init_thread( TEB *teb )
{
#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_8A__)
/* Win32/ARM applications expect the TEB pointer to be in the TPIDRURW register. */
__asm__ __volatile__( "mcr p15, 0, %0, c13, c0, 2" : : "r" (teb) );
#endif
pthread_setspecific( teb_key, teb );
}
/**********************************************************************
* signal_init_process
*/
void signal_init_process(void)
{
struct sigaction sig_act;
sig_act.sa_mask = server_block_set;
sig_act.sa_flags = SA_RESTART | SA_SIGINFO | SA_ONSTACK;
sig_act.sa_sigaction = int_handler;
if (sigaction( SIGINT, &sig_act, NULL ) == -1) goto error;
sig_act.sa_sigaction = fpe_handler;
if (sigaction( SIGFPE, &sig_act, NULL ) == -1) goto error;
sig_act.sa_sigaction = abrt_handler;
if (sigaction( SIGABRT, &sig_act, NULL ) == -1) goto error;
sig_act.sa_sigaction = quit_handler;
if (sigaction( SIGQUIT, &sig_act, NULL ) == -1) goto error;
sig_act.sa_sigaction = usr1_handler;
if (sigaction( SIGUSR1, &sig_act, NULL ) == -1) goto error;
sig_act.sa_sigaction = trap_handler;
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
sig_act.sa_sigaction = segv_handler;
if (sigaction( SIGSEGV, &sig_act, NULL ) == -1) goto error;
if (sigaction( SIGILL, &sig_act, NULL ) == -1) goto error;
if (sigaction( SIGBUS, &sig_act, NULL ) == -1) goto error;
return;
error:
perror("sigaction");
exit(1);
}
/***********************************************************************
* init_thread_context
*/
static void init_thread_context( CONTEXT *context, LPTHREAD_START_ROUTINE entry, void *arg, void *relay )
{
context->R0 = (DWORD)entry;
context->R1 = (DWORD)arg;
context->Sp = (DWORD)NtCurrentTeb()->Tib.StackBase;
context->Pc = (DWORD)relay;
}
/***********************************************************************
* attach_thread
*/
PCONTEXT DECLSPEC_HIDDEN attach_thread( LPTHREAD_START_ROUTINE entry, void *arg,
BOOL suspend, void *relay )
{
CONTEXT *ctx;
if (suspend)
{
CONTEXT context = { CONTEXT_ALL };
init_thread_context( &context, entry, arg, relay );
wait_suspend( &context );
ctx = (CONTEXT *)((ULONG_PTR)context.Sp & ~15) - 1;
*ctx = context;
}
else
{
ctx = (CONTEXT *)NtCurrentTeb()->Tib.StackBase - 1;
init_thread_context( ctx, entry, arg, relay );
}
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
ctx->ContextFlags = CONTEXT_FULL;
pLdrInitializeThunk( ctx, (void **)&ctx->R0, 0, 0 );
return ctx;
}
/***********************************************************************
* signal_start_thread
*/
__ASM_GLOBAL_FUNC( signal_start_thread,
".arm\n\t"
"push {r4-r12,lr}\n\t"
/* store exit frame */
"ldr r4, [sp, #40]\n\t" /* teb */
"str sp, [r4, #0x1d4]\n\t" /* teb->GdiTebBatch */
/* switch to thread stack */
"ldr r4, [r4, #4]\n\t" /* teb->Tib.StackBase */
"sub sp, r4, #0x1000\n\t"
/* attach dlls */
"bl " __ASM_NAME("attach_thread") "\n\t"
"mov sp, r0\n\t"
/* clear the stack */
"and r0, #~0xff0\n\t" /* round down to page size */
"bl " __ASM_NAME("virtual_clear_thread_stack") "\n\t"
/* switch to the initial context */
"mov r1, #1\n\t"
"mov r0, sp\n\t"
"b " __ASM_NAME("NtContinue") )
extern void DECLSPEC_NORETURN call_thread_exit_func( int status, void (*func)(int), TEB *teb );
__ASM_GLOBAL_FUNC( call_thread_exit_func,
".arm\n\t"
"ldr r3, [r2, #0x1d4]\n\t" /* teb->GdiTebBatch */
"mov ip, #0\n\t"
"str ip, [r2, #0x1d4]\n\t"
"cmp r3, ip\n\t"
"movne sp, r3\n\t"
"blx r1" )
/***********************************************************************
* signal_exit_thread
*/
void signal_exit_thread( int status, void (*func)(int) )
{
call_thread_exit_func( status, func, NtCurrentTeb() );
}
/**********************************************************************
* NtCurrentTeb (NTDLL.@)
*/
TEB * WINAPI NtCurrentTeb(void)
{
return pthread_getspecific( teb_key );
}
#endif /* __arm__ */
|
the_stack_data/557128.c | //SKIP PARAM: --set ana.activated[+] affeq --set sem.int.signed_overflow assume_none
int next;
int main() {
next = 0;
// Due to a bug in the dim add function, t was always set to 0 in the following block
int t;
next = t;
if (next == 0) {
t = 10;
}
assert (t == 10); //UNKNOWN!
}
|
the_stack_data/212644056.c | /*
Copyright (c) 1994-2003, Jason W. Bacon, Acadix Software Systems
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.
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 COPYRIGHT
OWNER 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 <stdio.h>
#include <string.h>
int main()
{
char name[100],type[100],line[1001];
int subscript,count;
FILE *infile;
#ifdef COHERENT
char *format = "#define %s __CUR __TERM %s [%d]\n",
*booleans = "(Booleans)",
*numbers = "(Numbers)",
*strings = "(Strings)",
*ostype = "COHERENT",
*filename = "/usr/include/term.h";
#endif
#ifdef FreeBSD
char *format1 = "#define %s (_CUR_TERM.%5s[%d])\n",
*format2 = "#define %s (_CUR_TERM.%4s[%d])\n",
*booleans = "bools",
*numbers = "nums",
*strings = "strs",
*ostype = "FreeBSD",
*filename = "/usr/include/term.h";
#endif
#ifdef linux
char *format1 = "#define %s CUR %8s[%d]\n",
*format2 = "#define %s CUR %7s[%d]\n",
*booleans = "Booleans",
*numbers = "Numbers",
*strings = "Strings",
*ostype = "linux",
*filename = "/usr/include/ncurses/term.h";
#endif
infile = fopen(filename,"r");
if ( infile == NULL )
{
fprintf(stderr,"Could not open %s.\n",filename);
exit(1);
}
printf("#ifdef %s\n",ostype);
while ( !feof(infile) )
{
fgets(line,1000,infile);
count = sscanf(line, format1, name, type, &subscript);
if ( count != 3 )
count = sscanf(line, format2, name, type, &subscript);
if ( count == 3 )
{
if ( strcmp(type,booleans) == 0 )
{
printf(" boolean %s; /* %d */\n",name,subscript);
}
else if ( strcmp(type,numbers) == 0 )
{
printf(" int %s; /* %d */\n",name,subscript);
}
else if ( strcmp(type,strings) == 0 )
{
printf(" char *%s; /* %d */\n",name,subscript);
}
else
fprintf(stderr,"Unknown type: %s\n",type);
}
}
puts("#endif");
fclose(infile);
return 0;
}
|
the_stack_data/18888876.c | // Bucket Sort in C programming
#include <stdio.h>
int getMax(int array[], int size)
{
int max = array[0];
for (int i = 1; i < size; i++)
if (array[i] > max)
max = array[i];
return max;
}
void bucketSort(int array[], int size)
{
// The size of bucket must be at least the (max+1) but
// we cannot assign declare it as int bucket(max+1) in C as
// it does not support dynamic memory allocation.
// So, its size is provided statically.
int bucket[10];
const int max = getMax(array, size);
for (int i = 0; i <= max; i++)
{
bucket[i] = 0;
}
for (int i = 0; i < size; i++)
{
bucket[array[i]]++;
}
for (int i = 0, j = 0; i <= max; i++)
{
while (bucket[i] > 0)
{
array[j++] = i;
bucket[i]--;
}
}
}
void printArray(int array[], int size)
{
for (int i = 0; i < size; ++i)
{
printf("%d ", array[i]);
}
printf("\n");
}
int main()
{
int data[] = {4, 3, 4, 5, 6, 0, 9, 5};
int size = sizeof(data) / sizeof(data[0]);
bucketSort(data, size);
printf("Sorted array in ascending order: \n");
printArray(data, size);
} |
the_stack_data/150144051.c | #include <stdio.h>
int main(){
printf("sizeof(int):\t%ld\n",sizeof(int));
printf("sizeof(short):\t%ld\n",sizeof(short));
printf("sizeof(long):\t%ld\n",sizeof(long));
printf("sizeof(long long):\t%ld\n",sizeof(long long));
printf("sizeof(char):\t%ld\n",sizeof(char));
printf("sizeof(float):\t%ld\n",sizeof(float));
printf("sizeof(double):\t%ld\n",sizeof(double));
return 0;
}
|
the_stack_data/98574538.c | /* -*- mode: C; c-basic-offset: 3; -*- */
/*--------------------------------------------------------------------*/
/*--- Reading of ARM(32) EXIDX unwind information readexidx.c ---*/
/*--------------------------------------------------------------------*/
/*
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2014-2015 Mozilla Foundation
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 of the
License, or (at your option) any later version.
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.
The GNU General Public License is contained in the file COPYING.
*/
/* libunwind - a platform-independent unwind library
Copyright 2011 Linaro Limited
This file is part of libunwind.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
// Copyright (c) 2010 Google Inc.
// 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 Google Inc. 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 COPYRIGHT
// OWNER 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.
// Derived originally from libunwind, with very extensive modifications.
/* Contributed by Julian Seward <[email protected]> */
// This file translates EXIDX unwind information into the same format
// that Valgrind uses for CFI information. Hence Valgrind's CFI
// unwinding abilities also become usable for EXIDX.
//
// See: "Exception Handling ABI for the ARM Architecture", ARM IHI 0038A
// http://infocenter.arm.com/help/topic/com.arm.doc.ihi0038a/IHI0038A_ehabi.pdf
// EXIDX data is presented in two parts:
//
// * an index table. This contains two words per routine,
// the first of which identifies the routine, and the second
// of which is a reference to the unwind bytecode. If the
// bytecode is very compact -- 3 bytes or less -- it can be
// stored directly in the second word.
//
// * an area containing the unwind bytecodes.
//
// General flow is: ML_(read_exidx) iterates over all
// of the index table entries (pairs). For each entry, it:
//
// * calls ExtabEntryExtract to copy the bytecode out into
// an intermediate buffer.
// * uses ExtabEntryDecode to parse the intermediate
// buffer. Each bytecode instruction is bundled into a
// arm_ex_to_module::extab_data structure, and handed to ..
//
// * .. TranslateCmd, which generates the pseudo-CFI
// records that Valgrind stores.
// This file is derived from the following files in the Mozilla tree
// toolkit/crashreporter/google-breakpad:
// src/common/arm_ex_to_module.cc
// src/common/arm_ex_reader.cc
#if defined(VGA_arm)
#include "pub_core_basics.h"
#include "pub_core_libcbase.h"
#include "pub_core_libcprint.h"
#include "pub_core_libcassert.h"
#include "pub_core_options.h"
#include "priv_storage.h"
#include "priv_readexidx.h"
static void complain ( const HChar* str )
{
if (!VG_(clo_xml) && VG_(clo_verbosity) > 1)
VG_(message)(Vg_UserMsg,
" Warning: whilst reading EXIDX: %s\n", str);
}
/*------------------------------------------------------------*/
/*--- MemoryRange ---*/
/*------------------------------------------------------------*/
typedef struct { Addr start; SizeT len; } MemoryRange;
/* Initialise |mr| for [start .. start+len). Zero ranges are allowed,
but wraparounds are not. Returns True on success. */
static Bool MemoryRange__init ( /*OUT*/MemoryRange* mr,
const void* startV, SizeT len )
{
VG_(memset)(mr, 0, sizeof(*mr));
/* This relies on Addr being unsigned. */
Addr start = (Addr)startV;
if (len > 0 && start + len - 1 < start) {
return False;
}
mr->start = start;
mr->len = len;
return True;
}
static Bool MemoryRange__covers ( MemoryRange* mr,
const void* startV, SizeT len )
{
vg_assert(len > 0);
if (mr->len == 0) {
return False;
}
Addr start = (Addr)startV;
return start >= mr->start && start + len - 1 <= mr->start + mr->len - 1;
}
/*------------------------------------------------------------*/
/*--- (Pass 1 of 3) The EXIDX extractor ---*/
/*------------------------------------------------------------*/
#define ARM_EXIDX_CANT_UNWIND 0x00000001
#define ARM_EXIDX_COMPACT 0x80000000
#define ARM_EXTBL_OP_FINISH 0xb0
#define ARM_EXIDX_TABLE_LIMIT (255*4)
/* These are in the ARM-defined format, so their layout is important. */
typedef
struct { UInt addr; UInt data; }
ExidxEntry;
typedef
enum {
ExSuccess=1, // success
ExInBufOverflow, // out-of-range while reading .exidx
ExOutBufOverflow, // output buffer is too small
ExCantUnwind, // this function is marked CANT_UNWIND
ExCantRepresent, // entry valid, but we can't represent it
ExInvalid // entry is invalid
}
ExExtractResult;
/* Helper function for fishing bits out of the EXIDX representation. */
static const void* Prel31ToAddr(const void* addr)
{
UInt offset32 = *(const UInt*)addr;
// sign extend offset32[30:0] to 64 bits -- copy bit 30 to positions
// 63:31 inclusive.
ULong offset64 = offset32;
if (offset64 & (1ULL << 30))
offset64 |= 0xFFFFFFFF80000000ULL;
else
offset64 &= 0x000000007FFFFFFFULL;
return ((const UChar*)addr) + (UWord)offset64;
}
// Extract unwind bytecode for the function denoted by |entry| into |buf|,
// and return the number of bytes of |buf| written, along with a code
// indicating the outcome.
static
ExExtractResult ExtabEntryExtract ( MemoryRange* mr_exidx,
MemoryRange* mr_extab,
const ExidxEntry* entry,
UChar* buf, SizeT buf_size,
/*OUT*/SizeT* buf_used)
{
Bool ok;
MemoryRange mr_out;
ok = MemoryRange__init(&mr_out, buf, buf_size);
if (!ok) return ExOutBufOverflow;
*buf_used = 0;
# define PUT_BUF_U8(_byte) \
do { if (!MemoryRange__covers(&mr_out, &buf[*buf_used], 1)) \
return ExOutBufOverflow; \
buf[(*buf_used)++] = (_byte); } while (0)
# define GET_EX_U32(_lval, _addr, _mr) \
do { if (!MemoryRange__covers((_mr), (const void*)(_addr), 4)) \
return ExInBufOverflow; \
(_lval) = *(const UInt*)(_addr); } while (0)
# define GET_EXIDX_U32(_lval, _addr) \
GET_EX_U32(_lval, _addr, mr_exidx)
# define GET_EXTAB_U32(_lval, _addr) \
GET_EX_U32(_lval, _addr, mr_extab)
UInt data;
GET_EXIDX_U32(data, &entry->data);
// A function can be marked CANT_UNWIND if (eg) it is known to be
// at the bottom of the stack.
if (data == ARM_EXIDX_CANT_UNWIND)
return ExCantUnwind;
UInt pers; // personality number
UInt extra; // number of extra data words required
UInt extra_allowed; // number of extra data words allowed
const UInt* extbl_data; // the handler entry, if not inlined
if (data & ARM_EXIDX_COMPACT) {
// The handler table entry has been inlined into the index table entry.
// In this case it can only be an ARM-defined compact model, since
// bit 31 is 1. Only personalities 0, 1 and 2 are defined for the
// ARM compact model, but 1 and 2 are "Long format" and may require
// extra data words. Hence the allowable personalities here are:
// personality 0, in which case 'extra' has no meaning
// personality 1, with zero extra words
// personality 2, with zero extra words
extbl_data = NULL;
pers = (data >> 24) & 0x0F;
extra = (data >> 16) & 0xFF;
extra_allowed = 0;
}
else {
// The index table entry is a pointer to the handler entry. Note
// that Prel31ToAddr will read the given address, but we already
// range-checked above.
extbl_data = Prel31ToAddr(&entry->data);
GET_EXTAB_U32(data, extbl_data);
if (!(data & ARM_EXIDX_COMPACT)) {
// This denotes a "generic model" handler. That will involve
// executing arbitrary machine code, which is something we
// can't represent here; hence reject it.
return ExCantRepresent;
}
// So we have a compact model representation. Again, 3 possible
// personalities, but this time up to 255 allowable extra words.
pers = (data >> 24) & 0x0F;
extra = (data >> 16) & 0xFF;
extra_allowed = 255;
extbl_data++;
}
// Now look at the handler table entry. The first word is |data|
// and subsequent words start at |*extbl_data|. The number of
// extra words to use is |extra|, provided that the personality
// allows extra words. Even if it does, none may be available --
// extra_allowed is the maximum number of extra words allowed. */
if (pers == 0) {
// "Su16" in the documentation -- 3 unwinding insn bytes
// |extra| has no meaning here; instead that byte is an unwind-info byte
PUT_BUF_U8(data >> 16);
PUT_BUF_U8(data >> 8);
PUT_BUF_U8(data);
}
else if ((pers == 1 || pers == 2) && extra <= extra_allowed) {
// "Lu16" or "Lu32" respectively -- 2 unwinding insn bytes,
// and up to 255 extra words.
PUT_BUF_U8(data >> 8);
PUT_BUF_U8(data);
UInt j;
for (j = 0; j < extra; j++) {
GET_EXTAB_U32(data, extbl_data);
extbl_data++;
PUT_BUF_U8(data >> 24);
PUT_BUF_U8(data >> 16);
PUT_BUF_U8(data >> 8);
PUT_BUF_U8(data >> 0);
}
}
else {
// The entry is invalid.
return ExInvalid;
}
// Make sure the entry is terminated with "FINISH"
if (*buf_used > 0 && buf[(*buf_used) - 1] != ARM_EXTBL_OP_FINISH)
PUT_BUF_U8(ARM_EXTBL_OP_FINISH);
return ExSuccess;
# undef GET_EXTAB_U32
# undef GET_EXIDX_U32
# undef GET_U32
# undef PUT_BUF_U8
}
/*------------------------------------------------------------*/
/*--- (Pass 2 of 3) The EXIDX decoder ---*/
/*------------------------------------------------------------*/
/* This (ExtabData) is an intermediate structure, used to carry
information from the decoder (pass 2) to the summariser (pass 3).
I don't think its layout is important. */
typedef
enum {
ARM_EXIDX_CMD_FINISH=0x100,
ARM_EXIDX_CMD_SUB_FROM_VSP,
ARM_EXIDX_CMD_ADD_TO_VSP,
ARM_EXIDX_CMD_REG_POP,
ARM_EXIDX_CMD_REG_TO_SP,
ARM_EXIDX_CMD_VFP_POP,
ARM_EXIDX_CMD_WREG_POP,
ARM_EXIDX_CMD_WCGR_POP,
ARM_EXIDX_CMD_RESERVED,
ARM_EXIDX_CMD_REFUSED
}
ExtabCmd;
static const HChar* showExtabCmd ( ExtabCmd cmd ) {
switch (cmd) {
case ARM_EXIDX_CMD_FINISH: return "FINISH";
case ARM_EXIDX_CMD_SUB_FROM_VSP: return "SUB_FROM_VSP";
case ARM_EXIDX_CMD_ADD_TO_VSP: return "ADD_TO_VSP";
case ARM_EXIDX_CMD_REG_POP: return "REG_POP";
case ARM_EXIDX_CMD_REG_TO_SP: return "REG_TO_SP";
case ARM_EXIDX_CMD_VFP_POP: return "VFP_POP";
case ARM_EXIDX_CMD_WREG_POP: return "WREG_POP";
case ARM_EXIDX_CMD_WCGR_POP: return "WCGR_POP";
case ARM_EXIDX_CMD_RESERVED: return "RESERVED";
case ARM_EXIDX_CMD_REFUSED: return "REFUSED";
default: return "???";
}
}
typedef
struct { ExtabCmd cmd; UInt data; }
ExtabData;
static void ppExtabData ( const ExtabData* etd ) {
VG_(printf)("ExtabData{%-12s 0x%08x}", showExtabCmd(etd->cmd), etd->data);
}
enum extab_cmd_flags {
ARM_EXIDX_VFP_SHIFT_16 = 1 << 16,
ARM_EXIDX_VFP_FSTMD = 1 << 17, // distinguishes FSTMxxD from FSTMxxX
};
/* Forwards */
typedef struct _SummState SummState;
static Int TranslateCmd(/*MOD*/SummState* state, const ExtabData* edata);
// Take the unwind information extracted by ExtabEntryExtract
// and parse it into frame-unwind instructions. These are as
// specified in "Table 4, ARM-defined frame-unwinding instructions"
// in the specification document detailed in comments at the top
// of this file.
//
// This reads from |buf[0, +data_size)|. It checks for overruns of
// the input buffer and returns a negative value if that happens, or
// for any other failure cases. It returns zero in case of success.
// Whilst reading the input, it dumps the result in |*state|.
static
Int ExtabEntryDecode(/*OUT*/SummState* state, const UChar* buf, SizeT buf_size)
{
if (buf == NULL || buf_size == 0)
return -3;
MemoryRange mr_in;
Bool ok = MemoryRange__init(&mr_in, buf, buf_size);
if (!ok)
return -2;
# define GET_BUF_U8(_lval) \
do { if (!MemoryRange__covers(&mr_in, buf, 1)) \
return -4; \
(_lval) = *(buf++); } while (0)
const UChar* end = buf + buf_size;
while (buf < end) {
ExtabData edata;
VG_(bzero_inline)(&edata, sizeof(edata));
UChar op;
GET_BUF_U8(op);
if ((op & 0xc0) == 0x00) {
// vsp = vsp + (xxxxxx << 2) + 4
edata.cmd = ARM_EXIDX_CMD_ADD_TO_VSP;
edata.data = (((Int)op & 0x3f) << 2) + 4;
}
else if ((op & 0xc0) == 0x40) {
// vsp = vsp - (xxxxxx << 2) - 4
edata.cmd = ARM_EXIDX_CMD_SUB_FROM_VSP;
edata.data = (((Int)op & 0x3f) << 2) + 4;
}
else if ((op & 0xf0) == 0x80) {
UChar op2;
GET_BUF_U8(op2);
if (op == 0x80 && op2 == 0x00) {
// Refuse to unwind
edata.cmd = ARM_EXIDX_CMD_REFUSED;
} else {
// Pop up to 12 integer registers under masks {r15-r12},{r11-r4}
edata.cmd = ARM_EXIDX_CMD_REG_POP;
edata.data = ((op & 0xf) << 8) | op2;
edata.data = edata.data << 4;
}
}
else if ((op & 0xf0) == 0x90) {
if (op == 0x9d || op == 0x9f) {
// 9d: Reserved as prefix for ARM register to register moves
// 9f: Reserved as prefix for Intel Wireless MMX reg to reg moves
edata.cmd = ARM_EXIDX_CMD_RESERVED;
} else {
// Set vsp = r[nnnn]
edata.cmd = ARM_EXIDX_CMD_REG_TO_SP;
edata.data = op & 0x0f;
}
}
else if ((op & 0xf0) == 0xa0) {
// Pop r4 to r[4+nnn], or
// Pop r4 to r[4+nnn] and r14
Int nnn = (op & 0x07);
edata.data = (1 << (nnn + 1)) - 1;
edata.data = edata.data << 4;
if (op & 0x08) edata.data |= 1 << 14;
edata.cmd = ARM_EXIDX_CMD_REG_POP;
}
else if (op == ARM_EXTBL_OP_FINISH) {
// Finish
edata.cmd = ARM_EXIDX_CMD_FINISH;
buf = end;
}
else if (op == 0xb1) {
UChar op2;
GET_BUF_U8(op2);
if (op2 == 0 || (op2 & 0xf0)) {
// Spare
edata.cmd = ARM_EXIDX_CMD_RESERVED;
} else {
// Pop integer registers under mask {r3,r2,r1,r0}
edata.cmd = ARM_EXIDX_CMD_REG_POP;
edata.data = op2 & 0x0f;
}
}
else if (op == 0xb2) {
// vsp = vsp + 0x204 + (uleb128 << 2)
ULong offset = 0;
UChar byte, shift = 0;
do {
GET_BUF_U8(byte);
offset |= (byte & 0x7f) << shift;
shift += 7;
} while ((byte & 0x80) && buf < end);
edata.data = offset * 4 + 0x204;
edata.cmd = ARM_EXIDX_CMD_ADD_TO_VSP;
}
else if (op == 0xb3 || op == 0xc8 || op == 0xc9) {
// b3: Pop VFP regs D[ssss] to D[ssss+cccc], FSTMFDX-ishly
// c8: Pop VFP regs D[16+ssss] to D[16+ssss+cccc], FSTMFDD-ishly
// c9: Pop VFP regs D[ssss] to D[ssss+cccc], FSTMFDD-ishly
edata.cmd = ARM_EXIDX_CMD_VFP_POP;
GET_BUF_U8(edata.data);
if (op == 0xc8) edata.data |= ARM_EXIDX_VFP_SHIFT_16;
if (op != 0xb3) edata.data |= ARM_EXIDX_VFP_FSTMD;
}
else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) {
// b8: Pop VFP regs D[8] to D[8+nnn], FSTMFDX-ishly
// d0: Pop VFP regs D[8] to D[8+nnn], FSTMFDD-ishly
edata.cmd = ARM_EXIDX_CMD_VFP_POP;
edata.data = 0x80 | (op & 0x07);
if ((op & 0xf8) == 0xd0) edata.data |= ARM_EXIDX_VFP_FSTMD;
}
else if (op >= 0xc0 && op <= 0xc5) {
// Intel Wireless MMX pop wR[10]-wr[10+nnn], nnn != 6,7
edata.cmd = ARM_EXIDX_CMD_WREG_POP;
edata.data = 0xa0 | (op & 0x07);
}
else if (op == 0xc6) {
// Intel Wireless MMX pop wR[ssss] to wR[ssss+cccc]
edata.cmd = ARM_EXIDX_CMD_WREG_POP;
GET_BUF_U8(edata.data);
}
else if (op == 0xc7) {
UChar op2;
GET_BUF_U8(op2);
if (op2 == 0 || (op2 & 0xf0)) {
// Spare
edata.cmd = ARM_EXIDX_CMD_RESERVED;
} else {
// Intel Wireless MMX pop wCGR registers under mask {wCGR3,2,1,0}
edata.cmd = ARM_EXIDX_CMD_WCGR_POP;
edata.data = op2 & 0x0f;
}
}
else {
// Spare
edata.cmd = ARM_EXIDX_CMD_RESERVED;
}
if (0)
VG_(printf)(" edata: cmd %08x data %08x\n",
(UInt)edata.cmd, edata.data);
Int ret = TranslateCmd ( state, &edata );
if (ret < 0) return ret;
}
return 0;
# undef GET_BUF_U8
}
/*------------------------------------------------------------*/
/*--- (Pass 3 of 3) The EXIDX summariser ---*/
/*------------------------------------------------------------*/
/* In this translation into DiCfSI_m, we're going to have the CFA play
the role of the VSP. That means that the VSP can be exactly any of
the CFA expressions, viz: {r7,r11,r12,r13) +/- offset.
All of this would be a lot simpler if the DiCfSI_m representation
was just a bit more expressive and orthogonal. But it isn't.
The central difficulty is that, although we can track changes
to the offset of VSP (via vsp_off), we can't deal with assignments
of an entirely new expression to it, because the existing
rules in |cfi| will almost certainly refer to the CFA, and so
changing it will make them invalid. Hence, below:
* for the case ARM_EXIDX_CMD_REG_TO_SP we simply disallow
assignment, and hence give up, if any rule refers to CFA
* for the case ARM_EXIDX_CMD_REG_POP, the SP (hence, VSP) is
updated by the pop, give up.
This is an ugly hack to work around not having a better (LUL-like)
expression representation. That said, these restrictions don't
appear to be a big problem in practice.
*/
struct _SummState {
// The DiCfSI_m under construction
DiCfSI_m cfi;
Int vsp_off;
// For generating CFI register expressions, if needed.
DebugInfo* di;
};
/* Generate a trivial CfiExpr, for the ARM(32) integer register
numbered |gprNo|. First ensure this DebugInfo has a cfsi_expr
array in which to park it. Returns -1 if |gprNo| cannot be
represented, otherwise returns a value >= 0. */
static
Int gen_CfiExpr_CfiReg_ARM_GPR ( /*MB_MOD*/DebugInfo* di, UInt gprNo )
{
CfiReg creg = Creg_INVALID;
switch (gprNo) {
case 13: creg = Creg_ARM_R13; break;
case 12: creg = Creg_ARM_R12; break;
case 15: creg = Creg_ARM_R15; break;
case 14: creg = Creg_ARM_R14; break;
case 7: creg = Creg_ARM_R7; break;
default: break;
}
if (creg == Creg_INVALID) {
return -1;
}
if (!di->cfsi_exprs) {
di->cfsi_exprs = VG_(newXA)( ML_(dinfo_zalloc), "di.gCCAG",
ML_(dinfo_free), sizeof(CfiExpr) );
}
Int res = ML_(CfiExpr_CfiReg)( di->cfsi_exprs, creg );
vg_assert(res >= 0);
return res;
}
/* Given a DiCfSI_m, find the _how/_off pair for the given ARM(32) GPR
number inside |cfsi_m|, or return NULL for both if that register
number is not represented. */
static
void maybeFindExprForRegno( /*OUT*/UChar** howPP, /*OUT*/Int** offPP,
DiCfSI_m* cfsi_m, Int regNo )
{
switch (regNo) {
case 15: *howPP = &cfsi_m->ra_how; *offPP = &cfsi_m->ra_off; return;
case 14: *howPP = &cfsi_m->r14_how; *offPP = &cfsi_m->r14_off; return;
case 13: *howPP = &cfsi_m->r13_how; *offPP = &cfsi_m->r13_off; return;
case 12: *howPP = &cfsi_m->r12_how; *offPP = &cfsi_m->r12_off; return;
case 11: *howPP = &cfsi_m->r11_how; *offPP = &cfsi_m->r11_off; return;
case 7: *howPP = &cfsi_m->r7_how; *offPP = &cfsi_m->r7_off; return;
default: break;
}
*howPP = NULL; *offPP = NULL;
}
/* Set cfi.cfa_{how,off} so as to be a copy of the expression denoted
by (how,off), if it is possible to do so. Returns True on
success. */
static
Bool setCFAfromCFIR( /*MOD*/DiCfSI_m* cfi, XArray*/*CfiExpr*/ cfsi_exprs,
UChar how, Int off )
{
switch (how) {
case CFIR_EXPR:
if (!cfsi_exprs) return False;
CfiExpr* e = (CfiExpr*)VG_(indexXA)(cfsi_exprs, off);
if (e->tag != Cex_CfiReg) return False;
if (e->Cex.CfiReg.reg == Creg_ARM_R7) {
cfi->cfa_how = CFIC_ARM_R7REL;
cfi->cfa_off = 0;
return True;
}
ML_(ppCfiExpr)(cfsi_exprs, off);
vg_assert(0);
default:
break;
}
VG_(printf)("setCFAfromCFIR: FAIL: how %d off %d\n", how, off);
vg_assert(0);
return False;
}
#define ARM_EXBUF_START(x) (((x) >> 4) & 0x0f)
#define ARM_EXBUF_COUNT(x) ((x) & 0x0f)
#define ARM_EXBUF_END(x) (ARM_EXBUF_START(x) + ARM_EXBUF_COUNT(x))
static Bool mentionsCFA ( DiCfSI_m* cfi )
{
# define MENTIONS_CFA(_how) ((_how) == CFIR_CFAREL || (_how) == CFIR_MEMCFAREL)
if (MENTIONS_CFA(cfi->ra_how)) return True;
if (MENTIONS_CFA(cfi->r14_how)) return True;
if (MENTIONS_CFA(cfi->r13_how)) return True;
if (MENTIONS_CFA(cfi->r12_how)) return True;
if (MENTIONS_CFA(cfi->r11_how)) return True;
if (MENTIONS_CFA(cfi->r7_how)) return True;
return False;
# undef MENTIONS_CFA
}
// Translate command from extab_data to command for Module.
static
Int TranslateCmd(/*MOD*/SummState* state, const ExtabData* edata)
{
/* Stay sane: check that the CFA has the expected form. */
vg_assert(state);
switch (state->cfi.cfa_how) {
case CFIC_ARM_R13REL: case CFIC_ARM_R12REL:
case CFIC_ARM_R11REL: case CFIC_ARM_R7REL: break;
default: vg_assert(0);
}
if (0) {
VG_(printf)(" TranslateCmd: ");
ppExtabData(edata);
VG_(printf)("\n");
}
Int ret = 0;
switch (edata->cmd) {
case ARM_EXIDX_CMD_FINISH:
/* Copy LR to PC if there isn't currently a rule for PC in force. */
if (state->cfi.ra_how == CFIR_UNKNOWN) {
if (state->cfi.r14_how == CFIR_UNKNOWN) {
state->cfi.ra_how = CFIR_EXPR;
state->cfi.ra_off = gen_CfiExpr_CfiReg_ARM_GPR(state->di, 14);
vg_assert(state->cfi.ra_off >= 0);
} else {
state->cfi.ra_how = state->cfi.r14_how;
state->cfi.ra_off = state->cfi.r14_off;
}
}
break;
case ARM_EXIDX_CMD_SUB_FROM_VSP:
state->vsp_off -= (Int)(edata->data);
break;
case ARM_EXIDX_CMD_ADD_TO_VSP:
state->vsp_off += (Int)(edata->data);
break;
case ARM_EXIDX_CMD_REG_POP: {
UInt i;
for (i = 0; i < 16; i++) {
if (edata->data & (1 << i)) {
// See if we're summarising for int register |i|. If so,
// describe how to pull it off the stack. The cast of |i| is
// a bit of a kludge but works because DW_REG_ARM_Rn has the
// value |n|, for 0 <= |n| <= 15 -- that is, for the ARM
// general-purpose registers.
UChar* rX_howP = NULL;
Int* rX_offP = NULL;
maybeFindExprForRegno(&rX_howP, &rX_offP, &state->cfi, i);
if (rX_howP) {
vg_assert(rX_offP);
/* rX_howP and rX_offP point at one of the rX fields
in |state->cfi|. Hence the following assignments
are really updating |state->cfi|. */
*rX_howP = CFIR_MEMCFAREL;
*rX_offP = state->vsp_off;
} else {
/* We're not tracking this register, so ignore it. */
vg_assert(!rX_offP);
}
state->vsp_off += 4;
}
}
/* Set cfa in case the SP got popped. */
if (edata->data & (1 << 13)) {
// vsp = curr_rules_.mR13expr;
//state->cfi.cfa_how =
//state->cfi.cfa_off =
//state->vsp_off = 0;
// If this happens, it would make the existing CFA references
// in the summary invalid. So give up instead.
goto cant_summarise;
}
break;
}
case ARM_EXIDX_CMD_REG_TO_SP: {
/* We're generating a new value for the CFA/VSP here. Hence,
if the summary already refers to the CFA at all, we can't
go any further, and have to abandon summarisation. */
if (mentionsCFA(&state->cfi))
goto cant_summarise;
vg_assert(edata->data < 16);
Int reg_no = edata->data;
// Same comment as above, re the casting of |reg_no|, applies.
UChar* rX_howP = NULL;
Int* rX_offP = NULL;
maybeFindExprForRegno(&rX_howP, &rX_offP, &state->cfi, reg_no);
if (rX_howP) {
vg_assert(rX_offP);
if (*rX_howP == CFIR_UNKNOWN) {
//curr_rules_.mR13expr = LExpr(LExpr::NODEREF, reg_no, 0);
Int expr_ix = gen_CfiExpr_CfiReg_ARM_GPR(state->di, reg_no);
if (expr_ix >= 0) {
state->cfi.r13_how = CFIR_EXPR;
state->cfi.r13_off = expr_ix;
} else {
goto cant_summarise;
}
} else {
//curr_rules_.mR13expr = *reg_exprP;
state->cfi.r13_how = *rX_howP;
state->cfi.r13_off = *rX_offP;
}
//vsp = curr_rules_.mR13expr;
Bool ok = setCFAfromCFIR( &state->cfi, state->di->cfsi_exprs,
state->cfi.r13_how, state->cfi.r13_off );
if (!ok) goto cant_summarise;
state->vsp_off = 0;
} else {
vg_assert(!rX_offP);
}
break;
}
case ARM_EXIDX_CMD_VFP_POP: {
/* Don't recover VFP registers, but be sure to adjust the stack
pointer. */
UInt i;
for (i = ARM_EXBUF_START(edata->data);
i <= ARM_EXBUF_END(edata->data); i++) {
state->vsp_off += 8;
}
if (!(edata->data & ARM_EXIDX_VFP_FSTMD)) {
state->vsp_off += 4;
}
break;
}
case ARM_EXIDX_CMD_WREG_POP: {
UInt i;
for (i = ARM_EXBUF_START(edata->data);
i <= ARM_EXBUF_END(edata->data); i++) {
state->vsp_off += 8;
}
break;
}
case ARM_EXIDX_CMD_WCGR_POP: {
UInt i;
// Pop wCGR registers under mask {wCGR3,2,1,0}, hence "i < 4"
for (i = 0; i < 4; i++) {
if (edata->data & (1 << i)) {
state->vsp_off += 4;
}
}
break;
}
case ARM_EXIDX_CMD_REFUSED:
case ARM_EXIDX_CMD_RESERVED:
ret = -1;
break;
}
return ret;
cant_summarise:
return -10;
}
/* Initialise the EXIDX summariser, by writing initial values in |state|. */
static
void AddStackFrame ( /*OUT*/SummState* state,
DebugInfo* di )
{
VG_(bzero_inline)(state, sizeof(*state));
state->vsp_off = 0;
state->di = di;
/* Initialise the DiCfSI_m that we are building. */
state->cfi.cfa_how = CFIC_ARM_R13REL;
state->cfi.cfa_off = 0;
state->cfi.ra_how = CFIR_UNKNOWN;
state->cfi.r14_how = CFIR_UNKNOWN;
state->cfi.r13_how = CFIR_UNKNOWN;
state->cfi.r12_how = CFIR_UNKNOWN;
state->cfi.r11_how = CFIR_UNKNOWN;
state->cfi.r7_how = CFIR_UNKNOWN;
}
static
void SubmitStackFrame( /*MOD*/DebugInfo* di,
SummState* state, Addr avma, SizeT len )
{
// JRS: I'm really not sure what this means, or if it is necessary
// return address always winds up in pc
//stack_frame_entry_->initial_rules[ustr__ZDra()] // ".ra"
// = stack_frame_entry_->initial_rules[ustr__pc()];
// maybe don't need to do anything here?
// the final value of vsp is the new value of sp.
switch (state->cfi.cfa_how) {
case CFIC_ARM_R13REL: case CFIC_ARM_R12REL:
case CFIC_ARM_R11REL: case CFIC_ARM_R7REL: break;
default: vg_assert(0);
}
state->cfi.r13_how = CFIR_CFAREL;
state->cfi.r13_off = state->vsp_off;
// Finally, add the completed RuleSet to the SecMap
if (len > 0) {
// Futz with the rules for r4 .. r11 in the same way as happens
// with the CFI summariser:
/* Mark callee-saved registers (r4 .. r11) as unchanged, if there is
no other information about them. FIXME: do this just once, at
the point where the ruleset is committed. */
if (state->cfi.r7_how == CFIR_UNKNOWN) {
state->cfi.r7_how = CFIR_SAME;
state->cfi.r7_off = 0;
}
if (state->cfi.r11_how == CFIR_UNKNOWN) {
state->cfi.r11_how = CFIR_SAME;
state->cfi.r11_off = 0;
}
if (state->cfi.r12_how == CFIR_UNKNOWN) {
state->cfi.r12_how = CFIR_SAME;
state->cfi.r12_off = 0;
}
if (state->cfi.r14_how == CFIR_UNKNOWN) {
state->cfi.r14_how = CFIR_SAME;
state->cfi.r14_off = 0;
}
// And add them
ML_(addDiCfSI)(di, avma, len, &state->cfi);
if (di->trace_cfi)
ML_(ppDiCfSI)(di->cfsi_exprs, avma, len, &state->cfi);
}
}
/*------------------------------------------------------------*/
/*--- Top level ---*/
/*------------------------------------------------------------*/
void ML_(read_exidx) ( /*MOD*/DebugInfo* di,
UChar* exidx_img, SizeT exidx_size,
UChar* extab_img, SizeT extab_size,
Addr text_last_svma,
PtrdiffT text_bias )
{
if (di->trace_cfi)
VG_(printf)("BEGIN ML_(read_exidx) exidx_img=[%p, +%lu) "
"extab_img=[%p, +%lu) text_last_svma=%lx text_bias=%lx\n",
exidx_img, exidx_size, extab_img, extab_size,
text_last_svma, (UWord)text_bias);
Bool ok;
MemoryRange mr_exidx, mr_extab;
ok = MemoryRange__init(&mr_exidx, exidx_img, exidx_size);
ok = ok && MemoryRange__init(&mr_extab, extab_img, extab_size);
if (!ok) {
complain(".exidx or .extab image area wraparound");
return;
}
const ExidxEntry* start_img = (const ExidxEntry*)exidx_img;
const ExidxEntry* end_img = (const ExidxEntry*)(exidx_img + exidx_size);
if (VG_(clo_verbosity) > 1)
VG_(message)(Vg_DebugMsg, " Reading EXIDX entries: %lu available\n",
exidx_size / sizeof(ExidxEntry) );
// Iterate over each of the EXIDX entries (pairs of 32-bit words).
// These occupy the entire .exidx section.
UWord n_attempted = 0, n_successful = 0;
const ExidxEntry* entry_img;
for (entry_img = start_img; entry_img < end_img; ++entry_img) {
n_attempted++;
// Figure out the code address range that this table entry_img is
// associated with.
Addr avma = (Addr)Prel31ToAddr(&entry_img->addr);
if (di->trace_cfi)
VG_(printf)("XXX1 entry: entry->addr 0x%x, avma 0x%lx\n",
entry_img->addr, avma);
Addr next_avma;
if (entry_img < end_img - 1) {
next_avma = (Addr)Prel31ToAddr(&(entry_img+1)->addr);
} else {
// This is the last EXIDX entry in the sequence, so we don't
// have an address for the start of the next function, to limit
// this one. Instead use the address of the last byte of the
// text section associated with this .exidx section, that we
// have been given. So as to avoid junking up the CFI unwind
// tables with absurdly large address ranges in the case where
// text_last_svma_ is wrong, only use the value if it is nonzero
// and within one page of |svma|. Otherwise assume a length of 1.
//
// In some cases, gcc has been observed to finish the exidx
// section with an entry of length 1 marked CANT_UNWIND,
// presumably exactly for the purpose of giving a definite
// length for the last real entry, without having to look at
// text segment boundaries.
Addr text_last_avma = text_last_svma + text_bias;
Bool plausible;
Addr maybe_next_avma = text_last_avma + 1;
if (maybe_next_avma > avma && maybe_next_avma - avma <= 4096) {
next_avma = maybe_next_avma;
plausible = True;
} else {
next_avma = avma + 1;
plausible = False;
}
if (!plausible && avma != text_last_avma + 1) {
HChar buf[100];
VG_(snprintf)(buf, sizeof(buf),
"Implausible EXIDX last entry size %lu"
"; using 1 instead.", text_last_avma - avma);
buf[sizeof(buf)-1] = 0;
complain(buf);
}
}
// Extract the unwind info into |buf|. This might fail for
// various reasons. It involves reading both the .exidx and
// .extab sections. All accesses to those sections are
// bounds-checked.
if (di->trace_cfi)
VG_(printf)("XXX1 entry is for AVMA 0x%lx 0x%lx\n",
avma, next_avma-1);
UChar buf[ARM_EXIDX_TABLE_LIMIT];
SizeT buf_used = 0;
ExExtractResult res
= ExtabEntryExtract(&mr_exidx, &mr_extab,
entry_img, buf, sizeof(buf), &buf_used);
if (res != ExSuccess) {
// Couldn't extract the unwind info, for some reason. Move on.
switch (res) {
case ExInBufOverflow:
complain("ExtabEntryExtract: .exidx/.extab section overrun");
break;
case ExOutBufOverflow:
complain("ExtabEntryExtract: bytecode buffer overflow");
break;
case ExCantUnwind:
// Some functions are marked CantUnwind by the compiler.
// Don't record these as attempted, since that's just
// confusing, and failure to summarise them is not the fault
// of this code.
n_attempted--;
if (0)
complain("ExtabEntryExtract: function is marked CANT_UNWIND");
break;
case ExCantRepresent:
complain("ExtabEntryExtract: bytecode can't be represented");
break;
case ExInvalid:
complain("ExtabEntryExtract: index table entry is invalid");
break;
default: {
HChar mbuf[100];
VG_(snprintf)(mbuf, sizeof(mbuf),
"ExtabEntryExtract: unknown error: %d", (Int)res);
buf[sizeof(mbuf)-1] = 0;
complain(mbuf);
break;
}
}
continue;
}
// Finally, work through the unwind instructions in |buf| and
// create CFI entries that Valgrind can use. This can also fail.
// First, initialise the summariser's running state, into which
// ExtabEntryDecode will write the CFI entries.
SummState state;
AddStackFrame( &state, di );
Int ret = ExtabEntryDecode( &state, buf, buf_used );
if (ret < 0) {
/* Failed summarisation. Ignore and move on. */
HChar mbuf[100];
VG_(snprintf)(mbuf, sizeof(mbuf),
"ExtabEntryDecode: failed with error code: %d", ret);
mbuf[sizeof(mbuf)-1] = 0;
complain(mbuf);
} else {
/* Successful summarisation. Add it to the collection. */
SubmitStackFrame( di, &state, avma, next_avma - avma );
n_successful++;
}
} /* iterating over .exidx */
if (VG_(clo_verbosity) > 1)
VG_(message)(Vg_DebugMsg,
" Reading EXIDX entries: %lu attempted, %lu successful\n",
n_attempted, n_successful);
}
#endif /* defined(VGA_arm) */
/*--------------------------------------------------------------------*/
/*--- end readexidx.c ---*/
/*--------------------------------------------------------------------*/
|
the_stack_data/909.c | /* Copyright (c) 2019-2021 Arm Limited
* SPDX-License-Identifier: Apache-2.0
*
* 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.
*/
/**
* Arm Compiler uses dedicated functions for each format specifier used by
* [sn/v/vsn]printf. When minimal-printf overwrites [sn/v/vsn]printf the
* linker is unable to remove unused functions related to printf.
*
* The following stubs replace the built-in functions and helps the linker
* to resolve dependencies and correctly remove unused functions.
*/
#ifdef MBED_MINIMAL_PRINTF
#if defined(TOOLCHAIN_ARM)
#include "mbed_printf_implementation.h"
#include <limits.h>
#include <stdio.h>
#include <stdarg.h>
/**
* Arm Compiler uses __2[s/sn/vsn]printf internally.
*/
int $Sub$$__2printf(const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
va_end(arguments);
return result;
}
int $Sub$$__2sprintf(char *buffer, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, NULL);
va_end(arguments);
return result;
}
int $Sub$$__2snprintf(char *buffer, size_t length, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
va_end(arguments);
return result;
}
int $Sub$$__2vprintf(const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stdout);
}
int $Sub$$__2vsprintf(char *buffer, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, LONG_MAX, format, arguments, NULL);
}
int $Sub$$__2vsnprintf(char *buffer, size_t length, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(buffer, length, format, arguments, NULL);
}
int $Sub$$__2fprintf(FILE *stream, const char *format, ...)
{
va_list arguments;
va_start(arguments, format);
int result = mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
va_end(arguments);
return result;
}
int $Sub$$__2vfprintf(FILE *stream, const char *format, va_list arguments)
{
return mbed_minimal_formatted_string(NULL, LONG_MAX, format, arguments, stream);
}
/**
* Replace the built-in functions which the linker is unable to prune with dummy stubs
* that take up less space.
*/
int $Sub$$_printf_a(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_c(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_char(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_char_common(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_char_file_locked(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_charcount(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_cs_common(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_d(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_dec(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_e(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_f(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_fp_dec(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_fp_dec_real(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_fp_hex(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_fp_hex_real(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_fp_infnan(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_g(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_hex_int_ll_ptr(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_hex_ptr(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_i(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_int_common(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_int_dec(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_int_hex(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_int_oct(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_l(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_lc(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_lcs_common(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_ll(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_ll_hex(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_ll_oct(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_lld(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_lli(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_llo(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_llu(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_llx(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_longlong_dec(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_longlong_hex(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_longlong_oct(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_ls(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_n(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_o(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_oct_int_ll(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_p(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_pad(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_percent(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_percent_end(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_s(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_str(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_string(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_truncate(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_truncate_signed(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_truncate_unsigned(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_u(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_wchar(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_wctomb(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_wstring(const char *format, ...)
{
return 0;
}
int $Sub$$_printf_x(const char *format, ...)
{
return 0;
}
#endif
#endif // MBED_MINIMAL_PRINTF
|
the_stack_data/111404.c | #define _GNU_SOURCE
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <dlfcn.h>
#include <string.h>
#include <sys/stat.h>
typedef struct _MonoImage MonoImage;
typedef struct _MonoAssembly MonoAssembly;
typedef struct _MonoMethod MonoMethod;
typedef struct _MonoObject MonoObject;
typedef struct _MonoClass MonoClass;
typedef struct _MonoDomain MonoDomain;
typedef struct _MonoArray MonoArray;
typedef int32_t mono_bool;
typedef enum {
MONO_IMAGE_OK,
MONO_IMAGE_ERROR_ERRNO,
MONO_IMAGE_MISSING_ASSEMBLYREF,
MONO_IMAGE_IMAGE_INVALID
} MonoImageOpenStatus;
typedef MonoImage *(*mono_image_open_from_data_with_name_t)(char *, int, int, MonoImageOpenStatus*, int, const char *);
typedef void(*mono_image_close_t)(MonoImage *image);
typedef MonoAssembly* (*mono_assembly_load_from_full_t)(MonoImage *image, const char *fname,
MonoImageOpenStatus *status, mono_bool refonly);
typedef MonoClass* (*mono_class_from_name_t)(MonoImage *image, const char* name_space, const char *name);
typedef MonoMethod* (*mono_class_get_method_from_name_t)(MonoClass *klass, const char *name, int param_count);
typedef MonoObject* (*mono_runtime_invoke_t)(MonoMethod *method, MonoObject *obj, void **params, MonoObject **exc);
typedef MonoClass* (*mono_get_byte_class_t)();
typedef MonoDomain* (*mono_domain_get_t)();
typedef char* (*mono_array_addr_with_size_t)(MonoArray *array, int size, uintptr_t idx);
typedef MonoArray *(*mono_array_new_t)(MonoDomain *domain, MonoClass *eclass, uintptr_t n);
typedef char *(*mono_class_get_name_t)(MonoClass *);
typedef char *(*mono_class_get_namespace_t)(MonoClass *);
typedef char *(*mono_method_get_name_t)(MonoMethod *);
typedef MonoClass *(*mono_method_get_class_t)(MonoMethod *);
static mono_image_close_t org_mono_image_close;
static mono_assembly_load_from_full_t org_mono_assembly_load_from_full;
static mono_class_from_name_t org_mono_class_from_name;
static mono_class_get_method_from_name_t org_mono_class_get_method_from_name;
static mono_get_byte_class_t org_mono_get_byte_class;
static mono_domain_get_t org_mono_domain_get;
static mono_array_addr_with_size_t org_mono_array_addr_with_size;
static mono_array_new_t org_mono_array_new;
static mono_class_get_name_t org_mono_class_get_name;
static mono_class_get_namespace_t org_mono_class_get_namespace;
static mono_method_get_name_t org_mono_method_get_name;
static mono_method_get_class_t org_mono_method_get_class;
static mono_image_open_from_data_with_name_t org_mono_image_open_from_data_with_name;
static mono_runtime_invoke_t org_mono_runtime_invoke;
static MonoImage *gamemod_img = NULL;
void print(const char *msg) {
if (!msg)
msg = "(null)";
if (write(1, msg, strlen(msg)))
;
}
static int load_image(const char *filename, MonoImage **pimage, MonoAssembly **passem) {
MonoImage *image = NULL;
MonoAssembly *assem = NULL;
int fd;
char *data = NULL;
int size;
struct stat st;
if ((fd = open(filename, O_RDONLY)) == -1) {
print("olmod load_image: cannot open ");
print(filename);
print("\n");
goto err;
}
if (fstat(fd, &st) == -1) {
print("cannot size\n");
goto err;
}
size = st.st_size;
if (!(data = (char *)malloc(size))) {
print("cannot alloc\n");
goto err;
}
if (read(fd, data, size) != size) {
print("cannot read\n");
goto err;
}
close(fd);
fd = -1;
MonoImageOpenStatus status;
if (!(image = org_mono_image_open_from_data_with_name(data, size, 1, &status, 0, filename)) ||
status != MONO_IMAGE_OK) {
print("cannot open image\n");
goto err;
}
if (!(assem = org_mono_assembly_load_from_full(image, filename, &status, 0)) || status != MONO_IMAGE_OK) {
print("cannot load assem\n");
goto err;
}
if (pimage)
*pimage = image;
if (passem)
*passem = assem;
return 0;
err:
if (image)
org_mono_image_close(image);
if (data)
free(data);
if (fd != -1)
close(fd);
return -1;
}
static int run_void_method(MonoImage *image,
const char *name_space, const char *cls_name, const char *method_name) {
MonoClass *cls;
if (!(cls = org_mono_class_from_name(image, name_space, cls_name))) {
print("cannot find class\n");
return -1;
}
MonoMethod* method;
if (!(method = org_mono_class_get_method_from_name(cls, method_name, 0))) {
print("cannot find method ");
print(method_name);
print("\n");
return -1;
}
//MonoObject *result;
MonoObject *exc;
org_mono_runtime_invoke(method, NULL, NULL, &exc);
if (exc) {
print("olmod: invoke exception caught\n");
void (*org_mono_print_unhandled_exception)(MonoObject*) =
dlsym(dlopen("./Overload_Data/Mono/x86_64/libmono.so",1), "mono_print_unhandled_exception");
if (org_mono_print_unhandled_exception)
org_mono_print_unhandled_exception(exc);
else
print("olmod: exception print failed\n");
return -1;
}
//print("invoke done\n");
return 0;
}
static MonoObject* my_mono_runtime_invoke(MonoMethod *method, MonoObject *obj, void **params, MonoObject **exc) {
if (gamemod_img) {
run_void_method(gamemod_img, "GameMod.Core", "GameMod", "Initialize");
gamemod_img = NULL;
}
return org_mono_runtime_invoke(method, obj, params, exc);
}
// strlcat: Russ Allbery <[email protected]>, PD
#undef strlcat
#define strlcat my_strlcat
static size_t strlcat(char *dst, const char *src, size_t size)
{
size_t used, length, copy;
used = strlen(dst);
length = strlen(src);
if (size > 0 && used < size - 1) {
copy = (length >= size - used) ? size - used - 1 : length;
memcpy(dst + used, src, copy);
dst[used + copy] = '\0';
}
return used + length;
}
static void *my_mono_image_open_from_data_with_name(char *data, int data_len, int copy,
MonoImageOpenStatus *st, int ref, const char*name)
{
int name_len;
if (name && (name_len = strlen(name)) > 19 && strcmp(name + name_len - 19, "Assembly-CSharp.dll") == 0) {
/*
load_image_data(&_binary_0Harmony_dll_start, &_binary_0Harmony_dll_end - &_binary_0Harmony_dll_start,
"0Harmony.dll");
gamemod_img = load_image_data(&_binary_GameMod_dll_start, &_binary_GameMod_dll_end - &_binary_GameMod_dll_start,
"GameMod.dll");
*/
MonoImage *harmony_img;
char buf[256];
char* ret = getenv("OLMODDIR");
if (ret) {
strncpy(buf, ret, sizeof(buf) - 1);
} else {
print("OLMODDIR environment variable missing");
abort();
}
//int len = GetModuleFileNameA(NULL, buf, sizeof(buf));
//while (len && buf[len - 1] != '\\')
// len--;
//buf[len] = 0;
int len = strlen(buf);
strlcat(buf, "/0Harmony.dll", sizeof(buf));
load_image(buf, &harmony_img, NULL);
buf[len] = 0;
strlcat(buf, "/GameMod.dll", sizeof(buf));
load_image(buf, &gamemod_img, NULL);
}
return org_mono_image_open_from_data_with_name(data, data_len, copy, st, ref, name);
}
#ifdef __APPLE__
#define org_dlsym dlsym
#else
#define new_dlsym dlsym
typedef void *(*DLSYM_PROC_T)(void*, const char*);
DLSYM_PROC_T org_dlsym;
#endif
// separate function needed on mac to prevent stub_helper in dlsym which prevents opengl driver loading (???)
__attribute__((noinline))
static void *mono_dlsym(void *lib, const char *sym) {
void *ret = org_dlsym(lib, sym);
if (strcmp(sym, "mono_image_close") == 0)
org_mono_image_close = (mono_image_close_t)ret;
if (strcmp(sym, "mono_runtime_invoke") == 0) {
org_mono_runtime_invoke = (mono_runtime_invoke_t)ret;
return my_mono_runtime_invoke;
}
if (strcmp(sym, "mono_assembly_load_from_full") == 0)
org_mono_assembly_load_from_full = (mono_assembly_load_from_full_t)ret;
if (strcmp(sym, "mono_class_from_name") == 0)
org_mono_class_from_name = (mono_class_from_name_t)ret;
if (strcmp(sym, "mono_class_get_method_from_name") == 0)
org_mono_class_get_method_from_name = (mono_class_get_method_from_name_t)ret;
if (strcmp(sym, "mono_get_byte_class") == 0)
org_mono_get_byte_class = (mono_get_byte_class_t)ret;
if (strcmp(sym, "mono_domain_get") == 0)
org_mono_domain_get = (mono_domain_get_t)ret;
if (strcmp(sym, "mono_array_addr_with_size") == 0)
org_mono_array_addr_with_size = (mono_array_addr_with_size_t)ret;
if (strcmp(sym, "mono_array_new") == 0)
org_mono_array_new = (mono_array_new_t)ret;
if (strcmp(sym, "mono_method_get_class") == 0)
org_mono_method_get_class = (mono_method_get_class_t)ret;
if (strcmp(sym, "mono_class_get_name") == 0)
org_mono_class_get_name = (mono_class_get_name_t)ret;
if (strcmp(sym, "mono_class_get_namespace") == 0)
org_mono_class_get_namespace = (mono_class_get_namespace_t)ret;
if (strcmp(sym, "mono_method_get_name") == 0)
org_mono_method_get_name = (mono_method_get_name_t)ret;
if (strcmp(sym, "mono_image_open_from_data_with_name") == 0) {
org_mono_image_open_from_data_with_name = ret;
return my_mono_image_open_from_data_with_name;
}
return ret;
}
void *new_dlsym(void *lib, const char *sym) {
if (sym[0] != 'm' || sym[1] != 'o' || sym[2] != 'n' || sym[3] != 'o')
return org_dlsym(lib, sym);
return mono_dlsym(lib, sym);
}
//static void olmod_init(void) __attribute__((constructor));
#ifdef __APPLE__
struct interpose { /* the struct/typenames are arbitrary */
void* new;
void* old;
};
typedef struct interpose interpose_t;
__attribute__((used)) static const struct { void *a, *b; } interpose_dlsym[]
__attribute__((section("__DATA, __interpose"))) =
{
{ (void*) new_dlsym, (void*) dlsym}
};
#else
__attribute__((constructor)) static void olmod_init(void)
{
// We need to get the address of "dlsym", but we can't call
// dlsym to query it as we define that symbol by ourselves to
// hook it. The previous method was to use the internal function
// _dl_sym which was exported by glibc prior to 2.34, but now
// is hidden.
//
// As a workaround, we can use dlvsym, but that requires us to
// know the exact version of the symbol to query. Fortunately,
// this is defined in the glibc ABI, so it won't change even in
// future glibc versions. Unfortunately, it varies by architecture.
// These macros might be GCC-specific...
#if defined(__x86_64__)
#define DLSYM_ABI_VERSION "2.2.5"
#elif defined (__i386__)
#define DLSYM_ABI_VERSION "2.0"
#else
#error NOT SUPPORTED FOR THIS ARCHITECTURE
#endif
if (!(org_dlsym = (DLSYM_PROC_T)dlvsym(RTLD_NEXT, "dlsym", "GLIBC_" DLSYM_ABI_VERSION))) {
print("olmod failed dlsym lookup\n");
abort();
} else {
// Use the versioned one to look up the unversioned version, as this might be a different one.
DLSYM_PROC_T ptr = (DLSYM_PROC_T)org_dlsym(RTLD_NEXT, "dlsym");
if (ptr && (ptr != org_dlsym)) {
org_dlsym = ptr;
}
}
}
#endif
|
the_stack_data/136342.c | /*
* cat
*
* Concatenates files together to standard output.
* In a supporting terminal, you can then pipe
* standard out to another file or other useful
* things like that.
*/
#include <stdio.h>
#define CHUNK_SIZE 4096
int main(int argc, char ** argv) {
int ret = 0;
for (int i = 1; i < argc; ++i) {
FILE * fd;
if (argc > 1) {
fd = fopen(argv[i], "r");
if (!fd) {
fprintf(stderr, "%s: %s: no such file or directory\n", argv[0], argv[1]);
ret = 1;
continue;
}
}
size_t length;
fseek(fd, 0, SEEK_END);
length = ftell(fd);
fseek(fd, 0, SEEK_SET);
char buf[CHUNK_SIZE];
while (length > CHUNK_SIZE) {
fread( buf, 1, CHUNK_SIZE, fd);
fwrite(buf, 1, CHUNK_SIZE, stdout);
fflush(stdout);
length -= CHUNK_SIZE;
}
if (length > 0) {
fread( buf, 1, length, fd);
fwrite(buf, 1, length, stdout);
fflush(stdout);
}
fclose(fd);
}
return ret;
}
/*
* vim:tabstop=4
* vim:noexpandtab
* vim:shiftwidth=4
*/
|
the_stack_data/376110.c | int main()
{
printf(3);
printf("BAR");
return 0;
}
|
the_stack_data/103265460.c | #include <curses.h> //#include<conio.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
int choice = 0, MobileNumber = 0, Ammount = 0;
while (1) {
printf("\t\tWelcome To Airtel Mobile Money\n");
printf("\t\t1. Send Money\n");
printf("\t\t2. Airtime/Bundles\n");
printf("\t\t3. Withdraw cash\n");
printf("\t\t4. Pay Bills\n");
printf("\t\t5. Payements\n");
printf("\t\t6. School fees\n");
printf("\t\t7. Financial Services\n");
printf("\t\t8. Wewole\n");
printf("\t\t9. Airtel Money Pay\n");
printf("\t\t10. My Account\n");
printf("\t\t11. Exit\n");
printf("\t\tEnter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
while (2) {
// system("clear"); //clears screen
printf("\n\t\tsend Money\n");
printf("\t\t1. Airtel and Other Number\n");
printf("\t\t2. MTN Number\n");
printf("\t\t3. UTL Number\n");
printf("\t\t4. International Transfer\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
// system("clear");
printf("\n\t\tEnter Airtel Mobile Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou Have successfuly sent %d shs to %d\n\n\n ", Ammount,
MobileNumber);
// system("PAUSE");
break;
case 2:
// system("clear");
printf("\n\t\tEnter MTN Mobile Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou Have successfuly sent %d shs to %d\n\n\n ", Ammount,
MobileNumber);
break;
case 3:
// system("clear");
printf("\t\tEnter UTL Mobile Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou Have successfuly sent %d shs to %d\n\n\n ", Ammount,
MobileNumber);
break;
case 4:
while (3) {
printf("\n\t\t1. Rwanda\n");
printf("\t\t2. Zambia\n");
printf("\t\t3. Tanzania\n");
printf("\t\t4. Malawi\n");
printf("\t\t5. Burundi\n");
printf("\t\t6. Zimbabwe\n");
printf("\t\t7. Exit\n");
printf("\t\tEnter choice :");
scanf("%d", &choice);
switch (choice) {
case 1:
while (4) {
printf("\t\t1. Airtel\n");
printf("\t\t2. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\t\tEnter Rwanda Airtel Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou have successfuly sent %d Rwanda francs to "
"%d\n\n",
Ammount, MobileNumber);
break;
case 2:
exit(0);
break;
default:
printf("\t\tInavalid choice! Please try again!\n\n");
break;
}
}
break;
case 2:
while (5) {
printf("\t\t1. Airtel\n");
printf("\t\t2. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\t\tEnter Zambia Airtel Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf(
"\t\tYou have successfuly sent %d Zambia shs to %d\n\n",
Ammount, MobileNumber);
break;
case 2:
exit(0);
break;
default:
printf("\t\tInavalid choice! Please try again!\n\n");
break;
}
break;
case 3:
while (6) {
printf("\t\t1. Airtel\n");
printf("\t\t2. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\t\tEnter Tanzania Airtel Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou have successfuly sent %d Tanzania shs to "
"%d\n\n",
Ammount, MobileNumber);
break;
case 2:
exit(0);
break;
default:
printf("\t\tInavalid choice! Please try again!\n\n");
break;
}
}
break;
case 4:
while (7) {
printf("\t\t1. Airtel\n");
printf("\t\t2. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\n\t\tEnter Malawi Airtel Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf(
"\t\tYou have successfuly sent %d Malawi shs to %d\n\n",
Ammount, MobileNumber);
break;
case 2:
exit(0);
break;
default:
printf("\t\tInavalid choice! Please try again!\n\n");
break;
}
}
break;
case 5:
while (8) {
printf("\t\t1. Airtel\n");
printf("\t\t2. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\t\tEnter Burundi Airtel Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou have successfuly sent %d Burundi francs to "
"%d\n\n",
Ammount, MobileNumber);
break;
case 2:
exit(0);
break;
default:
printf("\t\tInavalid choice! Please try again!\n\n");
break;
}
}
break;
case 6:
while (9) {
printf("\t\t1. Airtel\n");
printf("\t\t2. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\t\tEnter Zimbabwe Airtel Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou have successfuly sent %d Zimbabwe Dollars "
"to %d\n\n",
Ammount, MobileNumber);
break;
case 2:
exit(0);
break;
default:
printf("\t\tInavalid choice! Please try again!\n\n");
break;
}
}
break;
case 7:
exit(0);
// goto :
// while(1);
break;
default:
printf("\t\tInavalid choice!, please try again!!\n\n");
break;
}
}
default:
printf("\n\t\tInvalid choice, please try again!\n\n\n");
break;
}
}
break;
case 2:
printf("\n\t\tAirtime/Bundles\n\n");
while (10) {
printf("\t\t1. Buy Airtime\n");
printf("\t\t2. Buy Data Bundles\n");
printf("\t\t3. Buy Voice Bundles\n");
printf("\t\t4. IControl\n");
printf("\t\t5. OTT Service Tax\n");
printf("\t\t6. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\n\t\tBuy Airtime\n\n");
printf("\t\t1. For MySelt\n");
printf("\t\t2. For Another Number\n");
printf("\t\t3. Exit\n");
printf("\t\tEnter choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou have successfuly topped up %d shs on your "
"Number\n\n",
Ammount);
break;
case 2:
printf("\t\tEnter other Number: ");
scanf("%d", &MobileNumber);
printf("\t\tEnter Ammount: ");
scanf("%d", &Ammount);
printf("\t\tYou have successfuly topped up %d shs for %d\n\n",
Ammount, MobileNumber);
break;
default:
printf("\t\tInvalid choice Input! Please Try again!!\n\n");
break;
}
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
exit(0);
break;
break;
default:
printf("\t\tInvalid choice Input! Please Try again!!\n\n");
break;
}
}
break;
case 3:
printf("You selected Withdraw cash\n");
break;
case 4:
printf("You selected Pay Bills\n");
break;
case 5:
printf("You selected Payements\n");
break;
case 6:
printf("You selected School fees\n");
break;
case 7:
printf("You selected Financial Services\n");
break;
case 8:
printf("You selected Wewole\n");
break;
case 9:
printf("You selected Airtel Money Pay\n");
break;
case 10:
printf("You selected My Account\n");
break;
case 11:
printf("Thank you for using Airtel Money!\n");
printf("Bye!!");
exit(0);
}
}
return 0;
}
}
|
the_stack_data/20449905.c | #include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int fd;
// FIFO file path
char * myfifo = "/tmp/myfifo";
// Creating the named file(FIFO)
// mkfifo(<pathname>, <permission>)
mkfifo(myfifo, 0666);
char name[50];
printf("Insira seu nome para iniciar uma conversa: \n");
scanf("%s", name);
getchar();
char arr1[80], arr2[80];
while (1)
{
char final_message[130] = "";
// Open FIFO for write only
printf("Você: ");
fd = open(myfifo, O_WRONLY);
// Take an input arr2ing from user.
// 80 is maximum length
fgets(arr2, 80, stdin);
strcat(final_message, name);
strcat(final_message, ": ");
strcat(final_message, arr2);
// Write the input arr2ing on FIFO
// and close it
write(fd, final_message, strlen(final_message)+1);
close(fd);
// Open FIFO for Read only
fd = open(myfifo, O_RDONLY);
// Read from FIFO
read(fd, arr1, sizeof(arr1));
// Print the read message
printf("%s", arr1);
close(fd);
}
return 0;
}
|
the_stack_data/28263687.c | /*P12.20 Program to merge two files*/
#include<stdio.h>
#include<stdlib.h>
struct record
{
char name[20];
int roll;
int marks;
}stu1, stu2;
int main(void)
{
FILE *fp1,*fp2,*fp3;
int i,j;
if((fp1=fopen("sectionA","rb")) == NULL)
{
printf("Error in opening file\n");
exit(1);
}
if((fp2=fopen("sectionB","rb"))==NULL)
{
printf("Error in opening file\n");
exit(1);
}
if((fp3=fopen("merged","wb"))==NULL)
{
printf("Error in opening file\n");
exit(1);
}
i=fread(&stu1,sizeof(stu1),1,fp1);
j=fread(&stu2,sizeof(stu2),1,fp2);
while((i==1)&&(j==1))
{
if(stu1.marks > stu2.marks)
{
fwrite(&stu1,sizeof(stu1),1,fp3);
i = fread(&stu1,sizeof(stu1),1,fp1);
}
else
{
fwrite(&stu2,sizeof(stu2),1,fp3);
j = fread(&stu2,sizeof(stu2),1,fp2);
}
}
while(i==1) /*Write remaining records of sectionA into merged*/
{
fwrite(&stu1,sizeof(stu1),1,fp3);
i = fread(&stu1,sizeof(stu1),1,fp1);
}
while(j==1) /*Write remaining records of sectionB into merged*/
{
fwrite(&stu1,sizeof(stu1),1,fp3);
j = fread(&stu2,sizeof(stu2),1,fp2);
}
fclose(fp1);
fclose(fp2);
fclose(fp3);
return 0;
}
|
the_stack_data/14200553.c | /* This is based on https://gist.github.com/hi2p-perim/7855506 */
#include <stdio.h>
#if defined (_MSC_VER) || defined (__MINGW64__)
# include <intrin.h>
#else
void __cpuid(int *cpuinfo, int info) {
__asm__ __volatile__(
"xchg %%ebx, %%edi;"
"cpuid;"
"xchg %%ebx, %%edi;"
:"=a" (cpuinfo[0]), "=D" (cpuinfo[1]), "=c" (cpuinfo[2]), "=d" (cpuinfo[3])
:"0" (info)
);
}
#endif
int main(int argc, char *argv[]) {
int cpuinfo[4];
__cpuid(cpuinfo, 1);
printf("%d\n", cpuinfo[2] & (1 << 19) ? 1 : 0); /* SSE 4.1 */
return 0;
}
|
the_stack_data/396456.c | #include <stdio.h>
int main(int argc, char *argv[])
{
int index = atoi(argv[1]);
char *str = argv[index];
return 0;
}
|
the_stack_data/1121959.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chang-le <[email protected].> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/07/16 13:17:02 by chang-le #+# #+# */
/* Updated: 2020/07/16 17:07:12 by chang-le ### ########.fr */
/* */
/* ************************************************************************** */
void ft_print_comb(void);
int main(void)
{
ft_print_comb();
return (0);
}
|
the_stack_data/151916.c | #ifdef _MSC_VER
#include <float.h>
#endif
extern float _myexpf(float x);
extern float _mylogf(float x);
extern float _mylog10f(float x);
extern float _mypowf(float x, float y);
extern double _mysin(double x);
extern double _mycos(double y);
#if defined(_MSC_VER) && defined(_M_IX86)
#define fpu_save() _control87(0, 0)
#define fpu_set_single() _control87(_PC_24, _MCW_PC)
#define fpu_set_double() _control87(_PC_53, _MCW_PC)
#define fpu_restore(x) _control87((x), _MCW_PC)
#else
#define fpu_save() 0
#define fpu_set_single() (void)0
#define fpu_set_double() (void)0
#define fpu_restore(x) (void)x
#endif /* _MSC_VER */
float myexpf(float x)
{
unsigned state = fpu_save();
float y;
fpu_set_single();
y = _myexpf(x);
fpu_restore(state);
return y;
}
float mylogf(float x)
{
unsigned state = fpu_save();
float y;
fpu_set_single();
y = _mylogf(x);
fpu_restore(state);
return y;
}
float mylog10f(float x)
{
unsigned state = fpu_save();
float y;
fpu_set_single();
y = _mylog10f(x);
fpu_restore(state);
return y;
}
float mypowf(float x, float y)
{
unsigned state = fpu_save();
float z;
fpu_set_single();
z = _mypowf(x, y);
fpu_restore(state);
return z;
}
double mysin(double x)
{
unsigned state = fpu_save();
double y;
fpu_set_double();
y = _mysin(x);
fpu_restore(state);
return y;
}
double mycos(double x)
{
unsigned state = fpu_save();
double y;
fpu_set_double();
y = _mycos(x);
fpu_restore(state);
return y;
}
|
the_stack_data/18887860.c | /* The Computer Language Benchmarks Game
* http://benchmarksgame.alioth.debian.org/
contributed by Greg Buchholz
for the debian (AMD) machine...
compile flags: -O3 -ffast-math -march=athlon-xp -funroll-loops
for the gp4 (Intel) machine...
compile flags: -O3 -ffast-math -march=pentium4 -funroll-loops
*/
/*
* COMMAND LINE DEFINES
*
* -DSTATIC
* Use statics instead of locals.
*
* -DPRINTF
* Enable printing of results.
*
* -DTIMER
* Insert asm labels into source code at timing points (Z88DK).
*
* -DCOMMAND
* Enable reading of N from the command line.
*
*/
#ifdef STATIC
#undef STATIC
#define STATIC static
#else
#define STATIC
#endif
#ifdef PRINTF
#define PRINTF3(a,b,c) printf(a,b,c)
#define PUTC(a,b) putc(a,b)
#else
#define PRINTF3(a,b,c)
#define PUTC(a,b) (*output++ = a)
#endif
#ifdef TIMER
#define TIMER_START() __asm__("TIMER_START:")
#define TIMER_STOP() __asm__("TIMER_STOP:")
#else
#define TIMER_START()
#define TIMER_STOP()
#endif
#ifdef __Z88DK
#include <intrinsic.h>
#ifdef PRINTF
// enable printf %d
#pragma output CLIB_OPT_PRINTF = 0x01
#endif
#endif
#include<stdio.h>
unsigned char *output = (unsigned char *)0xc000;
int main (int argc, char **argv)
{
STATIC int w, h, bit_num;
STATIC unsigned char byte_acc;
STATIC int i;
STATIC int iter = 50;
STATIC double x, y;
STATIC double Zr, Zi, Cr, Ci, Tr, Ti;
STATIC double limit = 2.0;
#ifdef COMMAND
w = argc > 1 ? atoi(argv[1]) : 60;
h = argc > 2 ? atoi(argv[2]) : w;
#else
w = h = 60;
#endif
PRINTF3("P4\n%d %d\n",w,h);
TIMER_START();
for(y=0;y<h;++y)
{
for(x=0;x<w;++x)
{
Zr = Zi = Tr = Ti = 0.0;
Cr = (2.0*x/w - 1.5); Ci=(2.0*y/h - 1.0);
for (i=0;i<iter && (Tr+Ti <= limit*limit);++i)
{
Zi = 2.0*Zr*Zi + Ci;
Zr = Tr - Ti + Cr;
Tr = Zr * Zr;
Ti = Zi * Zi;
}
byte_acc <<= 1;
if(Tr+Ti <= limit*limit) byte_acc |= 0x01;
++bit_num;
if(bit_num == 8)
{
PUTC(byte_acc,stdout);
byte_acc = 0;
bit_num = 0;
}
else if(x == w-1)
{
byte_acc <<= (8-w%8);
PUTC(byte_acc,stdout);
byte_acc = 0;
bit_num = 0;
}
}
}
TIMER_STOP();
}
|
the_stack_data/139354.c | /*
* This file is Copyright (c)2010 by the GPSD project
* BSD terms apply: see the file COPYING in the distribution root for details.
*/
#include <sys/types.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <limits.h>
/*
* @@Cj - receiver ID
* @@Be 0 - almanac dump
*/
static int moto_send(int , char *, char *);
static char moto_gen_checksum(char *, int);
char *gpsd_hexdump(char *, size_t);
int gpsd_hexpack(char *, char *, int);
int hex2bin(char *s);
#define BSIZ 64
int main(int argc, char **argv) {
int speed, l, fd, n;
struct termios term;
char buf[BSIZ];
time_t s, t;
if (argc != 5){
fprintf(stderr, "usage: motosend <speed> <port> msgtype moto-body-hex\n");
return 1;
}
if ((l = strlen(argv[4])) > 2*USHRT_MAX){
fprintf(stderr, "oversized message\n");
return 1;
}
if (l % 2) {
fprintf(stderr, "body must have an even number of hex digits\n");
return 1;
}
speed = atoi(argv[1]);
switch (speed) {
case 230400:
case 115200:
case 57600:
case 38400:
case 28800:
case 14400:
case 9600:
case 4800:
break;
default:
fprintf(stderr, "invalid speed\n");
return 1;
}
if ((fd = open(argv[2], O_RDWR | O_NONBLOCK | O_NOCTTY, 0644)) == -1)
err(1, "open");
tcgetattr(fd, &term);
cfmakeraw(&term);
cfsetospeed(&term, speed);
cfsetispeed(&term, speed);
term.c_cc[VMIN] = 8;
term.c_cc[VTIME] = 1;
term.c_cflag &= ~(PARENB | PARODD | CRTSCTS);
term.c_cflag |= CREAD | CLOCAL;
term.c_iflag = term.c_oflag = term.c_lflag = (tcflag_t) 0;
if (tcsetattr(fd, TCSANOW | TCSAFLUSH, &term) == -1)
err(1, "tcsetattr");
tcflush(fd, TCIOFLUSH);
t = 0; n = 0;
while (1){
usleep(1000);
bzero(buf, BSIZ);
if ((l = read(fd, buf, BSIZ)) == -1)
if (!(EINTR == errno || EAGAIN == errno))
err(1, "read");
if (l > 0){
printf("%s", gpsd_hexdump(buf, l));
fflush(stdout);
}
/* allow for up to "n" resends, once per second */
if (((s = time(NULL)) > t) && (n < 1)){
t = s;
n++;
moto_send(fd, argv[3], argv[4]);
}
}
return 0;
}
char moto_gen_checksum(char *buf, int len){
int n;
char ck = '\0';
for (n = 0; n < len; n++)
ck ^= buf[n];
return ck;
}
static int moto_send(int fd, char *type, char *body ) {
size_t status;
char *buf;
unsigned short l;
l = strlen(body) / 2;
if ((buf = malloc(l+7)) == NULL)
return -1;
bzero(buf, l+7);
buf[0] = '@'; buf[1] = '@';
buf[2] = type[0]; buf[3] = type[1];
if (l)
if (gpsd_hexpack(body, buf+4, l) == -1){
free(buf);
return -1;
}
buf[l+4] = moto_gen_checksum(buf+2, l+2);
buf[l+5] = '\r'; buf[l+6] = '\n';
status = write(fd, buf, l+7);
if (status == -1)
perror("moto_send");
return (int)status;
}
static char last;
char *gpsd_hexdump(char *binbuf, size_t binbuflen)
{
static char hexbuf[USHRT_MAX*2+10+2];
size_t i, j = 0;
size_t len = (size_t)binbuflen;
const char *ibuf = (const char *)binbuf;
const char *hexchar = "0123456789abcdef";
for (i = 0; i < len; i++) {
if (ibuf[i] == '@' && (ibuf[i+1] == '@' || last == '@')){
hexbuf[j++] = '\n';
hexbuf[j++] = ibuf[i++];
hexbuf[j++] = ibuf[i++];
hexbuf[j++] = ibuf[i++];
hexbuf[j++] = ibuf[i++];
} else {
hexbuf[j++] = hexchar[ (ibuf[i]&0xf0)>>4 ];
hexbuf[j++] = hexchar[ ibuf[i]&0x0f ];
}
last = ibuf[i];
}
hexbuf[j] ='\0';
return hexbuf;
}
int gpsd_hexpack(char *src, char *dst, int len){
int i, k, l;
l = (int)(strlen(src) / 2);
if ((l < 1) || (l > len))
return -1;
bzero(dst, len);
for (i = 0; i < l; i++)
if ((k = hex2bin(src+i*2)) != -1)
dst[i] = (char)(k & 0xff);
else
return -1;
return l;
}
int hex2bin(char *s)
{
int a, b;
a = s[0] & 0xff;
b = s[1] & 0xff;
if ((a >= 'a') && (a <= 'f'))
a = a + 10 - 'a';
else if ((a >= 'A') && (a <= 'F'))
a = a + 10 - 'A';
else if ((a >= '0') && (a <= '9'))
a -= '0';
else
return -1;
if ((b >= 'a') && (b <= 'f'))
b = b + 10 - 'a';
else if ((b >= 'A') && (b <= 'F'))
b = b + 10 - 'A';
else if ((b >= '0') && (b <= '9'))
b -= '0';
else
return -1;
return ((a<<4) + b);
}
|
the_stack_data/234517247.c | /* { dg-do run } */
/* { dg-options "-O2 -fno-inline -fno-tree-ch -ftree-loop-linear" } */
extern void abort ();
int
test (int n, int *a)
{
int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
a[j] = i + n;
if (a[0] != 31 || i + n - 1 != 31)
abort ();
return 0;
}
int main (void)
{
int a[16];
test (16, a);
return 0;
}
|
the_stack_data/145452335.c | // Warning: This is a generated file, do not edit it!
#include <stdint.h>
#include <stddef.h>
const char temp_logo_png[] = {
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d,
0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00, 0x50,
0x08, 0x06, 0x00, 0x00, 0x00, 0x8e, 0x11, 0xf2, 0xad, 0x00, 0x00, 0x01,
0x84, 0x69, 0x43, 0x43, 0x50, 0x49, 0x43, 0x43, 0x20, 0x70, 0x72, 0x6f,
0x66, 0x69, 0x6c, 0x65, 0x00, 0x00, 0x28, 0x91, 0x7d, 0x91, 0x3d, 0x48,
0xc3, 0x40, 0x1c, 0xc5, 0x5f, 0x53, 0xa5, 0x52, 0x2a, 0x16, 0xec, 0x20,
0xe2, 0x90, 0xa1, 0x3a, 0x59, 0x10, 0x15, 0x71, 0xd4, 0x2a, 0x14, 0xa1,
0x42, 0xa8, 0x15, 0x5a, 0x75, 0x30, 0xb9, 0xf4, 0x0b, 0x9a, 0x18, 0x92,
0x14, 0x17, 0x47, 0xc1, 0xb5, 0xe0, 0xe0, 0xc7, 0x62, 0xd5, 0xc1, 0xc5,
0x59, 0x57, 0x07, 0x57, 0x41, 0x10, 0xfc, 0x00, 0x71, 0x74, 0x72, 0x52,
0x74, 0x91, 0x12, 0xff, 0x97, 0x14, 0x5a, 0xc4, 0x78, 0x70, 0xdc, 0x8f,
0x77, 0xf7, 0x1e, 0x77, 0xef, 0x00, 0xa1, 0x51, 0x65, 0x9a, 0xd5, 0x35,
0x06, 0x68, 0xba, 0x6d, 0x66, 0x52, 0x49, 0x31, 0x97, 0x5f, 0x11, 0x43,
0xaf, 0x08, 0x22, 0x8a, 0x30, 0x42, 0x88, 0xca, 0xcc, 0x32, 0x66, 0x25,
0x29, 0x0d, 0xdf, 0xf1, 0x75, 0x8f, 0x00, 0x5f, 0xef, 0x12, 0x3c, 0xcb,
0xff, 0xdc, 0x9f, 0xa3, 0x57, 0x2d, 0x58, 0x0c, 0x08, 0x88, 0xc4, 0x33,
0xcc, 0x30, 0x6d, 0xe2, 0x75, 0xe2, 0xa9, 0x4d, 0xdb, 0xe0, 0xbc, 0x4f,
0x1c, 0x63, 0x65, 0x59, 0x25, 0x3e, 0x27, 0x1e, 0x35, 0xe9, 0x82, 0xc4,
0x8f, 0x5c, 0x57, 0x3c, 0x7e, 0xe3, 0x5c, 0x72, 0x59, 0xe0, 0x99, 0x31,
0x33, 0x9b, 0x99, 0x23, 0x8e, 0x11, 0x8b, 0xa5, 0x0e, 0x56, 0x3a, 0x98,
0x95, 0x4d, 0x8d, 0x78, 0x92, 0x38, 0xae, 0x6a, 0x3a, 0xe5, 0x0b, 0x39,
0x8f, 0x55, 0xce, 0x5b, 0x9c, 0xb5, 0x6a, 0x8d, 0xb5, 0xee, 0xc9, 0x5f,
0x18, 0x29, 0xe8, 0xcb, 0x4b, 0x5c, 0xa7, 0x39, 0x84, 0x14, 0x16, 0xb0,
0x08, 0x09, 0x22, 0x14, 0xd4, 0x50, 0x41, 0x15, 0x36, 0x12, 0xb4, 0xea,
0xa4, 0x58, 0xc8, 0xd0, 0x7e, 0xd2, 0xc7, 0x3f, 0xe8, 0xfa, 0x25, 0x72,
0x29, 0xe4, 0xaa, 0x80, 0x91, 0x63, 0x1e, 0x1b, 0xd0, 0x20, 0xbb, 0x7e,
0xf0, 0x3f, 0xf8, 0xdd, 0xad, 0x55, 0x9c, 0x18, 0xf7, 0x92, 0x22, 0x49,
0xa0, 0xfb, 0xc5, 0x71, 0x3e, 0x86, 0x81, 0xd0, 0x2e, 0xd0, 0xac, 0x3b,
0xce, 0xf7, 0xb1, 0xe3, 0x34, 0x4f, 0x80, 0xe0, 0x33, 0x70, 0xa5, 0xb7,
0xfd, 0x1b, 0x0d, 0x60, 0xfa, 0x93, 0xf4, 0x7a, 0x5b, 0x8b, 0x1f, 0x01,
0x7d, 0xdb, 0xc0, 0xc5, 0x75, 0x5b, 0x53, 0xf6, 0x80, 0xcb, 0x1d, 0x60,
0xe0, 0xc9, 0x90, 0x4d, 0xd9, 0x95, 0x82, 0x34, 0x85, 0x62, 0x11, 0x78,
0x3f, 0xa3, 0x6f, 0xca, 0x03, 0xfd, 0xb7, 0x40, 0x78, 0xd5, 0xeb, 0xad,
0xb5, 0x8f, 0xd3, 0x07, 0x20, 0x4b, 0x5d, 0xa5, 0x6f, 0x80, 0x83, 0x43,
0x60, 0xa4, 0x44, 0xd9, 0x6b, 0x3e, 0xef, 0xee, 0xe9, 0xec, 0xed, 0xdf,
0x33, 0xad, 0xfe, 0x7e, 0x00, 0xf1, 0x30, 0x72, 0x73, 0x32, 0x0f, 0x86,
0xba, 0x00, 0x00, 0x00, 0x06, 0x62, 0x4b, 0x47, 0x44, 0x00, 0xff, 0x00,
0xff, 0x00, 0xff, 0xa0, 0xbd, 0xa7, 0x93, 0x00, 0x00, 0x00, 0x09, 0x70,
0x48, 0x59, 0x73, 0x00, 0x00, 0x2e, 0x23, 0x00, 0x00, 0x2e, 0x23, 0x01,
0x78, 0xa5, 0x3f, 0x76, 0x00, 0x00, 0x00, 0x07, 0x74, 0x49, 0x4d, 0x45,
0x07, 0xe6, 0x03, 0x10, 0x0a, 0x07, 0x30, 0x7f, 0x7f, 0x5c, 0xcd, 0x00,
0x00, 0x00, 0x19, 0x74, 0x45, 0x58, 0x74, 0x43, 0x6f, 0x6d, 0x6d, 0x65,
0x6e, 0x74, 0x00, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x77,
0x69, 0x74, 0x68, 0x20, 0x47, 0x49, 0x4d, 0x50, 0x57, 0x81, 0x0e, 0x17,
0x00, 0x00, 0x05, 0xcf, 0x49, 0x44, 0x41, 0x54, 0x78, 0xda, 0xed, 0x9d,
0x4d, 0x2c, 0x33, 0x6b, 0x14, 0xc7, 0xff, 0x53, 0x45, 0xe2, 0xdb, 0xa6,
0x24, 0xc4, 0xb6, 0x74, 0x25, 0x5d, 0x92, 0xb8, 0xef, 0x95, 0xf4, 0x5e,
0xe6, 0xa6, 0x41, 0xc4, 0xc6, 0x0a, 0xa1, 0x09, 0x09, 0x0b, 0x0b, 0x4d,
0x23, 0xe9, 0xba, 0x12, 0x56, 0xa4, 0x96, 0x16, 0x6c, 0x48, 0x44, 0x48,
0xae, 0xba, 0x21, 0xb9, 0x97, 0x10, 0x12, 0x3b, 0x0b, 0x65, 0x2b, 0xda,
0x88, 0x08, 0x8d, 0x46, 0x54, 0xab, 0x7d, 0xee, 0xe2, 0x35, 0xde, 0x69,
0x55, 0xfb, 0xcc, 0x97, 0x76, 0xc6, 0x9c, 0xa4, 0x91, 0xea, 0xf3, 0x31,
0xfe, 0xce, 0xf3, 0x9c, 0xdf, 0x39, 0x33, 0x9d, 0x61, 0x08, 0x21, 0x04,
0xba, 0x89, 0x36, 0x23, 0x00, 0xfc, 0xd5, 0xf9, 0x3b, 0x12, 0x89, 0x64,
0x1d, 0x0d, 0x06, 0x06, 0x24, 0x41, 0xc0, 0x18, 0x98, 0xa4, 0xcf, 0x0c,
0xbc, 0xf7, 0x86, 0x94, 0xcf, 0xf8, 0xbf, 0xe3, 0xfa, 0x03, 0x00, 0x01,
0xc0, 0xa4, 0xfc, 0xe4, 0xcf, 0x41, 0x78, 0xfd, 0xf8, 0x9f, 0xe3, 0xad,
0x3d, 0x93, 0x61, 0x2c, 0xa4, 0x19, 0x97, 0xdf, 0x27, 0xd5, 0x3b, 0x0c,
0x69, 0xfe, 0x9e, 0x74, 0xc6, 0xef, 0x9b, 0x7a, 0x4c, 0x5c, 0x9f, 0xbf,
0x7d, 0xff, 0xfe, 0x14, 0x30, 0x91, 0x20, 0xf0, 0xfd, 0xf3, 0x9f, 0xee,
0x4e, 0x02, 0x8c, 0xfd, 0xf3, 0xc7, 0x4f, 0x31, 0x33, 0xfd, 0x17, 0x74,
0xfb, 0xdc, 0xde, 0x57, 0x11, 0xe7, 0x81, 0xba, 0x89, 0x33, 0x83, 0x2e,
0x81, 0x0c, 0x02, 0xea, 0x0b, 0x58, 0xa2, 0x80, 0xfa, 0x02, 0xd6, 0x3d,
0x30, 0xc7, 0x02, 0xea, 0x51, 0x58, 0x0f, 0x22, 0x34, 0xe6, 0xf3, 0xf9,
0xe0, 0xf3, 0xf9, 0x64, 0x19, 0x8b, 0xf9, 0x4e, 0x18, 0x13, 0x8f, 0xc7,
0xb1, 0xb4, 0xb4, 0x04, 0x96, 0x65, 0xc1, 0xb2, 0xac, 0x2c, 0x22, 0x72,
0xab, 0x56, 0xf3, 0x7b, 0x60, 0x24, 0x12, 0xc1, 0xcc, 0xcc, 0x0c, 0x86,
0x86, 0x86, 0x7e, 0x65, 0x11, 0x32, 0x88, 0xf8, 0x9e, 0xce, 0x6a, 0x79,
0x0f, 0x0c, 0x85, 0x42, 0x98, 0x9a, 0x9a, 0xc2, 0xf4, 0xf4, 0xf4, 0xc7,
0x54, 0x4c, 0xa2, 0x88, 0x8c, 0xd6, 0xf7, 0xc0, 0x60, 0x30, 0x88, 0xe1,
0xe1, 0x61, 0xcc, 0xcf, 0xcf, 0x7f, 0x9e, 0xcf, 0x4a, 0x10, 0x91, 0xdb,
0xf4, 0x8c, 0x5c, 0xe5, 0x41, 0x4b, 0x76, 0x79, 0x79, 0x89, 0x81, 0x81,
0x01, 0x9c, 0x9c, 0x9c, 0x64, 0x6d, 0x1b, 0x8b, 0xc5, 0xc4, 0x45, 0xdf,
0xb7, 0x55, 0x6b, 0xd4, 0x1a, 0x48, 0x1f, 0x1f, 0x1f, 0xa3, 0xbb, 0xbb,
0x1b, 0xb7, 0xb7, 0xb7, 0x59, 0xdb, 0x2e, 0x2c, 0x2c, 0xc0, 0x6e, 0xb7,
0x4b, 0x9a, 0xcf, 0xa8, 0x35, 0x4c, 0x61, 0x59, 0x96, 0xaa, 0xad, 0xdb,
0xed, 0x86, 0xc3, 0xe1, 0x00, 0xc3, 0x48, 0xdb, 0xff, 0x35, 0x11, 0x85,
0xf9, 0x98, 0x42, 0x63, 0x0e, 0x87, 0x03, 0x4e, 0xa7, 0x13, 0x85, 0x85,
0x85, 0x7a, 0x14, 0x4e, 0x87, 0x29, 0x99, 0xcc, 0x6e, 0xb7, 0xc3, 0xe3,
0xf1, 0xa0, 0xa4, 0xa4, 0x44, 0x96, 0xf9, 0x55, 0xbd, 0x84, 0x43, 0xa1,
0x10, 0xdc, 0x6e, 0x77, 0xc6, 0x48, 0xcb, 0x37, 0xab, 0xd5, 0x8a, 0xc5,
0xc5, 0x45, 0x54, 0x57, 0x57, 0xcb, 0x96, 0x89, 0x18, 0xd5, 0x9a, 0x89,
0x04, 0x83, 0x41, 0x4c, 0x4c, 0x4c, 0x60, 0x7d, 0x7d, 0x9d, 0xaa, 0xbd,
0xc9, 0x64, 0xc2, 0xca, 0xca, 0x0a, 0xea, 0xea, 0xea, 0x64, 0x99, 0x9f,
0xa8, 0xd9, 0x03, 0x85, 0x60, 0x0a, 0x67, 0x1b, 0x1b, 0x1b, 0x68, 0x6a,
0x6a, 0x92, 0xaf, 0x88, 0xc0, 0xc7, 0x18, 0x35, 0x9d, 0x13, 0x11, 0x82,
0x29, 0x9c, 0x6d, 0x6e, 0x6e, 0xa2, 0xa5, 0xa5, 0x45, 0xd6, 0xe3, 0xe0,
0x56, 0xad, 0xaa, 0x96, 0xb0, 0x10, 0x4c, 0x91, 0x93, 0xf5, 0x54, 0x9f,
0xca, 0x09, 0xc5, 0x14, 0xb9, 0x59, 0x2f, 0x6b, 0x35, 0x46, 0x4b, 0x98,
0x22, 0x27, 0xeb, 0xd1, 0x2c, 0x61, 0x10, 0x42, 0x48, 0xc7, 0x1f, 0xbf,
0x91, 0x7c, 0xb4, 0x87, 0x87, 0x07, 0x32, 0x3e, 0x3e, 0x4e, 0xde, 0x82,
0x1e, 0xf5, 0xcb, 0x6e, 0xb7, 0x93, 0xfb, 0xfb, 0x7b, 0x45, 0x8f, 0xad,
0xf3, 0x4d, 0xb3, 0xbc, 0x8d, 0xc2, 0x42, 0x31, 0x45, 0x09, 0xd6, 0x53,
0x2d, 0xc6, 0x88, 0xc1, 0x14, 0x25, 0x58, 0x8f, 0x3a, 0x13, 0xc9, 0x27,
0x8c, 0x11, 0x83, 0x29, 0x4a, 0xb1, 0x1e, 0x75, 0x26, 0x92, 0x2f, 0xf5,
0x40, 0x31, 0x98, 0xa2, 0x24, 0xeb, 0xa9, 0x26, 0x0a, 0x8b, 0xc5, 0x14,
0xa5, 0x59, 0x8f, 0xba, 0x1a, 0xa3, 0x46, 0x4c, 0xf9, 0x0a, 0xd6, 0xa3,
0x59, 0xc2, 0x39, 0xc5, 0x18, 0xb1, 0x98, 0xc2, 0xbd, 0x1c, 0x0e, 0x07,
0x79, 0x7a, 0x7a, 0xca, 0xc9, 0xb1, 0xb3, 0x1d, 0x3f, 0x7e, 0x61, 0x4c,
0x2e, 0x42, 0x88, 0x58, 0x4c, 0x51, 0xaa, 0xae, 0x27, 0x18, 0x63, 0xf8,
0xb9, 0xf0, 0x57, 0x17, 0x54, 0xc5, 0x62, 0xca, 0x57, 0xb3, 0x1e, 0x35,
0x07, 0x7e, 0x65, 0x14, 0x96, 0x82, 0x29, 0xb9, 0x62, 0xbd, 0xac, 0x1c,
0xa8, 0x06, 0x4c, 0xc9, 0x05, 0xeb, 0x51, 0x57, 0x63, 0x94, 0xf6, 0x3f,
0xa9, 0x98, 0x92, 0x2b, 0xd6, 0xa3, 0x59, 0xc2, 0x8a, 0x63, 0x8c, 0x54,
0x4c, 0xc9, 0x25, 0xeb, 0xe5, 0x1c, 0x63, 0xa4, 0x62, 0x0a, 0xf7, 0x72,
0xbb, 0xdd, 0x24, 0x1a, 0x8d, 0xe6, 0x55, 0xa5, 0x88, 0xab, 0xc6, 0x80,
0xff, 0x46, 0x4e, 0x0b, 0x04, 0x02, 0xa4, 0xb7, 0xb7, 0x57, 0xb2, 0x78,
0xb9, 0x64, 0x3d, 0x6a, 0x0e, 0x94, 0x7b, 0x0f, 0x94, 0x8a, 0x29, 0xf9,
0xc2, 0x7a, 0xf4, 0x1c, 0x98, 0x47, 0x98, 0x92, 0x4f, 0xac, 0x47, 0x1d,
0x44, 0xe4, 0x04, 0xe9, 0x58, 0x2c, 0x26, 0x59, 0xbc, 0x7c, 0x63, 0xbd,
0x4c, 0x26, 0xfb, 0x25, 0xbe, 0x6d, 0x6d, 0x6d, 0xd8, 0xdf, 0xdf, 0xd7,
0x04, 0xeb, 0x51, 0x0b, 0x28, 0x77, 0x41, 0x55, 0x8a, 0x88, 0xf9, 0xc4,
0x7a, 0xd4, 0x02, 0x2a, 0x91, 0xca, 0x89, 0x11, 0x31, 0xdf, 0x58, 0x8f,
0x5a, 0x40, 0xa5, 0x4c, 0x88, 0x88, 0xb9, 0xaa, 0xeb, 0x89, 0x16, 0x4e,
0x4a, 0x45, 0x3a, 0x1a, 0x8d, 0x62, 0x65, 0x65, 0x85, 0xea, 0xfa, 0x62,
0x1a, 0x11, 0x95, 0x3e, 0x87, 0xab, 0x24, 0xc6, 0x08, 0xce, 0x44, 0xee,
0xee, 0xee, 0xc8, 0xe8, 0xe8, 0xe8, 0x3b, 0xe8, 0xee, 0xee, 0xee, 0x52,
0xf5, 0xdb, 0xdd, 0xdd, 0x4d, 0x0b, 0xca, 0x3d, 0x3d, 0x3d, 0x8a, 0x9f,
0xc3, 0x55, 0xc2, 0x3a, 0xf8, 0x99, 0x08, 0x47, 0xd5, 0x34, 0xa9, 0x59,
0x7f, 0x7f, 0xff, 0x07, 0x11, 0xb6, 0xb7, 0xb7, 0xa9, 0xfa, 0xef, 0xef,
0xef, 0x27, 0xf5, 0xb3, 0x5a, 0xad, 0xe4, 0xfa, 0xfa, 0x9a, 0xa8, 0xd1,
0x3a, 0x84, 0xa6, 0x72, 0x2f, 0x2f, 0x2f, 0x64, 0x64, 0x64, 0xe4, 0xd3,
0x94, 0x4b, 0xa8, 0x27, 0x9a, 0x4c, 0x26, 0xe2, 0xf7, 0xfb, 0x89, 0x5a,
0x2d, 0x49, 0x40, 0x9a, 0x25, 0xbc, 0xba, 0xba, 0x9a, 0x35, 0x6f, 0x15,
0x22, 0xe2, 0xd1, 0xd1, 0x11, 0x51, 0xb3, 0x09, 0x12, 0x30, 0x18, 0x0c,
0x92, 0xf2, 0xf2, 0x72, 0xaa, 0xe4, 0x9f, 0x56, 0x44, 0xb5, 0x1b, 0xa7,
0x19, 0x55, 0x14, 0xde, 0xdb, 0xdb, 0x43, 0x38, 0x1c, 0xa6, 0x8a, 0x4e,
0x36, 0x9b, 0x4d, 0xb6, 0x6f, 0x44, 0x6a, 0x22, 0x13, 0x89, 0x46, 0xa3,
0x98, 0x9d, 0x9d, 0x15, 0x34, 0x28, 0xcb, 0xb2, 0xd8, 0xdb, 0xdb, 0xfb,
0x3e, 0x02, 0x66, 0xca, 0x44, 0x02, 0x81, 0x00, 0xce, 0xce, 0xce, 0x04,
0x0f, 0xac, 0x75, 0x4f, 0x4c, 0x02, 0xe9, 0x4c, 0x89, 0xdc, 0xd5, 0xd5,
0x95, 0xe8, 0x49, 0xb4, 0xec, 0x89, 0xd4, 0x97, 0x76, 0xd0, 0xee, 0x7d,
0x9f, 0xd9, 0xe3, 0xe3, 0xa3, 0xf6, 0x97, 0x70, 0xb6, 0xb4, 0x4d, 0xac,
0x39, 0x1c, 0x0e, 0x74, 0x75, 0x75, 0x69, 0x5f, 0xc0, 0x4c, 0xe9, 0x7b,
0x45, 0x45, 0x85, 0xe8, 0xc1, 0x07, 0x07, 0x07, 0x51, 0x50, 0x50, 0xf0,
0xbd, 0xf7, 0xc0, 0x9a, 0x9a, 0x1a, 0xd1, 0x93, 0x34, 0x36, 0x36, 0x6a,
0xd6, 0xf3, 0x92, 0xf6, 0xc0, 0x4c, 0x18, 0xd3, 0xd0, 0xd0, 0x80, 0xf2,
0xf2, 0x72, 0xc1, 0x13, 0x58, 0x2c, 0x16, 0x54, 0x55, 0x55, 0x69, 0x56,
0x40, 0xea, 0xbb, 0x76, 0x54, 0x56, 0x56, 0x62, 0x72, 0x72, 0x52, 0xf0,
0x04, 0xb5, 0xb5, 0xb5, 0x9a, 0xde, 0xfb, 0x04, 0xdd, 0xb5, 0x43, 0x4c,
0x20, 0x38, 0x3d, 0x3d, 0x45, 0x3c, 0x1e, 0xff, 0x1e, 0x4b, 0x38, 0x5b,
0x41, 0xbf, 0xb9, 0xb9, 0x19, 0x2e, 0x97, 0x4b, 0xd0, 0x04, 0xe1, 0x70,
0x18, 0x37, 0x37, 0x37, 0xdf, 0x23, 0x13, 0xc9, 0xea, 0xae, 0x0c, 0x83,
0xb1, 0xb1, 0x31, 0x58, 0x2c, 0x16, 0x41, 0x83, 0xfb, 0xfd, 0x7e, 0x5d,
0x40, 0xce, 0xea, 0xeb, 0xeb, 0xb1, 0xbc, 0xbc, 0x2c, 0x68, 0xf0, 0x9d,
0x9d, 0x1d, 0x68, 0xfd, 0x1e, 0xb7, 0x82, 0xce, 0x89, 0x58, 0xad, 0x56,
0x1c, 0x1e, 0x1e, 0xc2, 0x64, 0x32, 0x51, 0xb5, 0x9f, 0x9b, 0x9b, 0xc3,
0xf9, 0xf9, 0xb9, 0xf6, 0x39, 0x50, 0xc8, 0x79, 0xb0, 0xd6, 0xd6, 0x56,
0x1c, 0x1c, 0x1c, 0xa0, 0xbd, 0xbd, 0x9d, 0xaa, 0xbd, 0xd7, 0xeb, 0xc5,
0xeb, 0xeb, 0xab, 0xee, 0x81, 0x7c, 0x33, 0x9b, 0xcd, 0xd8, 0xda, 0xda,
0xc2, 0xda, 0xda, 0x5a, 0x56, 0x6f, 0xf4, 0x7a, 0xbd, 0x58, 0x5a, 0x5a,
0xd2, 0xdc, 0x52, 0x16, 0x14, 0x85, 0xd3, 0x59, 0x69, 0x69, 0x29, 0xfa,
0xfa, 0xfa, 0x70, 0x76, 0x76, 0x86, 0xb5, 0xb5, 0x35, 0xd8, 0x6c, 0xb6,
0x8c, 0x39, 0xf1, 0xfa, 0xfa, 0x3a, 0x12, 0x89, 0x84, 0xf6, 0x5c, 0x50,
0xae, 0x0b, 0x2c, 0x63, 0xb1, 0x18, 0xb9, 0xb8, 0xb8, 0x20, 0xdb, 0xdb,
0xdb, 0xc4, 0xe3, 0xf1, 0x10, 0x9b, 0xcd, 0xf6, 0xa1, 0xdc, 0xef, 0x72,
0xb9, 0x88, 0xdf, 0xef, 0x27, 0x91, 0x48, 0x44, 0xf5, 0x25, 0xfd, 0xa4,
0xaf, 0xbb, 0xca, 0x71, 0x2d, 0x80, 0xd1, 0x68, 0x84, 0xd9, 0x6c, 0x86,
0xd9, 0x6c, 0x46, 0x67, 0x67, 0x27, 0x9c, 0x4e, 0x27, 0xe2, 0xf1, 0x38,
0x9e, 0x9f, 0x9f, 0x11, 0x89, 0x44, 0x90, 0x48, 0x24, 0x50, 0x54, 0x54,
0x84, 0xe2, 0xe2, 0x62, 0x18, 0x8d, 0xda, 0xb9, 0x61, 0x92, 0xa2, 0xf7,
0xce, 0x2a, 0x28, 0x28, 0x40, 0x59, 0x59, 0x19, 0xca, 0xca, 0xca, 0xbe,
0x6f, 0x39, 0x4b, 0x37, 0x4a, 0x0f, 0xec, 0x7c, 0xbb, 0x37, 0x7c, 0x2a,
0xeb, 0xf0, 0x0b, 0x0d, 0xfc, 0x9b, 0xff, 0xa7, 0x6b, 0xc3, 0x64, 0xf1,
0x66, 0xfe, 0x03, 0x0a, 0xc0, 0x1b, 0x2b, 0xdd, 0x43, 0x0d, 0xd2, 0xcd,
0x99, 0xfa, 0xc0, 0x02, 0xfe, 0x7b, 0x2e, 0xc1, 0xe7, 0x1e, 0x84, 0x90,
0x6e, 0xbc, 0x74, 0x0f, 0x42, 0xe0, 0xc6, 0xe6, 0x8f, 0xc9, 0x45, 0xd9,
0x74, 0x0f, 0x46, 0xe0, 0x17, 0x12, 0x00, 0x80, 0xd1, 0x1f, 0x87, 0x21,
0xcd, 0xfe, 0x07, 0x67, 0x0b, 0x51, 0x76, 0xa9, 0x0d, 0x92, 0xed, 0x00,
0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82
};
const size_t temp_logo_png_len = sizeof(temp_logo_png) / sizeof(char);
|
the_stack_data/127190.c | /*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)memset.c 5.6 (Berkeley) 1/26/91";*/
static char *rcsid = "$NetBSD: memset.c,v 1.4 1997/10/13 11:55:37 lukem Exp $";
#endif /* LIBC_SCCS and not lint */
#ifndef _KERNEL
#include <string.h>
#else
#include <lib/libkern/libkern.h>
#endif
void *
memset(dst, c, n)
void *dst;
register int c;
register size_t n;
{
if (n != 0) {
register char *d = dst;
do
*d++ = c;
while (--n != 0);
}
return (dst);
}
|
the_stack_data/100140218.c | int lengthOfLastWord(char *s) {
int len = strlen(s);
int i = len -1;
int ret = 0;
while(i >= 0 && s[i] == ' ')
i--;
while(i >= 0 && s[i] != ' '){
ret++;
i--;
}
return ret;
}
|
the_stack_data/1210066.c | #include <stdio.h>
minimum(int no1,int no2);
maximum(int no1,int no2);
multiply(int no1,int no2);
int main() {
int no1, no2;
printf("Enter a value for no 1 : ");
scanf("%d", &no1);
printf("Enter a value for no 2 : ");
scanf("%d", &no2);
printf("%d ", minimum(no1, no2));
printf("%d ", maximum(no1, no2));
printf("%d ", multiply(no1, no2));
return 0;
}
minimum(int no1,int no2){
if(no1>no2)
return no2;
else
return no1;
}
maximum(int no1,int no2){
if(no1<no2)
return no2;
else
return no1;
}
multiply(int no1,int no2){
return no1*no2;
}
|
the_stack_data/60925.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <math.h>
//=============================================================================
// Fast string to interger convert to ANSYS formatted intergers
//=============================================================================
__inline int fast_atoi(char* raw, int intsz){
int val;
int c;
val = 0;
for (c=0; c<intsz; ++c){
// Seek through white space
if (raw[0] == ' '){
++raw;
continue;
}
val = val*10 + (raw[0] - '0');
++raw;
}
return val;
}
//=============================================================================
// Checks for negative character
//=============================================================================
__inline int checkneg(char *raw, int intsz){
int c;
for (c=0; c<intsz; ++c){
if (raw[0] == '-'){
return 1;
}
++raw;
}
return 0;
}
// Reads various ansys float formats in the form of
// "3.7826539829200E+00"
// "1.0000000000000E-001"
// " -6.01203 "
//
// fltsz : Number of characters to read in a floating point number
__inline int ans_strtod(char *raw, int fltsz, double *arr){
int i;
double sign = 1;
for (i=0; i<fltsz; i++){
if (*raw == '\r' || *raw == '\n'){
// value is zero then
arr[0] = 0;
/* printf("EOL"); */
return 1;
}
else if (*raw != ' '){ // always skip whitespace
break;
}
raw++;
}
// either a number of a sign
if (*raw == '-'){
sign = -1;
++raw;
++i;
}
// next value is always a number
double val = *raw++ - '0'; i++;
// next value is always a "."
raw++; i++;
// Read through the rest of the number
double k = 0.1;
for (; i<fltsz; i++){
if (*raw == 'e' || *raw == 'E'){ // incredibly, can be lowercase
break;
}
else if (*raw >= '0' && *raw <= '9') {
val += (*raw++ - '0') * k;
k *= 0.1;
}
}
// Might have scientific notation left, for example:
// 1.0000000000000E-001
int evalue = 0;
int esign = 1;
if (*raw == 'e' || *raw == 'E'){
raw++; // skip "E"
// always a sign of some sort
if (*raw == '-'){
esign = -1;
}
raw++; i++; i++; // skip E and sign
/* printf(" %d<%d ", i, fltsz); */
for (; i<fltsz; i++){
// read to whitespace or end of the line
if (*raw == ' ' || *raw == '\r' || *raw == '\n'){
break;
}
evalue = evalue*10 + (*raw++ - '0');
}
val *= pow(10, esign*evalue);
}
// seek through end of float value
if (sign == -1){
*arr = -val;
}
else {
*arr = val;
}
/* printf(", %f", val); */
return 0; // Return 0 when a number has a been read
}
static inline double ans_strtod2(char *raw, int fltsz){
int i;
double sign = 1;
for (i=0; i<fltsz; i++){
if (*raw == '\r' || *raw == '\n'){
// value is zero then
return 0;
}
else if (*raw != ' '){ // always skip whitespace
break;
}
raw++;
}
// either a number of a sign
if (*raw == '-'){
sign = -1;
++raw;
++i;
}
// next value is always a number
double val = *raw++ - '0'; i++;
double k = 10;
for (; i<fltsz; i++){
if (*raw == '.'){
raw++;
break;
}
else {
val *= k;
val += (*raw++ - '0');
k *= 10;
}
}
// Read through the rest of the number
k = 0.1;
for (; i<fltsz; i++){
if (*raw == 'e' || *raw == 'E'){
break;
}
else if (*raw >= '0' && *raw <= '9') {
val += (*raw++ - '0') * k;
k *= 0.1;
}
}
// Might have scientific notation left, for example:
// 1.0000000000000E-001
int evalue = 0;
int esign = 1;
if (*raw == 'e' || *raw == 'E'){
raw++; // skip "E"
// always a sign of some sort
if (*raw == '-'){
esign = -1;
}
raw++; i++; i++; // skip E and sign
for (; i<fltsz; i++){
// read to whitespace or end of the line
if (*raw == ' ' || *raw == '\r' || *raw == '\n'){
break;
}
evalue = evalue*10 + (*raw++ - '0');
}
val *= pow(10, esign*evalue);
}
// seek through end of float value
if (sign == -1){
return -val;
}
return val;
}
//=============================================================================
// reads nblock from ANSYS. Raw string is from Python reader and file is
// positioned at the start of the data of NBLOCK
//
// Returns
// -------
// nnodes_read : int
// Number of nodes read.
//=============================================================================
int read_nblock(char *raw, int *nnum, double *nodes, int nnodes, int* intsz,
int fltsz, int *n){
// set to start of the NBLOCK
raw += n[0];
int len_orig = strlen(raw);
int i, j, i_val, eol;
for (i=0; i<nnodes; i++){
// It's possible that less nodes are written to the record than
// indicated. In this case the line starts with a -1
if (raw[0] == '-'){
break;
}
i_val = fast_atoi(raw, intsz[0]);
/* printf("%d", i_val); */
nnum[i] = i_val;
raw += intsz[0];
raw += intsz[1];
raw += intsz[2];
for (j=0; j<6; j++){
eol = ans_strtod(raw, fltsz, &nodes[6*i + j]);
if (eol) {
break;
}
else {
raw += fltsz;
}
}
// remaining are zeros
for (; j<6; j++){
nodes[6*i + j] = 0;
}
// possible whitespace (occurs in hypermesh generated files)
while (*raw == ' '){
++raw;
}
while (*raw == '\r' || *raw == '\n'){
++raw;
}
/* printf("\n"); */
}
// return file position
/* int fpos = len_orig - strlen(raw) + n[0]; */
/* return fpos; */
n[0] += len_orig - strlen(raw);
return i;
}
/* Read just the node coordinates from the output from the MAPDL
* NWRITE command
* (I8, 6G20.13) to write out NODE,X,Y,Z,THXY,THYZ,THZX
*/
int read_nblock_from_nwrite(const char* filename, int *nnum, double *nodes,
int nnodes){
FILE * stream = fopen(filename, "r");
if(stream == NULL)
{
printf("Error opening file");
exit(1);
}
// set to start of the NBLOCK
const int bufsize = 74; // One int, 3 floats, two end char max (/r/n)
char buffer[74];
int i;
for (i=0; i<nnodes; i++){
fgets(buffer, bufsize, stream);
nnum[i] = fast_atoi(&buffer[0], 9);
// X
if (buffer[9] == '\r' || buffer[9] == '\n'){
nodes[i*3 + 0] = 0;
nodes[i*3 + 1] = 0;
nodes[i*3 + 2] = 0;
continue;
}
nodes[i*3 + 0] = ans_strtod2(&buffer[9], 21);
// Y
if (buffer[30] == '\r' || buffer[30] == '\n'){
nodes[i*3 + 1] = 0;
nodes[i*3 + 2] = 0;
continue;
}
nodes[i*3 + 1] = ans_strtod2(&buffer[30], 21);
// Z
if (buffer[51] == '\r' || buffer[51] == '\n'){
nodes[i*3 + 2] = 0;
continue;
}
nodes[i*3 + 2] = ans_strtod2(&buffer[51], 21);
}
fclose(stream);
return 0;
}
/* ============================================================================
* Function: read_eblock
*
* Reads EBLOCK from ANSYS archive file.
* raw : Raw string is from Python reader
*
* elem_off : Indices of the start of each element in ``elem``
*
* elem: Array of elements
* Each element contains 10 items plus the nodes belonging to the
* element. The first 10 items are:
* mat - material reference number
* type - element type number
* real - real constant reference number
* secnum - section number
* esys - element coordinate system
* death - death flag (0 - alive, 1 - dead)
* solidm - solid model reference
* shape - coded shape key
* elnum - element number
* baseeid- base element number (applicable to reinforcing elements only
* nodes - The nodes belonging to the element in ANSYS numbering.
*
* nelem : Number of elements.
*
* pos : Position of the start of the EBLOCK.
* ==========================================================================*/
int read_eblock(char *raw, int *elem_off, int *elem, int nelem, int intsz,
int *pos){
int i, j, nnode;
// set to start of the EBLOCK
raw += pos[0];
int len_orig = strlen(raw);
int c = 0; // position in elem array
// Loop through elements
for (i=0; i<nelem; ++i){
// store start of each element
elem_off[i] = c;
// Check if end of line
while (raw[0] == '\r' || raw[0] == '\n' ){
++raw;
}
// Check if at end of the block
if (checkneg(raw, intsz)){
raw += intsz;
break;
}
// ANSYS archive format:
// Field 1: material reference number
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 2: element type number
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 3: real constant reference number
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 4: section number
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 5: element coordinate system
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 6: Birth/death flag
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 7: Solid model reference
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 8: Coded shape key
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
// Field 9: Number of nodes
nnode = fast_atoi(raw, intsz); raw += intsz;
/* // sanity check */
/* if (nnode > 20){ */
/* printf("Element %d\n", i); */
/* perror("Greater than 20 nodes\n"); */
/* exit(1); */
/* } */
// Field 10: Not Used
raw += intsz;
// Field 11: Element number
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
/* printf("reading element %d\n", elem[c - 1]); */
// Need an additional value for consitency with other formats
elem[c++] = 0;
// Read nodes in element
for (j=0; j<nnode; j++){
/* printf("reading node %d\n", j); */
// skip through EOL
while (raw[0] == '\r' || raw[0] == '\n' ) ++raw;
elem[c++] = fast_atoi(raw, intsz); raw += intsz;
}
}
// update file position
*(pos) = len_orig - strlen(raw) + pos[0];
// Return total data read
elem_off[nelem] = c;
return c;
}
// Simply write an array to disk as ASCII
int write_array_ascii(const char* filename, const double *arr,
const int nvalues){
FILE * stream = fopen(filename, "w");
int i;
for (i=0; i<nvalues; i++) {
fprintf(stream, "%20.12E\n", arr[i]);
}
fclose(stream);
return 0;
}
/* int main(){ */
/* const char* filename = "/tmp/ */
/* read_nblock_from_nwrite( filename, int *nnum, double *nodes, */
/* int nnodes){ */
|
the_stack_data/242329388.c | /*
** $VER: graphics3Dm68k.c 10.00 (01.02.98)
**
** Functions for graphics3D.library on a 68000
**
** Note: this code is take from lib sources of C Compiler VBCC
**
*/
/** divisione con segno tra numeri a 32bit **/
long _ldivs(long z,long n)
{
unsigned long uz,un,t=1;long q=0;int s=1;
if(!n) return(0);
if(z>=0) uz=z; else {uz=-z;s=-s;}
if(n>=0) un=n; else {un=-n;s=-s;}
while(un<=0xffffffff/2&&un<=uz/2){
t*=2;
un*=2;
}
while(t){
if(uz>=un){ q+=t; uz-=un;}
t/=2;
un/=2;
}
if(s>0) return(q); else return(-q);
}
|
the_stack_data/100141190.c | //Matriz de 6x6 rellena de numeros del 1 al 36
#include <stdio.h>
int main(void){
int x,y,z = 1;
printf("\nMatriz 6x6\n");
for(x = 0; x <= 5; x++){
for(y = 0; y <= 5; y++){
printf("[%d]\t",z);
z++;
}//fin for
printf("\n");
}//fin for
getchar();
return 0;
}//fin int main
|
the_stack_data/126218.c | // However, if two formal parameters become comparable solely because
// their actual parameters in one call are comparable (derived
// comparability), then all sets of actual parameters do NOT
// automatically become comparable.
void m(int x, int y) {
return;
}
void n(int x, int y) {
return;
}
int main() {
int a, b = 2, c = 3, d = 4;
a = b;
m(a, b);
m(c, d);
n(c, d);
return 0;
}
|
the_stack_data/90761706.c | #include<stdlib.h>
main()
{
system("php /Users/silen/Programs/PHP/composer.phar ");
}
|
the_stack_data/64199936.c | int f (float x) {
int m = __alignof__ x;
int n = __alignof__ (x);
return n + m;
}
|
the_stack_data/996428.c | /* pe14.8 -- ticket.c */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SEATNUM 12
struct name {
char first[20];
char last[20];
};
struct seat {
int id;
int assigned;
struct name customer;
};
char show_menu(void);
void eat_line(void);
void init_seats(struct seat seats[], int n);
int get_empty_seat_number(struct seat seats[], int n);
void show_empty_seats(struct seat seats[], int n);
void show_seats(struct seat seats[], int n);
int assign_customer_to_seat_and_save(struct seat seats[], int n, FILE* fp);
int delete_seat_assignment(struct seat seats[], int n, FILE* fp);
void save_seats(struct seat seats[], int n, FILE* fp);
int main(void)
{
struct seat plane[SEATNUM];
char choice;
FILE* fp;
// Open file
fp = fopen("plane.dat", "r+b");
if (fp == NULL) {
fprintf(stderr, "Cannot open file\n");
exit(1);
}
// Read file content
if (0 == fread(plane, sizeof(struct seat), SEATNUM, fp)) {
init_seats(plane, SEATNUM);
puts("Init plane");
}
while ((choice = show_menu()) != 'f') {
switch (choice) {
case 'a':
printf("%d empty seats left.\n", get_empty_seat_number(plane, SEATNUM));
break;
case 'b':
show_empty_seats(plane, SEATNUM);
break;
case 'c':
show_seats(plane, SEATNUM);
break;
case 'd':
assign_customer_to_seat_and_save(plane, SEATNUM, fp);
break;
case 'e':
delete_seat_assignment(plane, SEATNUM, fp);
case 'f':
default:
break;
}
}
puts("Bye.");
fclose(fp);
return 0;
}
char show_menu(void) {
char choice;
puts("-----------------------------------------------");
puts("To choose a function, enter its letter label:");
puts("a) Show number of empty seats");
puts("b) Show list of empty seats");
puts("c) Show alphabetical list of empty seats");
puts("d) Assign a customer to a seat assignment");
puts("e) Delete a seat assignment");
puts("f) Quit");
choice = getchar();
eat_line();
while (strchr("abcdef", choice) == NULL) {
puts("Enter a, b, c, d, e or f:");
choice = getchar();
eat_line();
}
return choice;
}
void eat_line()
{
while (getchar() != '\n')
continue;
}
int get_empty_seat_number(struct seat seats[], int n)
{
int num = 0;
int i;
for (i = 0; i < n; i++) {
if (seats[i].assigned == 0)
num++;
}
return num;
}
void init_seats(struct seat seats[], int n)
{
int i;
for (i = 0; i < n; i++) {
seats[i].id = i;
seats[i].assigned = 0;
}
}
void show_empty_seats(struct seat seats[], int n)
{
int i;
puts("Empty seats: ");
for (i = 0; i < n; i++) {
if (seats[i].assigned == 0) {
printf("%d ", seats[i].id);
}
}
putchar('\n');
}
int assign_customer_to_seat_and_save(struct seat seats[], int n, FILE* fp)
{
struct name customer_name;
int i;
puts("Enter custom name:");
scanf("%s %s", customer_name.first, customer_name.last);
eat_line();
for (i = 0; i < n; i++) {
if (seats[i].assigned == 0) {
seats[i].customer = customer_name;
seats[i].assigned = 1;
printf("Seat %d assigned to %s %s\n", seats[i].id, customer_name.first, customer_name.last);
fseek(fp, i * sizeof(struct seat) * 1L, SEEK_SET);
fwrite(&(seats[i]), sizeof(struct seat), 1, fp);
return 1;
}
}
puts("Sorry, seats are full.");
return 0;
}
void show_seats(struct seat seats[], int n)
{
int i;
for (i = 0; i < n; i++) {
if (seats[i].assigned == 1) {
printf("Seat %d, Customer: %s %s\n", seats[i].id, seats[i].customer.first, seats[i].customer.last);
}
}
putchar('\n');
}
int delete_seat_assignment(struct seat seats[], int n, FILE* fp)
{
int seat_id;
puts("Which seat do you want to delete assignment");
scanf("%d", &seat_id);
eat_line();
if (seat_id < n) {
seats[seat_id].assigned = 0;
printf("Seat %d now is empty.\n", seat_id);
fseek(fp, seat_id * sizeof(struct seat) * 1L, SEEK_SET);
fwrite(&(seats[seat_id]), sizeof(struct seat), 1, fp);
return 1;
} else {
printf("Invalid seat id: %d", seat_id);
return 0;
}
}
void save_seats(struct seat seats[], int n, FILE* fp) {
fclose(fp);
fp = fopen("plane.dat", "w+b");
if (fp == NULL) {
fprintf(stderr, "Cannot open file with w+b\n");
}
fwrite(seats, sizeof(struct seat), n, fp);
} |
the_stack_data/82130.c | /*
At Kenjeran Crossroad there is a traffic light with below specifications:
Red light will be turned on for 20s
Yellow light for 5s, after red light
Green light for 60s, after yellow light
You are at the street, with M cars to your front and N cars behind you.
To fill time, you create a program that can tell you whether or not you're able to pass the traffic light
and how many cars are left at the road after T seconds.
For every 5s in green light, one car is able to pass the traffic light.
* Input Format :
There are three integers M, N, and T, as explained in the problem statement.
* Constraints :
1 <= M, N, T <= 100
* Output Format :
Display "YES!" if you are able to pass the traffic light, "NO!" otherwise.
Display the number of cars left behind on the same line. If all cars pass the traffic light, display 0 instead.
Sample Input 0
45 12 200
Sample Output 0
NO! 33
Sample Input 1
45 48 630
Sample Output 1
YES! 8
Sample Input 2
12 12 200
Sample Output 2
YES! 0
*/
#include <stdio.h>
int main()
{
int mobildepan, mobilbelakang, t;
scanf("%d %d %d", &mobildepan, &mobilbelakang, &t);
int totalMobil = mobildepan + 1 + mobilbelakang;
int totalWaktu = 85;
int bagi = t/totalWaktu;
int sisaWaktu = t%totalWaktu;
int mobil = bagi * 12;
if(sisaWaktu>=25)
{
mobil = mobil + ((sisaWaktu-25)/5);
}
if(mobil>=mobildepan+1)
{
printf("YES! ");
if(mobil>totalMobil)
{
printf("0");
}
else
{
printf("%d", totalMobil - mobil);
}
}
else
{
printf("NO! ");
if(mobil>totalMobil)
{
printf("0");
}
else
{
printf("%d", totalMobil - mobil);
}
}
}
|
the_stack_data/51700877.c | int main(){
printf("hello,world");
return 0;
}
|
the_stack_data/122016132.c | #include<stdio.h>
int main()
{
int bt[20],p[20],wt[20],tat[20],pr[20],i,j,pos,n;
float total=0,temp,avg_wt,avg_tat;
printf("Enter Total Number of Process:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter Process No.,Burst Time and Priority\n");
scanf("%d",&p[i]);
scanf("%d",&bt[i]);
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
{
pos=i;
for(j=i+1;j<n;j++)
{
if(pr[j]<pr[pos])
pos=j;
}
temp=pr[i];
pr[i]=pr[pos];
pr[pos]=temp;
temp=bt[i];
bt[i]=bt[pos];
bt[pos]=temp;
temp=p[i];
p[i]=p[pos];
p[pos]=temp;
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=0;
for(j=0;j<i;j++)
wt[i]+=bt[j];
total+=wt[i];
}
avg_wt=total/n;
total=0;
printf("\nProcess\t Burst Time \tPriority \tWaiting Time\tTurnaround Time");
for(i=0;i<n;i++)
{
tat[i]=bt[i]+wt[i];
total+=tat[i];
printf("\n%d\t\t %d\t\t%d\t\t%d\t\t\t%d",p[i],bt[i],pr[i],wt[i],tat[i]);
}
avg_tat=total/n;
printf("\n\nAverage Waiting Time=%f",avg_wt);
printf("\nAverage Turnaround Time=%f\n",avg_tat);
return 0;
}
|
the_stack_data/115765510.c | /* Code from Head First C.
Modified by Allen Downey.
*/
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
int listener_d = 0;
/* Print an error message and exit.
*/
void error(char *msg) {
fprintf(stderr, "%s: %s\n", msg, strerror(errno));
exit(1);
}
/* Set up the signal catcher.
*/
int catch_signal(int sig, void (*handler)(int)) {
struct sigaction action;
action.sa_handler = handler;
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
return sigaction(sig, &action, NULL);
}
/* Signal handler for SHUTDOWN
*/
void handle_shutdown(int sig) {
if (listener_d)
close(listener_d);
fprintf(stderr, "Bye!\n");
exit(EXIT_SUCCESS);
}
/* Create the listener socket.
*/
int open_listener_socket(void) {
int s = socket(PF_INET, SOCK_STREAM, 0);
if (s == -1)
error("Can't open listener socket");
return s;
}
/* Wait for clients to connect.
*/
int open_client_socket(void) {
static struct sockaddr_storage client_address;
static unsigned int address_size = sizeof(client_address);
int s;
if ((s = accept(listener_d, (struct sockaddr *)&client_address,
&address_size)) == -1)
error("Can't open client socket");
return s;
}
/* Bind the socket to a port.
*/
void bind_to_port(int socket, int port) {
struct sockaddr_in name;
name.sin_family = PF_INET;
name.sin_port = (in_port_t)htons(port);
name.sin_addr.s_addr = htonl(INADDR_ANY);
int reuse = 1;
int res = setsockopt(socket, SOL_SOCKET, SO_REUSEADDR,
(char *)&reuse, sizeof(int));
if (res == -1)
error("Can't set the 'reuse' option on the socket");
res = bind(socket, (struct sockaddr *)&name, sizeof(name));
if (res == -1)
error("Can't bind to socket");
}
/* Send to the client.
*/
int say(int socket, char *s)
{
int res = send(socket, s, strlen(s), 0);
if (res == -1)
error("Error talking to the client");
return res;
}
/* Read from the client.
Returns: number of characters read.
*/
int read_in(int socket, char *buf, int len)
{
/* treat the socket stream as a regular IO stream,
so we can do character IO */
FILE *fp = fdopen(socket, "r");
int i = 0, ch;
/* eat any leading whitespace */
while (isspace(ch = fgetc(fp)) && ch != EOF) {
// do nothing
}
if (ferror(fp))
error("fgetc");
while (ch != '\n' && ch != EOF) {
if (i < len)
buf[i++] = ch;
ch = fgetc(fp);
}
if (ferror(fp))
error("fgetc");
/* terminate the string, eating any trailing whitespace */
while (isspace(buf[--i])) {
buf[i] = '\0';
}
return strlen(buf);
}
char intro_msg[] = "Internet Knock-Knock Protocol Server\nKnock, knock.\n";
int main(int argc, char *argv[])
{
char buf[255];
// set up the signal handler
if (catch_signal(SIGINT, handle_shutdown) == -1)
error("Setting interrupt handler");
// create the listening socket
int port = 30000;
listener_d = open_listener_socket();
bind_to_port(listener_d, port);
if (listen(listener_d, 10) == -1)
error("Can't listen");
while (1) {
printf("Waiting for connection on port %d\n", port);
int connect_d = open_client_socket();
if (say(connect_d, intro_msg) == -1) {
close(connect_d);
continue;
}
if (!fork()) {
close(listener_d);
read_in(connect_d, buf, sizeof(buf));
// TODO (optional): check to make sure they said "Who's there?"
if (say(connect_d, "Surrealist giraffe.\n") == -1) {
close(connect_d);
continue;
}
read_in(connect_d, buf, sizeof(buf));
// TODO (optional): check to make sure they said "Surrealist giraffe who?"
if (say(connect_d, "Bathtub full of brightly-colored machine tools.\n") == -1) {
close(connect_d);
continue;
}
}
close(connect_d);
exit(0);
}
return 0;
}
|
the_stack_data/48573956.c | /*@ begin PerfTuning (
def build
{
arg build_command = 'gcc -O3 -fopenmp -DDYNAMIC';
arg libs = '-lm -lrt';
}
def performance_counter
{
arg repetitions = 35;
}
def performance_params
{
# Cache tiling
param T1_I[] = [1,16,32,64,128,256,512];
param T1_J[] = [1,16,32,64,128,256,512];
param T2_I[] = [1,64,128,256,512,1024,2048];
param T2_J[] = [1,64,128,256,512,1024,2048];
# Array copy
# Unroll-jam
param U1_I[] = range(1,31);
param U_I[] = range(1,31);
param U_J[] = range(1,31);
# Register tiling
param RT_I[] = [1,8,32];
param RT_J[] = [1,8,32];
# Scalar replacement
# Vectorization
# Parallelization
# Constraints
constraint tileI = ((T2_I == 1) or (T2_I % T1_I == 0));
constraint tileJ = ((T2_J == 1) or (T2_J % T1_J == 0));
constraint reg_capacity = (RT_I*RT_J <= 150);
constraint unroll_limit = ((U_I == 1) or (U_J == 1));
}
def search
{
arg algorithm = 'Randomsearch';
arg total_runs = 300;
}
def input_params
{
param N[] = [10000];
}
def input_vars
{
arg decl_file = 'decl.h';
arg init_file = 'init.c';
}
def validation {
arg validation_file = 'validation.c';
}
) @*/
#define max(x,y) ((x) > (y)? (x) : (y))
#define min(x,y) ((x) < (y)? (x) : (y))
int i,j, k;
int it, jt, kt;
int ii, jj, kk;
int iii, jjj, kkk;
/*@ begin Loop(
transform Composite(
unrolljam = (['i'],[U1_I])
)
for (i = 0; i <= ny-1; i++)
s[i] = 0;
transform Composite(
tile = [('i',T1_I,'ii'),('j',T1_J,'jj'),
(('ii','i'),T2_I,'iii'),(('jj','j'),T2_J,'jjj')],
unrolljam = (['i','j'],[U_I,U_J]),
regtile = (['i','j'],[RT_I,RT_J])
)
for (i = 0; i <= nx-1; i++) {
q[i] = 0;
for (j = 0; j <= ny-1; j++) {
s[j] = s[j] + r[i]*A[i*ny+j];
q[i] = q[i] + A[i*ny+j]*p[j];
}
}
) @*/
/*@ end @*/
/*@ end @*/
|
the_stack_data/107953149.c | /*When the sum of the cube of the individual digits of a number
is equal to that number, the number is called Armstrong number. For example 153.
Sum of its divisor is 13 + 53;+ 33; = 1+125+27 = 153*/
#include <stdio.h>
#include<math.h>
void main(){
int num,r,sum,temp;
int sno,eno;
printf("Input starting number of range: ");
scanf("%d",&sno);
printf("Input ending number of range : ");
scanf("%d",&eno);
printf("Armstrong numbers in given range are: ");
for(num=sno;num<=eno;num++){
temp=num;
sum = 0;
while(temp!=0){
r=temp % 10;
temp/=10;
sum=sum + pow(r,3);
}
if(sum==num)
printf("%d ",num);
}
printf("\n");
}
|
the_stack_data/62476.c | /***********************************************/
/* */
/* If demo #3 */
/* */
/***********************************************/
#include <stdio.h>
/***********************************************/
main ()
{ int persnum,usernum,balance;
persnum = 7462;
balance = -12;
printf ("The Plastic Bank Corporation\n");
printf ("Please enter your personal number :");
usernum = getnumber();
if (usernum == 7462)
{
printf ("\nThe current state of your account\n");
printf ("is %d\n",balance);
if (balance < 0)
{
printf ("The account is overdrawn!\n");
}
}
else
{
printf ("This is not your account\n");
}
printf ("Have a splendid day! Thank you.\n");
}
/**************************************************/
getnumber () /* get a number from the user */
{ int num = 0;
scanf ("%d",&num);
if ((num > 9999) || (num <= 0))
{
printf ("That is not a valid number\n");
}
return (num);
}
|
the_stack_data/45330.c | /*
Simple bitwise operation calculator
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct OpMap {
char is_and[3], is_or[2], is_sleft[5], is_sright[6];
};
int main(int argc, char* argv[]){
// force correct positional args
if (argc != 3){
puts("Enter provide an operation argument");
puts("and a numerical value.");
puts("Accepted operation args: and or sleft sright.");
exit(1);
}
int value = atoi(argv[2]);
int length = strlen(argv[1]);
char *op = (char*) malloc(length*sizeof(char));
struct OpMap op_map = {"and", "or", "sleft", "sright"};
// save op choice and parrot input
strcpy(op, argv[1]);
printf("You entered '%s'\n", op);
// print results
if (strcmp(op, op_map.is_and) <= 0){
puts("Computed symbol &");
for (int i = 0; i < 10; ++i){
printf("%d & %d = %d\n", i, value, i & value);
}
} else if (strcmp(op, op_map.is_or) <= 0){
puts("Computed symbol |");
for (int i = 0; i < 10; ++i){
printf("%d | %d = %d\n", i, value, i | value);
}
} else if (strcmp(op, op_map.is_sleft) <= 0){
puts("Computed symbol <<");
for (int i = 0; i < 10; ++i){
printf("%d << %d = %d\n", i, value, i << value);
}
} else if (strcmp(op, op_map.is_sright) <= 0){
puts("Computed symbol >>");
for (int i = 0; i < 10; ++i){
printf("%d >> %d = %d\n", i, value, i >> value);
}
}
// tidy up
free(op);
return 0;
}
|
the_stack_data/115764698.c | // Test array references
int main()
{
int a[] = {1, 2, 3, 4};
return a[2];
}
|
the_stack_data/50136758.c | #include <stdio.h>
// Programm "Messwertumrechnung"
int main() {
int messwert;
float prozWert;
printf("Simulation des Messwerts. Bitte Wert eingeben: ");
scanf_s("%i", &messwert);
// Berechnung und Ausgabe des Werts skaliert auf den Bereich 0..100 %
prozWert = messwert * 100 / 1023;
/*
Achtung: Die Reihenfolge der Berechnungsschritte ist hier
entscheidend. Wuerde man
prozWert = messwert / 1023 * 100;
berechnen, waere das Ergebnis 0 fuer alle Werte ausser
den messwert 1023, da zunaechst der int-Wert durch
1023 dividiert wird und das Ergebnis auf einen ganzzahligen
Wert gerundet wird.
*/
printf("Der Messwert %i entspricht %.1f %%\n", messwert, prozWert);
} |
the_stack_data/153445.c |
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
//dir1 dir2 filename diffTool
//it will see if filename is under dir1 or dir2, and then find its counterpart, and then launch "diffTool filename counterpart"
//dir1 and dir2 must not contain space (which makes enclosing double quotes necessary, double quotes makes matching string more troublesome)
#define commandpromptmaxstrlen_win2k 2047
static char fnmbuf[commandpromptmaxstrlen_win2k];
int main(int argc, char **argv) {
if(argc!=5)return 1;
fnmbuf[0]='"';fnmbuf[1]='"';
strcpy(fnmbuf+2,argv[4]);
strcat(fnmbuf, "\" ");
strcat(fnmbuf, argv[3]);
strcat(fnmbuf, " ");
size_t i=0;
for(;argv[1][i]!=0;i++)
argv[1][i]=tolower((unsigned char)argv[1][i]);
size_t si0=i;
i=0;
for(;argv[2][i]!=0;i++)
argv[2][i]=tolower((unsigned char)argv[2][i]);
size_t si1=i;
i=0;
for(;argv[3][i]!=0;i++)
argv[3][i]=tolower((unsigned char)argv[3][i]);
if(si0<i && memcmp(argv[1],argv[3],si0)==0){
strcat(fnmbuf,argv[2]);
strcat(fnmbuf,argv[3]+si0);
strcat(fnmbuf,"\"");
system(fnmbuf);
return 0;
}else if(si1<i && memcmp(argv[2],argv[3],si1)==0){
strcat(fnmbuf,argv[1]);
strcat(fnmbuf,argv[3]+si1);
strcat(fnmbuf,"\"");
system(fnmbuf);
return 0;
}
return 1;
}
|
the_stack_data/54825724.c | #include<stdio.h>
int main()
{
int num1,num2,temp;
printf("enter two variable to sawp : ");
scanf("%d %d",&num1,&num2);
temp=num1;
num1=num2;
num2=temp;
printf("%d %d",num1,num2);
}
|
the_stack_data/193892470.c | #include<stdio.h>
#include<stdlib.h>
#include<limits.h>
void largestThreeNo(int arr[], int n)
{
int i;
int first,second,third;
first = second = third = INT_MIN;
for(i = 0;i < n;i++)
{
if(arr[i] > first)
{
third = second;
second = first;
first = arr[i];
}
else if(arr[i] > second)
{
printf("\n The value of i is: %d",i);
third = second;
second = arr[i];
}
else if(arr[i] > third)
{
third = arr[i];
}
}
printf("\n The Largest Elements Are: %d %d %d",first,second,third);
}
int main()
{
int arr[] = {43,10,32,21,65,78};
int n = sizeof(arr)/sizeof(arr[0]);
largestThreeNo(arr,n);
return 0;
}
|
the_stack_data/70450753.c | #include <math.h>
#include <stdio.h>
/* First algorithm for the largest common denominator. */
void lcd1(int a, int b)
{
int x;
do
{
/* Set x to the absolute value of a - b. */
x = abs(a - b);
/* Replace the largest value with x. */
if (a > b)
a = x;
else
b = x;
} while ((a != 0) && (b != 0)); /* Do this as long no value is 0. */
printf("%d\n", a != 0 ? a : b);
}
/* Second algorithm for the largest common denominator. */
void lcd2(int a, int b)
{
int x;
do
{
/* Set x to the modulus of a and b. */
x = a % b;
/* Set a to b. */
a = b;
/* Set b to x. */
b = x;
} while (b == 0); /* Continue as long b is 0. */
printf("%d\n", x);
}
/* Third algorithm for the largest common denominator. */
void lcd3(int a, int b)
{
int x;
do
{
/* This is the same as x = a % b. */
x = (a - (a / b) * b);
a = b;
b = x;
} while (b == 0); /* Continue as long b is 0. */
printf("%d\n", x);
}
int main()
{
lcd1(30, 25);
lcd2(30, 25);
lcd3(30, 25);
return 0;
}
|
the_stack_data/57950254.c | #include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <sys/stat.h>
#define ERR_EXIT(m) \
do\
{\
perror(m);\
exit(EXIT_FAILURE);\
}\
while (0);\
void creat_daemon(void);
int main(void)
{
time_t t;
int fd;
creat_daemon();
while(1){
fd = open("daemon.log",O_WRONLY|O_CREAT|O_APPEND,0644);
if(fd == -1)
ERR_EXIT("open error");
t = time(0);
char *buf = asctime(localtime(&t));
write(fd,buf,strlen(buf));
close(fd);
sleep(60);
}
return 0;
}
void creat_daemon(void)
{
pid_t pid;
pid = fork();
if( pid == -1)
ERR_EXIT("fork error");
if(pid > 0 )
exit(EXIT_SUCCESS);
if(setsid() == -1)
ERR_EXIT("SETSID ERROR");
chdir("/");
int i;
for( i = 0; i < 3; ++i)
{
close(i);
open("/dev/null", O_RDWR);
dup(0);
dup(0);
}
umask(0);
return;
}
|
the_stack_data/881699.c | #include <stddef.h>
int mx_strcmp(const char *s1, const char *s2);
int mx_linear_search(char **arr, const char *s) {
for (int i = 0; arr[i] != NULL; ++i) {
if (mx_strcmp(arr[i], s) == 0) {
return i;
}
}
return -1;
} |
the_stack_data/6388812.c | #include <stdio.h>
#include <locale.h>
#include <uchar.h>
enum { buf_max = 512, };
typedef struct fileState {
FILE * reader;
int complete;
} fileState;
fileState readOne(fileState inp, char * b){
fileState endState = {inp.reader, 0};
if (fgets(b,2000,inp.reader)==NULL){
endState.complete = 1;
}
return endState;
}
int main(){
char buffer[buf_max] = {0};
char *b = buffer;
fileState inits= {stdin, 0};
while (readOne(inits, b).complete == 0){
printf("%s", b);
}
}
|
the_stack_data/52445.c | #include <stdio.h>
#include <string.h>
typedef struct
{
int codigo;
char nome[21];
float salario;
}func;
void exibetab(func tab[], int linhatab)
{
for (int i = 0; i < linhatab; i++)
{
printf("{%d, %s, %.2f},\n", tab[i].codigo, tab[i].nome, tab[i].salario);
}
}
int func_codigo(func tab[], int nlinha)
{
return (tab[nlinha].codigo > tab[nlinha+1].codigo);
}
int func_nome(func tab[], int nlinha)
{
if (strcmp(tab[nlinha].nome, tab[nlinha+1].nome) == 1)
{
return 1;
}
return 0;
}
int func_salario(func tab[], int nlinha)
{
return (tab[nlinha].salario > tab[nlinha+1].salario);
}
void ordena(int (*function)(func tab[], int nlinha), func tab[], int linhatab)
{
func aux[1];
for (int i = 1; i <= linhatab-1; i++)
{
for (int j = 0; j < linhatab-i; j++)
{
if (function(tab, j))
{
aux[0] = tab[j];
tab[j] = tab[j+1];
tab[j+1] = aux[0];
}
}
}
}
int main()
{
func v[] ={ {561, "Eva Maranhao", 9200.00},
{295, "Ana Teixeira", 6100.00},
{473, "Denise Lagoa", 8500.00},
{102, "Catia Telles", 7300.00},
{384, "Beatriz Lira", 5400.00}};
printf("Ordenar por\n1-Codigo\n2-Nome\n3-Salario\n\n");
switch(getchar())
{
case '1':
ordena(func_codigo, v, 5);
break;
case '2':
ordena(func_nome, v, 5);
break;
case '3':
ordena(func_salario, v, 5);
break;
}
printf("Tabela ordenada\n");
exibetab(v, 5);
return 0;
}
|
the_stack_data/75303.c | #include <stdio.h>
void helloc(void);
void helloc(void) {
printf("C: Hello, world!\n");
} |
the_stack_data/179831246.c | //
// main.c
// Exercise 1-11
//
// Created by Yilun Yang on 6/6/20.
// Copyright © 2020 Yilun Yang. All rights reserved.
//
#include <stdio.h>
int main(int argc, const char * argv[]) {
// insert code here...
printf("Hello, World!\n");
return 0;
}
|
the_stack_data/218894117.c | /*
* eui64.c - EUI64 routines for IPv6CP.
*
* Copyright (c) 1999 Tommi Komulainen. 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. The name(s) of the authors of this software must not be used to
* endorse or promote products derived from this software without
* prior written permission.
*
* 4. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by Tommi Komulainen
* <[email protected]>".
*
* THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS, IN NO EVENT SHALL THE AUTHORS 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.
*
* $Id: eui64.c,v 1.6 2002/12/04 23:03:32 paulus Exp $
*/
#ifdef LIBOHIBOARD_ETHERNET_LWIP_2_0_3
#include "netif/ppp/ppp_opts.h"
#if PPP_SUPPORT && PPP_IPV6_SUPPORT /* don't build if not configured for use in lwipopts.h */
#include "netif/ppp/ppp_impl.h"
#include "netif/ppp/eui64.h"
/*
* eui64_ntoa - Make an ascii representation of an interface identifier
*/
char *eui64_ntoa(eui64_t e) {
static char buf[20];
sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x",
e.e8[0], e.e8[1], e.e8[2], e.e8[3],
e.e8[4], e.e8[5], e.e8[6], e.e8[7]);
return buf;
}
#endif /* PPP_SUPPORT && PPP_IPV6_SUPPORT */
#endif /* LIBOHIBOARD_ETHERNET_LWIP_2_0_3 */
|
the_stack_data/1045812.c | /*
* @@name: target_data.1c
* @@type: C
* @@compilable: yes
* @@linkable: no
* @@expect: success
* @@version: omp_4.0
*/
extern void init(float*, float*, int);
extern void output(float*, int);
void vec_mult(float *p, float *v1, float *v2, int N)
{
int i;
init(v1, v2, N);
#pragma omp target data map(to: v1[0:N], v2[:N]) map(from: p[0:N])
{
#pragma omp target
#pragma omp parallel for
for (i=0; i<N; i++)
p[i] = v1[i] * v2[i];
}
output(p, N);
}
|
the_stack_data/95645.c | /*
* Copyright (c) 2017, The OpenThread Authors.
* 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 copyright holder 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 COPYRIGHT HOLDER 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.
*/
/**
* @file
* This file implements gcc-specific startup code for the efr32.
*/
__extension__ typedef int __guard __attribute__((mode(__DI__)));
int __cxa_guard_acquire(__guard *g) { return !*(char *)(g); }
void __cxa_guard_release(__guard *g) { *(char *)g = 1; }
void __cxa_guard_abort(__guard *g) { (void)g; }
void __cxa_pure_virtual(void) { while (1); }
|
the_stack_data/654577.c | /* Taxonomy Classification: 0000000000000063000300 */
/*
* WRITE/READ 0 write
* WHICH BOUND 0 upper
* DATA TYPE 0 char
* MEMORY LOCATION 0 stack
* SCOPE 0 same
* CONTAINER 0 no
* POINTER 0 no
* INDEX COMPLEXITY 0 constant
* ADDRESS COMPLEXITY 0 constant
* LENGTH COMPLEXITY 0 N/A
* ADDRESS ALIAS 0 none
* INDEX ALIAS 0 none
* LOCAL CONTROL FLOW 0 none
* SECONDARY CONTROL FLOW 0 none
* LOOP STRUCTURE 6 non-standard while
* LOOP COMPLEXITY 3 two
* ASYNCHRONY 0 no
* TAINT 0 no
* RUNTIME ENV. DEPENDENCE 0 no
* MAGNITUDE 3 4096 bytes
* CONTINUOUS/DISCRETE 0 discrete
* SIGNEDNESS 0 no
*/
/*
Copyright 2005 Massachusetts Institute of Technology
All rights reserved.
Redistribution and use of software 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 set of conditions and the disclaimer below.
- Redistributions in binary form must reproduce the copyright notice, this
set of conditions, and the disclaimer below in the documentation and/or
other materials provided with the distribution.
- Neither the name of the Massachusetts Institute of Technology 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".
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 COPYRIGHT OWNER 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.
*/
int main(int argc, char *argv[])
{
int init_value;
int test_value;
int loop_counter;
char buf[10];
init_value = 0;
test_value = 4105;
loop_counter = init_value;
while((++loop_counter) && (loop_counter <= test_value))
{
/* BAD */
buf[4105] = 'A';
}
return 0;
}
|
the_stack_data/161080207.c | #include <stdio.h>
int F(int x) {
if (x == 1)
return 1;
if (x % 2 == 0)
return F(x / 2);
return F(x - 1) + F(x + 1);
}
int main(void) {
int n;
scanf("%d", &n);
printf("%d\n", F(n));
return 0;
} |
the_stack_data/220455064.c | #include <stdio.h>
int main() {
return fflush(NULL);
}
|
the_stack_data/68888341.c | #define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
typedef char VARTYPE;
typedef struct node {
VARTYPE data;
struct node* next; // pointer to the next node
} Queue_Node;
typedef struct queue_ptr { // queue pointer
Queue_Node* head; // head pointer of the queue
Queue_Node* tail; // tail pointer of the queue
} Queue_Eigen; // name forked from linear algebra
// declare before definition
int isDigit(VARTYPE x);
int isEmptyQueue(Queue_Eigen* q);
int Queue_Size(Queue_Eigen* q);
int initQue(Queue_Eigen* q);
int enQue(Queue_Eigen* q, VARTYPE obj);
VARTYPE* deQue(Queue_Eigen* q);
int main() {
Queue_Eigen que; // declare a new queue
initQue(&que); // initialize the queue
VARTYPE ch; // declare a char for input temp
while (~scanf("%c", &ch)) { // the inverse of -1 is 0
if (isDigit(ch)) {
enQue(&que, ch); // if it is number, enqueue it
}
}
VARTYPE* chp; // a char* to receive pointer from function deQue()
while (!isEmptyQueue(&que)) { // if the queue is not empty
chp = deQue(&que); // pop out the first real node
printf("%c", *chp);
free(chp); // release the temporary space
}
}
int isDigit(VARTYPE x) {
return x >= '0' && x <= '9';
}
int isEmptyQueue(Queue_Eigen* q) {
return q->head == q->tail; // the queue is empty if both pointer point to the empty head node
}
int Queue_Size(Queue_Eigen* q) {
Queue_Node* ptr = q->head->next; // declare a new pointer following the head
int cnt = 0; // initialize the counter
while (ptr != NULL) { // while the pointer does not exceed the tail
cnt++; // add the counter
ptr = ptr->next; // move forward the counter
}
return cnt;
}
int initQue(Queue_Eigen* q) { // initialize the queue
q->head = (Queue_Node*)calloc(1, sizeof(Queue_Node));
// assign space for the reserved head node, which will remain empty and located to a fixed address.
q->tail = q->head; // point the tail to the head
q->tail->next = NULL; // There is only a element in the queue now.
return 0;
}
int enQue(Queue_Eigen* q, VARTYPE obj) { // Append a node to the rear end
Queue_Node* newnode = (Queue_Node*)calloc(1, sizeof(Queue_Node));
// assign space for a new node, for following data store
newnode->data = obj; // fill in data
newnode->next = NULL; // it will be the new tail of the queue
q->tail->next = newnode; // point the "next" pointer of the current tail to the new node
q->tail = newnode; // move forward the tail pointer
return 0;
}
VARTYPE* deQue(Queue_Eigen* q) { // remove the node following the reserved head and return it
if(isEmptyQueue(q)){
return NULL; // return nothing if the queue is empty
}
VARTYPE* Ans = (VARTYPE*)calloc(1, sizeof(VARTYPE));
// assign new space for the final answer
Queue_Node* targetnode = q->head->next; // declare a node* for temporary target node store
*Ans = targetnode->data; // duplicate the data, the address is not essential now
q->head->next = targetnode->next; // move forward pointer of the next of head, to the next node of the target
if (q->tail == targetnode) {
q->tail = q->head; // reset the tail if the target is the tail, the queue will be empty after pop
}
free(targetnode); // release the space occupied by the target node
return Ans; // return the data
}
|
the_stack_data/26701326.c | #include <stdio.h>
int smallest_multiple();
int main(void) {
printf("Result: %d\n", smallest_multiple());
return 0;
}
int smallest_multiple() {
int count = 20;
while (1) {
for (int i = 2; i <= 20; i++) {
if (count % i != 0) {
break;
}
if (i == 20) {
return count;
}
}
count++;
}
}
|
the_stack_data/165768362.c | /*-----------------------------------------------------------------------*/
/* Program: STREAM */
/* Revision: $Id: stream.c,v 1.3 2015-03-02 08:36:29 frmh84 Exp $ */
/* Original code developed by John D. McCalpin */
/* Programmers: John D. McCalpin */
/* Joe R. Zagar */
/* */
/* This program measures memory transfer rates in MB/s for simple */
/* computational kernels coded in C. */
/*-----------------------------------------------------------------------*/
/* Copyright 1991-2013: John D. McCalpin */
/*-----------------------------------------------------------------------*/
/* License: */
/* 1. You are free to use this program and/or to redistribute */
/* this program. */
/* 2. You are free to modify this program for your own use, */
/* including commercial use, subject to the publication */
/* restrictions in item 3. */
/* 3. You are free to publish results obtained from running this */
/* program, or from works that you derive from this program, */
/* with the following limitations: */
/* 3a. In order to be referred to as "STREAM benchmark results", */
/* published results must be in conformance to the STREAM */
/* Run Rules, (briefly reviewed below) published at */
/* http://www.cs.virginia.edu/stream/ref.html */
/* and incorporated herein by reference. */
/* As the copyright holder, John McCalpin retains the */
/* right to determine conformity with the Run Rules. */
/* 3b. Results based on modified source code or on runs not in */
/* accordance with the STREAM Run Rules must be clearly */
/* labelled whenever they are published. Examples of */
/* proper labelling include: */
/* "tuned STREAM benchmark results" */
/* "based on a variant of the STREAM benchmark code" */
/* Other comparable, clear, and reasonable labelling is */
/* acceptable. */
/* 3c. Submission of results to the STREAM benchmark web site */
/* is encouraged, but not required. */
/* 4. Use of this program or creation of derived works based on this */
/* program constitutes acceptance of these licensing restrictions. */
/* 5. Absolutely no warranty is expressed or implied. */
/*-----------------------------------------------------------------------*/
# include <stdio.h>
# include <unistd.h>
# include <math.h>
# include <float.h>
# include <limits.h>
# include <sys/time.h>
/*-----------------------------------------------------------------------
* INSTRUCTIONS:
*
* 1) STREAM requires different amounts of memory to run on different
* systems, depending on both the system cache size(s) and the
* granularity of the system timer.
* You should adjust the value of 'STREAM_ARRAY_SIZE' (below)
* to meet *both* of the following criteria:
* (a) Each array must be at least 4 times the size of the
* available cache memory. I don't worry about the difference
* between 10^6 and 2^20, so in practice the minimum array size
* is about 3.8 times the cache size.
* Example 1: One Xeon E3 with 8 MB L3 cache
* STREAM_ARRAY_SIZE should be >= 4 million, giving
* an array size of 30.5 MB and a total memory requirement
* of 91.5 MB.
* Example 2: Two Xeon E5's with 20 MB L3 cache each (using OpenMP)
* STREAM_ARRAY_SIZE should be >= 20 million, giving
* an array size of 153 MB and a total memory requirement
* of 458 MB.
* (b) The size should be large enough so that the 'timing calibration'
* output by the program is at least 20 clock-ticks.
* Example: most versions of Windows have a 10 millisecond timer
* granularity. 20 "ticks" at 10 ms/tic is 200 milliseconds.
* If the chip is capable of 10 GB/s, it moves 2 GB in 200 msec.
* This means the each array must be at least 1 GB, or 128M elements.
*
* Version 5.10 increases the default array size from 2 million
* elements to 10 million elements in response to the increasing
* size of L3 caches. The new default size is large enough for caches
* up to 20 MB.
* Version 5.10 changes the loop index variables from "register int"
* to "ssize_t", which allows array indices >2^32 (4 billion)
* on properly configured 64-bit systems. Additional compiler options
* (such as "-mcmodel=medium") may be required for large memory runs.
*
* Array size can be set at compile time without modifying the source
* code for the (many) compilers that support preprocessor definitions
* on the compile line. E.g.,
* gcc -O -DSTREAM_ARRAY_SIZE=100000000 stream.c -o stream.100M
* will override the default size of 10M with a new size of 100M elements
* per array.
*/
#ifndef STREAM_ARRAY_SIZE
// # define STREAM_ARRAY_SIZE 10000000
# define STREAM_ARRAY_SIZE 80000000
#endif
/* 2) STREAM runs each kernel "NTIMES" times and reports the *best* result
* for any iteration after the first, therefore the minimum value
* for NTIMES is 2.
* There are no rules on maximum allowable values for NTIMES, but
* values larger than the default are unlikely to noticeably
* increase the reported performance.
* NTIMES can also be set on the compile line without changing the source
* code using, for example, "-DNTIMES=7".
*/
#ifdef NTIMES
#if NTIMES<=1
# define NTIMES 10
#endif
#endif
#ifndef NTIMES
# define NTIMES 10
#endif
/* Users are allowed to modify the "OFFSET" variable, which *may* change the
* relative alignment of the arrays (though compilers may change the
* effective offset by making the arrays non-contiguous on some systems).
* Use of non-zero values for OFFSET can be especially helpful if the
* STREAM_ARRAY_SIZE is set to a value close to a large power of 2.
* OFFSET can also be set on the compile line without changing the source
* code using, for example, "-DOFFSET=56".
*/
#ifndef OFFSET
# define OFFSET 0
#endif
/*
* 3) Compile the code with optimization. Many compilers generate
* unreasonably bad code before the optimizer tightens things up.
* If the results are unreasonably good, on the other hand, the
* optimizer might be too smart for me!
*
* For a simple single-core version, try compiling with:
* cc -O stream.c -o stream
* This is known to work on many, many systems....
*
* To use multiple cores, you need to tell the compiler to obey the OpenMP
* directives in the code. This varies by compiler, but a common example is
* gcc -O -fopenmp stream.c -o stream_omp
* The environment variable OMP_NUM_THREADS allows runtime control of the
* number of threads/cores used when the resulting "stream_omp" program
* is executed.
*
* To run with single-precision variables and arithmetic, simply add
* -DSTREAM_TYPE=float
* to the compile line.
* Note that this changes the minimum array sizes required --- see (1) above.
*
* The preprocessor directive "TUNED" does not do much -- it simply causes the
* code to call separate functions to execute each kernel. Trivial versions
* of these functions are provided, but they are *not* tuned -- they just
* provide predefined interfaces to be replaced with tuned code.
*
*
* 4) Optional: Mail the results to [email protected]
* Be sure to include info that will help me understand:
* a) the computer hardware configuration (e.g., processor model, memory type)
* b) the compiler name/version and compilation flags
* c) any run-time information (such as OMP_NUM_THREADS)
* d) all of the output from the test case.
*
* Thanks!
*
*-----------------------------------------------------------------------*/
# define HLINE "-------------------------------------------------------------\n"
# ifndef MIN
# define MIN(x,y) ((x)<(y)?(x):(y))
# endif
# ifndef MAX
# define MAX(x,y) ((x)>(y)?(x):(y))
# endif
#ifndef STREAM_TYPE
#define STREAM_TYPE double
#endif
static STREAM_TYPE a[STREAM_ARRAY_SIZE+OFFSET],
b[STREAM_ARRAY_SIZE+OFFSET],
c[STREAM_ARRAY_SIZE+OFFSET];
static double avgtime[4] = {0}, maxtime[4] = {0},
mintime[4] = {FLT_MAX,FLT_MAX,FLT_MAX,FLT_MAX};
static char *label[4] = {"Copy: ", "Scale: ",
"Add: ", "Triad: "};
static double bytes[4] = {
2 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE,
2 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE,
3 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE,
3 * sizeof(STREAM_TYPE) * STREAM_ARRAY_SIZE
};
extern double mysecond();
extern void checkSTREAMresults();
#ifdef TUNED
extern void tuned_STREAM_Copy();
extern void tuned_STREAM_Scale(STREAM_TYPE scalar);
extern void tuned_STREAM_Add();
extern void tuned_STREAM_Triad(STREAM_TYPE scalar);
#endif
#ifdef _OPENMP
extern int omp_get_num_threads();
#endif
int
main()
{
int quantum, checktick();
int BytesPerWord;
int k;
ssize_t j;
STREAM_TYPE scalar;
double t, times[4][NTIMES];
/* --- SETUP --- determine precision and check timing --- */
printf(HLINE);
printf("STREAM version $Revision: 1.3 $\n");
printf(HLINE);
BytesPerWord = sizeof(STREAM_TYPE);
printf("This system uses %d bytes per array element.\n",
BytesPerWord);
printf(HLINE);
#ifdef N
printf("***** WARNING: ******\n");
printf(" It appears that you set the preprocessor variable N when compiling this code.\n");
printf(" This version of the code uses the preprocesor variable STREAM_ARRAY_SIZE to control the array size\n");
printf(" Reverting to default value of STREAM_ARRAY_SIZE=%llu\n",(unsigned long long) STREAM_ARRAY_SIZE);
printf("***** WARNING: ******\n");
#endif
printf("Array size = %llu (elements), Offset = %d (elements)\n" , (unsigned long long) STREAM_ARRAY_SIZE, OFFSET);
printf("Memory per array = %.1f MiB (= %.1f GiB).\n",
BytesPerWord * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.0),
BytesPerWord * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.0/1024.0));
printf("Total memory required = %.1f MiB (= %.1f GiB).\n",
(3.0 * BytesPerWord) * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024.),
(3.0 * BytesPerWord) * ( (double) STREAM_ARRAY_SIZE / 1024.0/1024./1024.));
printf("Each kernel will be executed %d times.\n", NTIMES);
printf(" The *best* time for each kernel (excluding the first iteration)\n");
printf(" will be used to compute the reported bandwidth.\n");
#ifdef _OPENMP
printf(HLINE);
#pragma omp parallel
{
#pragma omp master
{
k = omp_get_num_threads();
printf ("Number of Threads requested = %i\n",k);
}
}
#endif
#ifdef _OPENMP
k = 0;
#pragma omp parallel
#pragma omp atomic
k++;
printf ("Number of Threads counted = %i\n",k);
#endif
/* Get initial value for system clock. */
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++) {
a[j] = 1.0;
b[j] = 2.0;
c[j] = 0.0;
}
printf(HLINE);
if ( (quantum = checktick()) >= 1)
printf("Your clock granularity/precision appears to be "
"%d microseconds.\n", quantum);
else {
printf("Your clock granularity appears to be "
"less than one microsecond.\n");
quantum = 1;
}
t = mysecond();
#pragma omp parallel for
for (j = 0; j < STREAM_ARRAY_SIZE; j++)
a[j] = 2.0E0 * a[j];
t = 1.0E6 * (mysecond() - t);
printf("Each test below will take on the order"
" of %d microseconds.\n", (int) t );
printf(" (= %d clock ticks)\n", (int) (t/quantum) );
printf("Increase the size of the arrays if this shows that\n");
printf("you are not getting at least 20 clock ticks per test.\n");
printf(HLINE);
printf("WARNING -- The above is only a rough guideline.\n");
printf("For best results, please be sure you know the\n");
printf("precision of your system timer.\n");
printf(HLINE);
/* --- MAIN LOOP --- repeat test cases NTIMES times --- */
scalar = 3.0;
for (k=0; k<NTIMES; k++)
{
times[0][k] = mysecond();
#ifdef TUNED
tuned_STREAM_Copy();
#else
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
c[j] = a[j];
#endif
times[0][k] = mysecond() - times[0][k];
times[1][k] = mysecond();
#ifdef TUNED
tuned_STREAM_Scale(scalar);
#else
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
b[j] = scalar*c[j];
#endif
times[1][k] = mysecond() - times[1][k];
times[2][k] = mysecond();
#ifdef TUNED
tuned_STREAM_Add();
#else
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
c[j] = a[j]+b[j];
#endif
times[2][k] = mysecond() - times[2][k];
times[3][k] = mysecond();
#ifdef TUNED
tuned_STREAM_Triad(scalar);
#else
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
a[j] = b[j]+scalar*c[j];
#endif
times[3][k] = mysecond() - times[3][k];
}
/* --- SUMMARY --- */
for (k=1; k<NTIMES; k++) /* note -- skip first iteration */
{
for (j=0; j<4; j++)
{
avgtime[j] = avgtime[j] + times[j][k];
mintime[j] = MIN(mintime[j], times[j][k]);
maxtime[j] = MAX(maxtime[j], times[j][k]);
}
}
printf("Function Best Rate MB/s Avg time Min time Max time\n");
for (j=0; j<4; j++) {
avgtime[j] = avgtime[j]/(double)(NTIMES-1);
printf("%s%12.1f %11.6f %11.6f %11.6f\n", label[j],
1.0E-06 * bytes[j]/mintime[j],
avgtime[j],
mintime[j],
maxtime[j]);
}
printf(HLINE);
/* --- Check Results --- */
checkSTREAMresults();
printf(HLINE);
return 0;
}
# define M 20
int
checktick()
{
int i, minDelta, Delta;
double t1, t2, timesfound[M];
/* Collect a sequence of M unique time values from the system. */
for (i = 0; i < M; i++) {
t1 = mysecond();
while( ((t2=mysecond()) - t1) < 1.0E-6 )
;
timesfound[i] = t1 = t2;
}
/*
* Determine the minimum difference between these M values.
* This result will be our estimate (in microseconds) for the
* clock granularity.
*/
minDelta = 1000000;
for (i = 1; i < M; i++) {
Delta = (int)( 1.0E6 * (timesfound[i]-timesfound[i-1]));
minDelta = MIN(minDelta, MAX(Delta,0));
}
return(minDelta);
}
/* A gettimeofday routine to give access to the wall
clock timer on most UNIX-like systems. */
#include <sys/time.h>
double mysecond()
{
struct timeval tp;
struct timezone tzp;
int i;
i = gettimeofday(&tp,&tzp);
return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 );
}
#ifndef abs
#define abs(a) ((a) >= 0 ? (a) : -(a))
#endif
void checkSTREAMresults ()
{
STREAM_TYPE aj,bj,cj,scalar;
STREAM_TYPE aSumErr,bSumErr,cSumErr;
STREAM_TYPE aAvgErr,bAvgErr,cAvgErr;
double epsilon;
ssize_t j;
int k,ierr,err;
/* reproduce initialization */
aj = 1.0;
bj = 2.0;
cj = 0.0;
/* a[] is modified during timing check */
aj = 2.0E0 * aj;
/* now execute timing loop */
scalar = 3.0;
for (k=0; k<NTIMES; k++)
{
cj = aj;
bj = scalar*cj;
cj = aj+bj;
aj = bj+scalar*cj;
}
/* accumulate deltas between observed and expected results */
aSumErr = 0.0;
bSumErr = 0.0;
cSumErr = 0.0;
for (j=0; j<STREAM_ARRAY_SIZE; j++) {
aSumErr += abs(a[j] - aj);
bSumErr += abs(b[j] - bj);
cSumErr += abs(c[j] - cj);
// if (j == 417) printf("Index 417: c[j]: %f, cj: %f\n",c[j],cj); // MCCALPIN
}
aAvgErr = aSumErr / (STREAM_TYPE) STREAM_ARRAY_SIZE;
bAvgErr = bSumErr / (STREAM_TYPE) STREAM_ARRAY_SIZE;
cAvgErr = cSumErr / (STREAM_TYPE) STREAM_ARRAY_SIZE;
if (sizeof(STREAM_TYPE) == 4) {
epsilon = 1.e-6;
}
else if (sizeof(STREAM_TYPE) == 8) {
epsilon = 1.e-13;
}
else {
printf("WEIRD: sizeof(STREAM_TYPE) = %lu\n",sizeof(STREAM_TYPE));
epsilon = 1.e-6;
}
err = 0;
if (abs(aAvgErr/aj) > epsilon) {
err++;
printf ("Failed Validation on array a[], AvgRelAbsErr > epsilon (%e)\n",epsilon);
printf (" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n",aj,aAvgErr,abs(aAvgErr)/aj);
ierr = 0;
for (j=0; j<STREAM_ARRAY_SIZE; j++) {
if (abs(a[j]/aj-1.0) > epsilon) {
ierr++;
#ifdef VERBOSE
if (ierr < 10) {
printf(" array a: index: %ld, expected: %e, observed: %e, relative error: %e\n",
j,aj,a[j],abs((aj-a[j])/aAvgErr));
}
#endif
}
}
printf(" For array a[], %d errors were found.\n",ierr);
}
if (abs(bAvgErr/bj) > epsilon) {
err++;
printf ("Failed Validation on array b[], AvgRelAbsErr > epsilon (%e)\n",epsilon);
printf (" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n",bj,bAvgErr,abs(bAvgErr)/bj);
printf (" AvgRelAbsErr > Epsilon (%e)\n",epsilon);
ierr = 0;
for (j=0; j<STREAM_ARRAY_SIZE; j++) {
if (abs(b[j]/bj-1.0) > epsilon) {
ierr++;
#ifdef VERBOSE
if (ierr < 10) {
printf(" array b: index: %ld, expected: %e, observed: %e, relative error: %e\n",
j,bj,b[j],abs((bj-b[j])/bAvgErr));
}
#endif
}
}
printf(" For array b[], %d errors were found.\n",ierr);
}
if (abs(cAvgErr/cj) > epsilon) {
err++;
printf ("Failed Validation on array c[], AvgRelAbsErr > epsilon (%e)\n",epsilon);
printf (" Expected Value: %e, AvgAbsErr: %e, AvgRelAbsErr: %e\n",cj,cAvgErr,abs(cAvgErr)/cj);
printf (" AvgRelAbsErr > Epsilon (%e)\n",epsilon);
ierr = 0;
for (j=0; j<STREAM_ARRAY_SIZE; j++) {
if (abs(c[j]/cj-1.0) > epsilon) {
ierr++;
#ifdef VERBOSE
if (ierr < 10) {
printf(" array c: index: %ld, expected: %e, observed: %e, relative error: %e\n",
j,cj,c[j],abs((cj-c[j])/cAvgErr));
}
#endif
}
}
printf(" For array c[], %d errors were found.\n",ierr);
}
if (err == 0) {
printf ("Solution Validates: avg error less than %e on all three arrays\n",epsilon);
}
#ifdef VERBOSE
printf ("Results Validation Verbose Results: \n");
printf (" Expected a(1), b(1), c(1): %f %f %f \n",aj,bj,cj);
printf (" Observed a(1), b(1), c(1): %f %f %f \n",a[1],b[1],c[1]);
printf (" Rel Errors on a, b, c: %e %e %e \n",abs(aAvgErr/aj),abs(bAvgErr/bj),abs(cAvgErr/cj));
#endif
}
#ifdef TUNED
/* stubs for "tuned" versions of the kernels */
void tuned_STREAM_Copy()
{
ssize_t j;
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
c[j] = a[j];
}
void tuned_STREAM_Scale(STREAM_TYPE scalar)
{
ssize_t j;
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
b[j] = scalar*c[j];
}
void tuned_STREAM_Add()
{
ssize_t j;
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
c[j] = a[j]+b[j];
}
void tuned_STREAM_Triad(STREAM_TYPE scalar)
{
ssize_t j;
#pragma omp parallel for
for (j=0; j<STREAM_ARRAY_SIZE; j++)
a[j] = b[j]+scalar*c[j];
}
/* end of stubs for the "tuned" versions of the kernels */
#endif
|
the_stack_data/117328655.c | // shoot at other player (admonisher standard, 4x heavy ion beam, 2x pugilist, very short fire hold)
// peer0_0 = client > server
char peer0_0[] = {
0x00, 0x00, 0x00, 0x39, 0x01, 0x00, 0x00, 0x00 };
char peer0_1[] = {
0x14, 0x02, 0x01, 0xda, 0x79, 0x62, 0x11, 0x9e,
0x00, 0x00, 0x00, 0x29, 0x00, 0x00, 0x00, 0x00,
0xbd, 0xbc, 0x01, 0xda, 0xbb, 0x00, 0xbe, 0x00,
0x00, 0x00, 0x06, 0xbe, 0x00, 0x00, 0x00, 0x00,
0xbe, 0x00, 0x00, 0x00, 0x01, 0xbe, 0x00, 0x00,
0x00, 0x02, 0xbe, 0x00, 0x00, 0x00, 0x03, 0xbe,
0x00, 0x00, 0x00, 0x04, 0xbe, 0x00, 0x00, 0x00,
0x05 };
char peer1_0[] = {
0x00, 0x00, 0x00, 0x3c, 0x01, 0x00, 0xd6, 0x08 };
char peer1_1[] = {
0x14, 0x54, 0x01, 0xda, 0x79, 0x62, 0x11, 0xda,
0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x75, 0x63,
0x7b, 0x44, 0x2d, 0x00, 0x00, 0xbd, 0xbc, 0x00,
0x00, 0xbe, 0x00, 0x00, 0x00, 0x06, 0xbe, 0x00,
0x00, 0x00, 0x00, 0xbe, 0x00, 0x00, 0x00, 0x01,
0xbe, 0x00, 0x00, 0x00, 0x02, 0xbe, 0x00, 0x00,
0x00, 0x03, 0xbe, 0x00, 0x00, 0x00, 0x04, 0xbe,
0x00, 0x00, 0x00, 0x05 };
char peer0_2[] = {
0x00, 0x00, 0x00, 0x2f, 0x01, 0x00, 0x00, 0x00 };
char peer0_3[] = {
0x14, 0x02, 0x01, 0xda, 0x79, 0x62, 0x12, 0x00,
0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
0xbd, 0xbc, 0x01, 0xda, 0xbb, 0x00, 0xbe, 0x00,
0x00, 0x00, 0x04, 0xbe, 0x00, 0x00, 0x00, 0x00,
0xbe, 0x00, 0x00, 0x00, 0x01, 0xbe, 0x00, 0x00,
0x00, 0x02, 0xbe, 0x00, 0x00, 0x00, 0x03 };
char peer1_2[] = {
0x00, 0x00, 0x00, 0x32, 0x01, 0x00, 0xd6, 0x08 };
char peer1_3[] = {
0x14, 0x54, 0x01, 0xda, 0x79, 0x62, 0x12, 0x5f,
0x00, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00,
0x7b, 0x44, 0x2a, 0xf1, 0xb9, 0xbd, 0xbc, 0x00,
0x00, 0xbe, 0x00, 0x00, 0x00, 0x04, 0xbe, 0x00,
0x00, 0x00, 0x00, 0xbe, 0x00, 0x00, 0x00, 0x01,
0xbe, 0x00, 0x00, 0x00, 0x02, 0xbe, 0x00, 0x00,
0x00, 0x03 };
char peer0_4[] = {
0x00, 0x00, 0x00, 0x37, 0x01, 0x00, 0x00, 0x00 };
char peer0_5[] = {
0x15, 0x02, 0x01, 0xda, 0x79, 0x62, 0x13, 0xf1,
0x00, 0x00, 0x00, 0x27, 0x00, 0x00, 0x00, 0x00,
0xbd, 0xbc, 0x01, 0xda, 0xbe, 0x00, 0x00, 0x00,
0x06, 0xbe, 0x00, 0x00, 0x00, 0x00, 0xbe, 0x00,
0x00, 0x00, 0x01, 0xbe, 0x00, 0x00, 0x00, 0x02,
0xbe, 0x00, 0x00, 0x00, 0x03, 0xbe, 0x00, 0x00,
0x00, 0x04, 0xbe, 0x00, 0x00, 0x00, 0x05 };
char peer1_4[] = {
0x00, 0x00, 0x00, 0x33, 0x01, 0x00, 0xd6, 0x08 };
char peer1_5[] = {
0x15, 0x54, 0x01, 0xda, 0x79, 0x62, 0x14, 0x4d,
0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x75, 0x63,
0xbe, 0x00, 0x00, 0x00, 0x06, 0xbe, 0x00, 0x00,
0x00, 0x00, 0xbe, 0x00, 0x00, 0x00, 0x01, 0xbe,
0x00, 0x00, 0x00, 0x02, 0xbe, 0x00, 0x00, 0x00,
0x03, 0xbe, 0x00, 0x00, 0x00, 0x04, 0xbe, 0x00,
0x00, 0x00, 0x05 };
|
the_stack_data/764080.c | /*
** makeobj.c
**
**---------------------------------------------------------------------------
** Copyright 2014 Braden Obrzut
** 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. The name of the 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 AUTHOR ``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 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.
**---------------------------------------------------------------------------
**
** This is a throwaway program to create OMF object files for DOS. It also
** extracts the object files. It should be compatible with MakeOBJ by John
** Romero except where we calculate the checksum correctly.
**
*/
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#pragma pack(1)
typedef struct
{
unsigned char type;
unsigned short len;
} SegHeader;
typedef struct
{
unsigned short len;
unsigned char name;
unsigned char classname;
unsigned char overlayname;
} SegDef;
#pragma pack()
const char* ReadFile(const char* fn, int *size)
{
char* out;
FILE* f = fopen(fn, "rb");
fseek(f, 0, SEEK_END);
*size = ftell(f);
out = (char*)malloc(*size);
fseek(f, 0, SEEK_SET);
fread(out, *size, 1, f);
fclose(f);
return out;
}
void WriteFile(const char* fn, const char *data, int size)
{
FILE* f = fopen(fn, "wb");
fwrite(data, size, 1, f);
fclose(f);
}
void Extract(const char* infn)
{
const char* in;
const char* start;
const char* p;
char outfn[16];
char str[256];
char *outdata;
int outsize;
int insize;
SegHeader head;
outdata = NULL;
start = in = ReadFile(infn, &insize);
while(in < start + insize)
{
head = *(SegHeader*)in;
switch(head.type)
{
case 0x80: /* THEADR */
memcpy(outfn, in+4, in[3]);
outfn[in[3]] = 0;
printf("Output: %s\n", outfn);
{
int i;
for(i = 0;i < 16;++i)
{
if(outfn[i] == ' ')
outfn[i] = 0;
}
}
break;
case 0x88: /* COMENT */
switch(in[3])
{
case 0:
memcpy(str, in+5, head.len-2);
str[head.len-3] = 0;
printf("Comment: %s\n", str);
break;
default:
printf("Unknown comment type %X @ %x ignored.\n", (unsigned char)in[3], (unsigned int)(in - start));
break;
}
break;
case 0x96: /* LNAMES */
p = in+3;
while(p < in+head.len+2)
{
memcpy(str, p+1, (unsigned char)*p);
str[(unsigned char)*p] = 0;
printf("Name: %s\n", str);
p += (unsigned char)*p+1;
}
break;
case 0x98: /* SEGDEF */
{
SegDef *sd;
sd = *(in+3) ? (SegDef*)(in+4) : (SegDef*)(in+7);
printf("Segment Length: %d\n", sd->len);
outdata = (char*)malloc(sd->len);
outsize = sd->len;
break;
}
case 0x90: /* PUBDEF */
p = in+5;
if(in[5] == 0)
p += 2;
while(p < in+head.len+2)
{
memcpy(str, p+1, (unsigned char)*p);
str[(unsigned char)*p] = 0;
printf("Public Name: %s\n", str);
p += (unsigned char)*p+4;
}
break;
case 0xA0: /* LEDATA */
printf("Writing data at %d (%d)\n", *(unsigned short*)(in+4), head.len-4);
memcpy(outdata+*(unsigned short*)(in+4), in+6, head.len-4);
break;
case 0x8A: /* MODEND */
/* Ignore */
break;
default:
printf("Unknown header type %X @ %x ignored.\n", head.type, (unsigned int)(in - start));
break;
}
in += 3 + head.len;
}
WriteFile(outfn, outdata, outsize);
free((char*)start);
free(outdata);
}
void CheckSum(char *s, unsigned short len)
{
int sum;
len += 3;
sum = 0;
while(len > 1)
{
sum += *(unsigned char*)s;
++s;
--len;
}
*s = (unsigned char)(0x100-(sum&0xFF));
}
void MakeDataObj(const char* infn, const char* outfn, const char* segname, const char* symname, int altmode)
{
#define Flush() fwrite(d.buf, d.head.len+3, 1, f)
union
{
char buf[4096];
SegHeader head;
} d;
int i;
FILE *f;
int insize;
const char *in;
const char *infn_stripped = strrchr(infn, '/');
if(strrchr(infn, '\\') > infn_stripped)
infn_stripped = strrchr(infn, '\\');
if(infn_stripped == NULL)
infn_stripped = infn;
else
++infn_stripped;
f = fopen(outfn, "wb");
in = ReadFile(infn, &insize);
d.head.type = 0x80;
d.head.len = 14;
d.buf[3] = 12;
if(d.buf[3] > 12)
d.buf[3] = 12;
sprintf(&d.buf[4], "%-12s", infn_stripped);
for(i = 0;i < strlen(infn_stripped) && i < 12;++i)
d.buf[4+i] = toupper(d.buf[4+i]);
/* CheckSum(d.buf, d.head.len); */
d.buf[17] = 0; /* For some reason this one isn't checksummed by MakeOBJ */
Flush();
d.head.type = 0x88;
d.head.len = 15;
d.buf[3] = 0;
d.buf[4] = 0;
/* We're not really MakeOBJ v1.1, but to allow us to verify with md5sums */
memcpy(&d.buf[5], "MakeOBJ v1.1", 12);
CheckSum(d.buf, d.head.len);
Flush();
d.head.type = 0x96;
d.head.len = strlen(infn_stripped)+40;
d.buf[3] = 6;
memcpy(&d.buf[4], "DGROUP", 6);
d.buf[10] = 5;
memcpy(&d.buf[11], "_DATA", 5);
d.buf[16] = 4;
memcpy(&d.buf[17], "DATA", 4);
d.buf[21] = 0;
d.buf[22] = 5;
memcpy(&d.buf[23], "_TEXT", 5);
d.buf[28] = 4;
memcpy(&d.buf[29], "CODE", 4);
d.buf[33] = 8;
memcpy(&d.buf[34], "FAR_DATA", 8);
if(!segname)
{
if(!altmode)
{
d.buf[42] = strlen(infn_stripped)-1;
for(i = 0;i < strlen(infn_stripped)-4;++i)
{
if(i == 0)
d.buf[43] = toupper(infn_stripped[0]);
else
d.buf[43+i] = tolower(infn_stripped[i]);
}
memcpy(&d.buf[43+i], "Seg", 3);
}
else
{
d.head.len = 40;
}
}
else
{
d.head.len = strlen(segname)+41;
d.buf[42] = strlen(segname);
strcpy(&d.buf[43], segname);
}
CheckSum(d.buf, d.head.len);
Flush();
d.head.type = 0x98;
d.head.len = 7;
*(unsigned short*)(d.buf+4) = insize;
if(altmode == 0)
{
d.buf[3] = (char)((unsigned char)0x60);
d.buf[6] = 8;
d.buf[7] = 7;
d.buf[8] = 4;
}
else
{
d.buf[3] = (char)((unsigned char)0x48);
d.buf[6] = 2;
d.buf[7] = 3;
d.buf[8] = 4;
}
CheckSum(d.buf, d.head.len);
Flush();
if(altmode)
{
d.head.type = 0x9A;
d.head.len = 4;
d.buf[3] = 1;
d.buf[4] = (char)((unsigned char)0xFF);
d.buf[5] = 1;
CheckSum(d.buf, d.head.len);
Flush();
}
d.head.type = 0x90;
d.head.len = strlen(infn_stripped)+4;
d.buf[3] = 1;
d.buf[4] = 1;
if(!symname)
{
d.buf[5] = strlen(infn_stripped)-3;
d.buf[6] = '_';
for(i = 0;i < strlen(infn_stripped)-4;++i)
d.buf[7+i] = tolower(infn_stripped[i]);
}
else
{
d.head.len = strlen(symname)+7;
d.buf[5] = strlen(symname);
strcpy(&d.buf[6], symname);
i = strlen(symname)-1;
}
d.buf[7+i] = 0;
d.buf[8+i] = 0;
d.buf[9+i] = 0;
/* This checksum is calculated wrong in MakeOBJ, although I don't know in what way. */
CheckSum(d.buf, d.head.len);
Flush();
#define LEDATA_LEN 1024
for(i = 0;i < insize;i += LEDATA_LEN)
{
d.head.type = 0xA0;
d.head.len = insize - i > LEDATA_LEN ? LEDATA_LEN+4 : insize - i + 4;
d.buf[3] = 1;
*(unsigned short*)(d.buf+4) = i;
memcpy(&d.buf[6], &in[i], d.head.len-4);
CheckSum(d.buf, d.head.len);
Flush();
}
d.head.type = 0x8A;
d.head.len = 2;
d.buf[3] = 0;
d.buf[4] = 0;
CheckSum(d.buf, d.head.len);
Flush();
fclose(f);
free((char*)in);
}
void DumpData(const char* infn, const char* outfn, int skip)
{
FILE *f;
int i;
int insize;
char symname[9];
const char *in;
const char *infn_stripped = strrchr(infn, '/');
if(strrchr(infn, '\\') > infn_stripped)
infn_stripped = strrchr(infn, '\\');
if(infn_stripped == NULL)
infn_stripped = infn;
else
++infn_stripped;
f = fopen(outfn, "wb");
memset(symname, 0, 9);
memcpy(symname, infn_stripped, strlen(infn_stripped)-4);
fprintf(f, "char far %s[] ={\r\n", symname);
in = ReadFile(infn, &insize);
for(i = skip;i < insize;++i)
{
fprintf(f, "%d", (unsigned char)in[i]);
if(i != insize-1)
fprintf(f, ",\r\n");
}
fprintf(f, " };\r\n");
fclose(f);
free((char*)in);
}
int main(int argc, char* argv[])
{
if(argc < 3)
{
printf("Converts file to OMF.\nUseage:\n ./makeobj [fx] <input> ...\n");
return 0;
}
switch(argv[1][0])
{
case 'c':
if(argc < 4)
{
printf("Need an output location. (Extra parms: <output> [<symbol>])\n");
return 0;
}
else
{
const char *symname = NULL;
if(argc >= 5)
symname = argv[4];
MakeDataObj(argv[2], argv[3], NULL, symname, 1);
}
break;
default:
case 'f':
if(argc < 4)
{
printf("Need an output location. (Extra parms: <output> [<segname> <symbol>])\n");
return 0;
}
else
{
const char *segname = NULL, *symname = NULL;
if(argc >= 6)
{
segname = argv[4];
symname = argv[5];
}
MakeDataObj(argv[2], argv[3], segname, symname, 0);
}
break;
case 'x':
Extract(argv[2]);
break;
case 's':
if(argc < 4)
{
printf("Need an output location. (Extra parms: <output> [<skip>])\n");
return 0;
}
else
{
int skip = 0;
if(argc >= 5)
{
skip = atoi(argv[4]);
}
DumpData(argv[2], argv[3], skip);
}
break;
break;
}
return 0;
}
|
the_stack_data/144330.c | /**ARGS: symbols --locate --undefs --cant -DFOO -UBAR */
/**SYSCODE: = 2 */
#ifdef FOO
#define FOO 1
#else
#undef FOO
#endif
#ifndef BAR
#define BAR 1
#else
#undef BAR
#endif
|
the_stack_data/86074310.c | #include <assert.h>
#include <stdlib.h>
extern int nondet_int();
int main() {
int arraylen=nondet_int();
if(arraylen==3)
{
int** array_init = malloc(sizeof(int *)*arraylen);
int a0, a1, a2;
array_init[0] = &a0;
array_init[1] = &a1;
array_init[2] = &a2;
void **local_array=(void**)array_init;
int *address=(int *)local_array[0];
assert(address==&a0);
}
}
|
the_stack_data/153268398.c | // RUN: %clang_analyze_cc1 -analyzer-checker=core,alpha.core,debug.ExprInspection %s -analyzer-store=region -verify
void clang_analyzer_eval(int);
unsigned foo(void);
typedef struct bf { unsigned x:2; } bf;
void bar(void) {
bf y;
*(unsigned*)&y = foo();
y.x = 1;
}
struct s {
int n;
};
void f(void) {
struct s a;
int *p = &(a.n) + 1; // expected-warning{{Pointer arithmetic on}}
}
typedef struct {
int x,y;
} Point;
Point getit(void);
void test(void) {
Point p;
(void)(p = getit()).x;
}
#define true ((bool)1)
#define false ((bool)0)
typedef _Bool bool;
void testLazyCompoundVal(void) {
Point p = {42, 0};
Point q;
clang_analyzer_eval((q = p).x == 42); // expected-warning{{TRUE}}
clang_analyzer_eval(q.x == 42); // expected-warning{{TRUE}}
}
struct Bits {
unsigned a : 1;
unsigned b : 2;
unsigned c : 1;
bool x;
struct InnerBits {
bool y;
unsigned d : 16;
unsigned e : 6;
unsigned f : 2;
} inner;
};
void testBitfields(void) {
struct Bits bits;
if (foo() && bits.b) // expected-warning {{garbage}}
return;
if (foo() && bits.inner.e) // expected-warning {{garbage}}
return;
bits.c = 1;
clang_analyzer_eval(bits.c == 1); // expected-warning {{TRUE}}
if (foo() && bits.b) // expected-warning {{garbage}}
return;
if (foo() && bits.x) // expected-warning {{garbage}}
return;
bits.x = true;
clang_analyzer_eval(bits.x == true); // expected-warning{{TRUE}}
bits.b = 2;
clang_analyzer_eval(bits.x == true); // expected-warning{{TRUE}}
if (foo() && bits.c) // no-warning
return;
bits.inner.e = 50;
if (foo() && bits.inner.e) // no-warning
return;
if (foo() && bits.inner.y) // expected-warning {{garbage}}
return;
if (foo() && bits.inner.f) // expected-warning {{garbage}}
return;
extern struct InnerBits getInner(void);
bits.inner = getInner();
if (foo() && bits.inner.e) // no-warning
return;
if (foo() && bits.inner.y) // no-warning
return;
if (foo() && bits.inner.f) // no-warning
return;
bits.inner.f = 1;
if (foo() && bits.inner.e) // no-warning
return;
if (foo() && bits.inner.y) // no-warning
return;
if (foo() && bits.inner.f) // no-warning
return;
if (foo() && bits.a) // expected-warning {{garbage}}
return;
}
//-----------------------------------------------------------------------------
// Incorrect behavior
//-----------------------------------------------------------------------------
void testTruncation(void) {
struct Bits bits;
bits.c = 0x11; // expected-warning{{implicit truncation}}
// FIXME: We don't model truncation of bitfields.
clang_analyzer_eval(bits.c == 1); // expected-warning {{FALSE}}
}
|
the_stack_data/26190.c | /* PR middle-end/31309 */
/* Origin: Peeter Joot <[email protected]> */
/* { dg-do run { target *-*-linux* *-*-gnu* } } */
#include <sys/mman.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#if defined(STACK_SIZE) && (STACK_SIZE < 128*1024)
#define CHUNK_SIZE 4096
#else
#define CHUNK_SIZE 16384
#endif
unsigned long ossAlignX(unsigned long i, unsigned long X)
{
return ((i + (X - 1)) & ~(unsigned long) (X - 1));
}
struct STRUCT_6_BYTES
{
unsigned char slot[sizeof(unsigned short)];
unsigned char page[sizeof(unsigned int)];
};
struct SQLU_DICT_INFO_0
{
void *pBlah;
char bSomeFlag1;
char bSomeFlag2;
struct STRUCT_6_BYTES dRID;
};
struct SQLU_DATAPART_0
{
struct SQLU_DICT_INFO_0 *pDictRidderInfo;
};
struct XXX
{
struct SQLU_DATAPART_0 *m_pDatapart;
};
struct STRUCT_6_BYTES INIT_6_BYTES_ZERO()
{
struct STRUCT_6_BYTES ridOut = {{0,0}, {0,0,0,0}};
return ridOut;
}
void Initialize(struct XXX *this, int iIndex)
{
struct SQLU_DICT_INFO_0 *pDictRidderInfo
= this->m_pDatapart[iIndex].pDictRidderInfo;
pDictRidderInfo->bSomeFlag1 = 0;
pDictRidderInfo->bSomeFlag2 = 0;
pDictRidderInfo->dRID = INIT_6_BYTES_ZERO();
}
int main(void)
{
int rc;
struct stuff
{
char c0[CHUNK_SIZE-sizeof(struct XXX)];
struct XXX o;
char c1[CHUNK_SIZE*2-sizeof(struct SQLU_DATAPART_0)];
struct SQLU_DATAPART_0 dp;
char c2[CHUNK_SIZE*2-sizeof(struct SQLU_DICT_INFO_0)];
struct SQLU_DICT_INFO_0 di;
char c3[CHUNK_SIZE];
};
char buf[sizeof(struct stuff)+CHUNK_SIZE];
struct stuff *u
= (struct stuff *)ossAlignX((unsigned long)&buf[0], CHUNK_SIZE);
/* This test assumes system memory page
size of CHUNK_SIZE bytes or less. */
if (sysconf(_SC_PAGESIZE) > CHUNK_SIZE)
return 0;
memset(u, 1, sizeof(struct stuff));
u->c1[0] = '\xAA';
u->c2[0] = '\xBB';
u->c3[0] = '\xCC';
rc = mprotect(u->c1, CHUNK_SIZE, PROT_NONE);
if (rc == -1)
printf("mprotect:c1: %d: %d(%s)\n", rc, errno, strerror(errno));
rc = mprotect(u->c2, CHUNK_SIZE, PROT_NONE);
if (rc == -1)
printf("mprotect:c2: %d: %d(%s)\n", rc, errno, strerror(errno));
rc = mprotect(u->c3, CHUNK_SIZE, PROT_NONE);
if (rc == -1)
printf("mprotect:c3: %d: %d(%s)\n", rc, errno, strerror(errno));
u->o.m_pDatapart = &u->dp;
u->dp.pDictRidderInfo = &u->di;
Initialize(&u->o, 0);
mprotect(u->c1, CHUNK_SIZE, PROT_READ|PROT_WRITE);
mprotect(u->c2, CHUNK_SIZE, PROT_READ|PROT_WRITE);
mprotect(u->c3, CHUNK_SIZE, PROT_READ|PROT_WRITE);
return 0;
}
|
the_stack_data/61074994.c | /* ureadasn.c
-- parse, mangle and otherwise rewrite ASN1 file/entries for readseq reading
-- from NCBI toolkit (ncbi.nlm.nih.gov:/toolkit)
*/
#ifdef NCBI
#include <stdio.h>
#include <ctype.h>
#include <string.h>
/* NCBI toolkit :include: must be on lib path */
#include <ncbi.h>
#include <seqport.h>
#define UREADASN
#include "ureadseq.h"
#pragma segment ureadasn
/* this stuff is hacked up from tofasta.c of ncbitools */
#define kBaseAny 0
#define kBaseNucleic 1
#define kBaseAmino 2
typedef struct tofasta {
Boolean idonly;
short *seqnum;
short whichSeq;
char **seq, **seqid;
long *seqlen;
} FastaDat, PNTR FastaPtr;
void BioseqRawToRaw(BioseqPtr bsp, Boolean idonly,
short whichSeq, short *seqnum,
char **seq, char **seqid, long *seqlen)
{
SeqPortPtr spp;
SeqIdPtr bestid;
Uint1 repr, code, residue;
CharPtr tmp, title;
long outlen, outmax;
char localid[256], *sp;
/* !!! this may be called several times for a single sequence
because SeqEntryExplore looks for parts and joins them...
assume seq, seqid, seqlen may contain data (or NULL)
*/
if (bsp == NULL) return;
repr = Bioseq_repr(bsp);
if (!(repr == Seq_repr_raw || repr == Seq_repr_const)) return;
(*seqnum)++;
if (!(whichSeq == *seqnum || whichSeq == 0)) return;
bestid = SeqIdFindBest(bsp->id, (Uint1) 0);
title = BioseqGetTitle(bsp);
if (idonly) {
sprintf(localid, " %d) ", *seqnum);
tmp= localid + strlen(localid)-1;
}
else {
strcpy(localid," ");
tmp= localid;
}
tmp = SeqIdPrint(bestid, tmp, PRINTID_FASTA_SHORT);
tmp = StringMove(tmp, " ");
StringNCpy(tmp, title, 200);
/* fprintf(stderr,"BioseqRawToRaw: localid='%s'\n",localid); */
/* < seqid is fixed storage */
/* strcpy( *seqid, localid); */
/* < seqid is variable sized */
outmax= strlen(localid) + 3;
if (*seqid==NULL) {
*seqid= (char*) malloc(outmax);
if (*seqid==NULL) return;
strcpy(*seqid, localid);
}
else {
outmax += strlen(*seqid) + 2;
*seqid= (char*) realloc( *seqid, outmax);
if (*seqid==NULL) return;
if (!idonly) strcat(*seqid, "; ");
strcat(*seqid, localid);
}
if (idonly) {
strcat(*seqid,"\n");
return;
}
if (ISA_na(bsp->mol)) code = Seq_code_iupacna;
else code = Seq_code_iupacaa;
spp = SeqPortNew(bsp, 0, -1, 0, code);
SeqPortSeek(spp, 0, SEEK_SET);
sp= *seq;
if (sp==NULL) { /* this is always true now !? */
outlen= 0;
outmax= 500;
sp= (char*) malloc(outmax);
}
else {
outlen= strlen(sp);
outmax= outlen + 500;
sp= (char*) realloc( sp, outmax);
}
if (sp==NULL) return;
while ((residue = SeqPortGetResidue(spp)) != SEQPORT_EOF) {
if (outlen>=outmax) {
outmax= outlen + 500;
sp= (char*) realloc(sp, outmax);
if (sp==NULL) return;
}
sp[outlen++] = residue;
}
sp= (char*) realloc(sp, outlen+1);
if (sp!=NULL) sp[outlen]= '\0';
*seq= sp;
*seqlen= outlen;
SeqPortFree(spp);
return;
}
static void SeqEntryRawseq(SeqEntryPtr sep, Pointer data, Int4 index, Int2 indent)
{
FastaPtr tfa;
BioseqPtr bsp;
if (!IS_Bioseq(sep)) return;
bsp = (BioseqPtr)sep->data.ptrvalue;
tfa = (FastaPtr) data;
BioseqRawToRaw(bsp, tfa->idonly, tfa->whichSeq, tfa->seqnum,
tfa->seq, tfa->seqid, tfa->seqlen);
}
void SeqEntryToRaw(SeqEntryPtr sep, Boolean idonly, short whichSeq, short *seqnum,
char **seq, char **seqid, long *seqlen)
{
FastaDat tfa;
if (sep == NULL) return;
tfa.idonly= idonly;
tfa.seqnum= seqnum;
tfa.whichSeq= whichSeq;
tfa.seq = seq;
tfa.seqid = seqid;
tfa.seqlen= seqlen;
SeqEntryExplore(sep, (Pointer)&tfa, SeqEntryRawseq);
}
char *listASNSeqs(const char *filename, const long skiplines,
const short format, /* note: this is kASNseqentry or kASNseqset */
short *nseq, short *error )
{
AsnIoPtr aip = NULL;
SeqEntryPtr the_set;
AsnTypePtr atp, atp2;
AsnModulePtr amp;
Boolean inIsBinary= FALSE; /* damn, why can't asn routines test this? */
char *seq = NULL;
char *seqid = NULL, stemp[256];
long seqlen;
int i, count;
*nseq= 0;
*error= 0;
/* asn dictionary setups */
/*fprintf(stderr,"listASNSeqs: SeqEntryLoad\n");*/
if (! SeqEntryLoad()) goto errxit; /* sequence alphabets (and sequence parse trees) */
amp = AsnAllModPtr(); /* get pointer to all loaded ASN.1 modules */
if (amp == NULL) goto errxit;
atp = AsnFind("Bioseq-set"); /* get the initial type pointers */
if (atp == NULL) goto errxit;
atp2 = AsnFind("Bioseq-set.seq-set.E");
if (atp2 == NULL) goto errxit;
/*fprintf(stderr,"listASNSeqs: AsnIoOpen\n");*/
/* open the ASN.1 input file in the right mode */
/* !!!! THIS FAILS when filename has MAC PATH (& other paths?) (:folder:filename) */
if ((aip = AsnIoOpen(filename, inIsBinary?"rb":"r")) == NULL) goto errxit;
for (i=0; i<skiplines; i++) fgets( stemp, 255, aip->fp); /* this may mess up asn routines... */
if (! ErrSetLog ("stderr")) goto errxit;
else ErrSetOpts(ERR_CONTINUE, ERR_LOG_ON); /*?? log errors instead of die */
if (format == kASNseqentry) { /* read one Seq-entry */
/*fprintf(stderr,"listASNSeqs: SeqEntryAsnRead\n");*/
the_set = SeqEntryAsnRead(aip, NULL);
SeqEntryToRaw(the_set, true, 0, nseq, &seq, &seqid, &seqlen);
if (seq) free(seq); seq= NULL;
SeqEntryFree(the_set);
}
else { /* read Seq-entry's from a Bioseq-set */
count = 0;
/*fprintf(stderr,"listASNSeqs: AsnReadId\n");*/
while ((atp = AsnReadId(aip, amp, atp)) != NULL) {
if (atp == atp2) { /* top level Seq-entry */
the_set = SeqEntryAsnRead(aip, atp);
SeqEntryToRaw(the_set, true, 0, nseq, &seq, &seqid, &seqlen);
SeqEntryFree(the_set);
if (seq) free(seq); seq= NULL;
}
else
AsnReadVal(aip, atp, NULL);
count++;
}
}
AsnIoClose(aip);
*error= 0;
return seqid;
errxit:
AsnIoClose(aip);
if (seqid) free(seqid);
*error= eASNerr;
return NULL;
}
char *readASNSeq(const short whichEntry, const char *filename,
const long skiplines,
const short format, /* note: this is kASNseqentry or kASNseqset */
long *seqlen, short *nseq,
short *error, char **seqid )
{
AsnIoPtr aip = NULL;
SeqEntryPtr the_set;
AsnTypePtr atp, atp2;
AsnModulePtr amp;
Boolean inIsBinary= FALSE; /* damn, why can't asn routines test this? */
char *seq, stemp[200];
int i, count;
*seqlen= 0;
*nseq= 0;
*error= 0;
seq= NULL;
/*fprintf(stderr,"readASNseq: SeqEntryLoad\n");*/
/* asn dictionary setups */
if (! SeqEntryLoad()) goto errxit; /* sequence alphabets (and sequence parse trees) */
amp = AsnAllModPtr(); /* get pointer to all loaded ASN.1 modules */
if (amp == NULL) goto errxit;
atp = AsnFind("Bioseq-set"); /* get the initial type pointers */
if (atp == NULL) goto errxit;
atp2 = AsnFind("Bioseq-set.seq-set.E");
if (atp2 == NULL) goto errxit;
/* open the ASN.1 input file in the right mode */
/*fprintf(stderr,"readASNseq: AsnIoOpen(%s)\n", filename);*/
if ((aip = AsnIoOpen(filename, inIsBinary?"rb":"r")) == NULL) goto errxit;
for (i=0; i<skiplines; i++) fgets( stemp, 255, aip->fp); /* this may mess up asn routines... */
if (! ErrSetLog ("stderr")) goto errxit;
else ErrSetOpts(ERR_CONTINUE, ERR_LOG_ON); /*?? log errors instead of die */
seq= NULL;
if (format == kASNseqentry) { /* read one Seq-entry */
/*fprintf(stderr,"readASNseq: SeqEntryAsnRead\n");*/
the_set = SeqEntryAsnRead(aip, NULL);
SeqEntryToRaw(the_set, false, whichEntry, nseq, &seq, seqid, seqlen);
SeqEntryFree(the_set);
goto goodexit;
}
else { /* read Seq-entry's from a Bioseq-set */
count = 0;
/*fprintf(stderr,"readASNseq: AsnReadId\n");*/
while ((atp = AsnReadId(aip, amp, atp)) != NULL) {
if (atp == atp2) { /* top level Seq-entry */
the_set = SeqEntryAsnRead(aip, atp);
SeqEntryToRaw(the_set, false, whichEntry, nseq, &seq, seqid, seqlen);
SeqEntryFree(the_set);
if (*nseq >= whichEntry) goto goodexit;
}
else
AsnReadVal(aip, atp, NULL);
count++;
}
}
goodexit:
AsnIoClose(aip);
*error= 0;
return seq;
errxit:
AsnIoClose(aip);
*error= eASNerr;
if (seq) free(seq);
return NULL;
}
#endif /*NCBI*/
|
the_stack_data/109367.c | #include<stdio.h>
#include<time.h>
#include<stdlib.h>
#define range_max 1000
#define times 3
//运行环境 Visual studio
int judge(int guess)
{
int count = 0;
if (!(guess - 1))
{
printf_s("%d", 1);
return count;
}
do
{
if (guess % 2)//如果是基数
{
guess = (times*guess + 1) / 2;
count++;
}
else
{
guess = guess / 2;
count++;
}
} while (guess - 1);
return count;
}
int main()
{
int seed = clock()*clock()*clock()*time(NULL);
int test_times = 100;
int rand_num_max = 1000, rand_num_min = 2, test_num = 0;
int i = 0;
srand(seed);
for (i = 0; i < test_times; i++)
{
test_num = rand() % (rand_num_max - rand_num_min + 1) + rand_num_min;
printf_s("%d===%d times\n", test_num, judge(test_num));
}
system("pause");
}
|
the_stack_data/248580567.c | /* strcmp( const char *, const char * )
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include <string.h>
#ifndef REGTEST
int strcmp( const char * s1, const char * s2 )
{
while ( ( *s1 ) && ( *s1 == *s2 ) )
{
++s1;
++s2;
}
return ( *(unsigned char *)s1 - *(unsigned char *)s2 );
}
#endif
#ifdef TEST
#include "_PDCLIB_test.h"
int main( void )
{
char cmpabcde[] = "abcde";
char cmpabcd_[] = "abcd\xfc";
char empty[] = "";
TESTCASE( strcmp( abcde, cmpabcde ) == 0 );
TESTCASE( strcmp( abcde, abcdx ) < 0 );
TESTCASE( strcmp( abcdx, abcde ) > 0 );
TESTCASE( strcmp( empty, abcde ) < 0 );
TESTCASE( strcmp( abcde, empty ) > 0 );
TESTCASE( strcmp( abcde, cmpabcd_ ) < 0 );
return TEST_RESULTS;
}
#endif
|
the_stack_data/153269010.c | /*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University 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 REGENTS 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 REGENTS 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.
*/
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)tmpnam.c 5.3 (Berkeley) 2/24/91";*/
static char *rcsid = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <unistd.h>
#include <stdio.h>
char *
tmpnam(s)
char *s;
{
static char buf[L_tmpnam];
if (s == NULL)
s = buf;
(void)snprintf(s, L_tmpnam, "%stmp.XXXXXX", P_tmpdir);
return(mktemp(s));
}
|
the_stack_data/86075098.c | #include<stdio.h>
int main()
{
int i;
do{
scanf("%d",&i);
}while(i<0 || i>9);
if(i==0)printf("zero\n");
else if(i==1)printf("one\n");
else if(i==2)printf("two\n");
else if(i==3)printf("three\n");
else if(i==4)printf("four\n");
else if(i==5)printf("five\n");
else if(i==6)printf("six\n");
else if(i==7)printf("seven\n");
else if(i==8)printf("eight\n");
else printf("nine\n");
return 0;
}
|
the_stack_data/1059785.c | #include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/prctl.h>
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <string.h>
int main(void)
{
char s[32];
int status;
int pid = fork();
memset(s, 0, 32);
if (pid == 0)
{
prctl(1, 1);
ptrace(PTRACE_TRACEME, 0, 0, 0);
puts("Give me some shellcode, k");
gets(s);
}
else if (pid > 0) {
wait(&status);
do {
if (!(status & 0x7f))
{
puts("child is exiting...");
return 0;
}
} while (ptrace(PTRACE_PEEKUSER, pid, 0x2c, 0) != 0x0b);
puts("no exec() for you");
kill(pid, 0x9);
}
return 0;
} |
the_stack_data/175142919.c | /* the second assignment assumes failed before */
int
main(void) {
double x = 1;
int foo = 0;
if (foo)
x = 1;
}
|
the_stack_data/173577443.c | #include<stdio.h>
int main()
{
//WAP to convert a quantity in meter entered through keyboard into its equivalent kilometer and meter as per the following format. Example. 2430 meter = 2 Km and 430 meter
int a;
printf("Enter distance(in meters): ");
scanf("%d",&a);
printf("%d meters = %d Km and %d meters",a,a/1000,a%1000);
return 0;
} |
the_stack_data/25137282.c | /*
Copyright (c) 2017, Alexey Frunze
2-clause BSD license.
*/
#ifdef __SMALLER_C_32__
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <errno.h>
#include "ifp.h"
static int match(char* s, char* upattern)
{
int c1, c2;
do
{
c1 = toupper((unsigned char)*s++);
c2 = *upattern++;
if (c1 != c2)
return c2 ? 0 : 1;
} while (c1);
return 1;
}
float strtof(char* nptr, char** endptr)
{
char* nptr0 = nptr;
int neg = 0;
float val = 0;
while (isspace((unsigned char)*nptr))
nptr++;
if (*nptr == '-')
neg = 1, nptr++;
else if (*nptr == '+')
nptr++;
if (match(nptr, "NAN"))
{
val = NAN;
nptr += 3;
}
else if (match(nptr, "INF"))
{
val = INFINITY;
nptr += 3;
if (match(nptr, "INITY"))
nptr += 5;
}
else
{
unsigned char digits[MAX_FP_DIGITS];
int mcnt = 0, mexp = 0;
int gotint = 0, gotfrct = 0;
int esign = 0;
unsigned eexp = 0;
int e;
int c;
while (*nptr == '0')
{
gotint = 1; // got integral part digits: all zeroes so far
nptr++;
}
while (isdigit(c = (unsigned char)*nptr))
{
gotint = 2; // got integral part digits: non-zero
if (mcnt < MAX_FP_DIGITS)
digits[mcnt++] = c - '0';
else
mexp++; // TBD??? overflow
nptr++;
}
if (*nptr == '.')
{
nptr++;
if (gotint < 2)
while (*nptr == '0')
{
gotfrct = 1; // got fractional part digits: all zeroes so far
mexp--; // TBD??? overflow
nptr++;
}
while (isdigit(c = (unsigned char)*nptr))
{
gotfrct = 2; // got fractional part digits: non-zero
if (mcnt < MAX_FP_DIGITS)
digits[mcnt++] = c - '0';
mexp--; // TBD??? overflow
nptr++;
}
}
if ((gotint | gotfrct) == 0)
{
nptr = nptr0;
goto lend;
}
if (*nptr == 'E' || *nptr == 'e')
{
char* nptr1 = nptr++;
int gotexp = 0;
if (*nptr == '-')
esign = '-', nptr++;
else if (*nptr == '+')
nptr++;
while (isdigit(c = (unsigned char)*nptr))
{
int d = c - '0';
unsigned ex10 = eexp * 10;
gotexp = 2; // got e/E and exponent part digits
if (ex10 / 10 != eexp ||
ex10 + d < ex10 ||
ex10 + d > (unsigned)-1 / 2)
{
nptr = nptr0;
goto lend;
}
eexp = ex10 + d;
nptr++;
}
if (!gotexp)
nptr = nptr1;
}
e = (esign == '-') ? -(int)eexp : (int)eexp;
// drop trailing zeroes, if any
while (mcnt && !digits[mcnt - 1])
{
mcnt--;
mexp++; // TBD??? overflow
}
if (!mcnt)
mexp = digits[mcnt++] = 0;
if (mexp >= 0 && e > INT_MAX - mexp)
mexp = INT_MAX;
else if (mexp < 0 && e < INT_MIN - mexp)
mexp = INT_MIN;
else
mexp += e;
eexp = __cvtfd(digits, mcnt, mexp);
memcpy(&val, &eexp, sizeof val);
if (val == INFINITY)
errno = ERANGE;
}
if (neg)
val = -val;
lend:
if (endptr)
*endptr = nptr;
return val;
}
#endif
|
the_stack_data/1196678.c | #include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
void main(int argc, char *argv[])
{
static uid_t ruid, euid, tmpruid, tmpeuid;
ruid = getuid(); // Save current real user id
euid = geteuid(); // Save the effective user id
int errnum;
printf("Before setuid:\n");
system("id");
printf("Real: %d\n", ruid);
printf("effective: %d\n\n", euid);
if (!(setreuid(1005, ruid)==0)){ //Get studentroot(owner) priviledges
printf("\nSetuid failed.\n");
errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("Error printed by perror");
}
printf("\nAfter setuid:\n");
system("id");
printf("Real: %d\n", getuid());
printf("effective: %d\n", geteuid());
if (!(setreuid(ruid, euid)==0)){ //Drop priviledges back to user id
printf("\nSetuid failed.\n");
errnum = errno;
fprintf(stderr, "Value of errno: %d\n", errno);
perror("Error printed by perror");
}
printf("\nAfter setuid restore:\n");
system("id");
printf("Real: %d\n", getuid());
printf("effective: %d\n", geteuid());
return;
}
|
the_stack_data/933700.c | #include <stdio.h>
#include <string.h>
char *s_gets(char *st, int n);
#define MAXTITL 40
#define MAXAUTL 40
#define MAXBKS 100
struct book { /* structure template: tag is book */
char title[MAXTITL];
char author[MAXAUTL];
float value;
}; /* end of structure template */
int main(void)
{
struct book library[MAXBKS]; /* array of book structures */
int count = 0;
int index;
printf("Please enter the book title.\n");
printf("Press [enter] at the start of a line to stop.\n");
while (count < MAXBKS && s_gets(library[count].title, MAXTITL) != NULL
&& library[count].title[0] != '\0') {
printf("Now enter the author.\n");
s_gets(library[count].author, MAXAUTL);
printf("Now enter the value.\n");
scanf("%f", &library[count++].value);
while (getchar() != '\n') continue; /* clear input line */
if (count < MAXBKS) printf("Enter the next title.\n");
}
if (count > 0) {
printf("Here is the list of your books:\n");
for (index =0; index < count; index++) {
printf("%s by %s: $%.2f\n", library[index].title,
library[index].author, library[index].value);
}
} else {
printf("No books? Too bad.\n");
}
return 0;
}
char *s_gets(char *st, int n)
{
char *ret_val;
char *find;
ret_val = fgets(st, n, stdin);
if (ret_val) {
find = strchr(st, '\n'); // look for new line
if (find) { // if the address is not NULL
*find = '\0'; // place a null character there
} else {
while (getchar() != '\n') continue; // dispose of rest of line
}
}
return ret_val;
}
|
the_stack_data/27218.c | int main() {
int x=-4,y;
// should succeed
y=x>>1;
x>>=1;
assert(x==-2);
assert(y==-2);
// should also work with mixed types
assert(((-2)>>1u)==-1);
}
|
the_stack_data/212643679.c | // A bunch of information about your game - used on the title screen, as well as
// the credits, and anywhere else you fancy!
const unsigned char gameName[] = "Depths";
const unsigned char gameAuthor[] = "@cppchriscpp";
const unsigned char gameAuthorContact[] = "blurhg";
const unsigned char currentYear[] = "2020";
|
the_stack_data/167331989.c | int simple_function(int i) {
if (i > 0) {
int value = i;
value += 3;
value = value * 2;
return value;
} else {
return i * -5 + i;
}
}
|
the_stack_data/1047541.c | #include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>
//#include "instrument.h"
/* Default problem size. */
#ifndef TSTEPS
# define TSTEPS 10
#endif
#ifndef N
# define N 1024
#endif
#ifndef NBTHREADS
# define NBTHREADS 2
#endif
/* Default data type is double. */
#ifndef DATA_TYPE
# define DATA_TYPE double
#endif
#ifndef DATA_PRINTF_MODIFIER
# define DATA_PRINTF_MODIFIER "%0.2lf "
#endif
/* Array declaration. Enable malloc if POLYBENCH_TEST_MALLOC. */
#ifndef POLYBENCH_TEST_MALLOC
DATA_TYPE X[N][N];
DATA_TYPE A[N][N];
DATA_TYPE B[N][N];
#else
DATA_TYPE** X = (DATA_TYPE**)malloc(MAXGRID * sizeof(DATA_TYPE*));
DATA_TYPE** A = (DATA_TYPE**)malloc(MAXGRID * sizeof(DATA_TYPE*));
DATA_TYPE** B = (DATA_TYPE**)malloc(MAXGRID * sizeof(DATA_TYPE*));
{
int i;
for (i = 0; i < N; ++i)
{
X[i] = (DATA_TYPE*)malloc(N * sizeof(DATA_TYPE));
A[i] = (DATA_TYPE*)malloc(N * sizeof(DATA_TYPE));
B[i] = (DATA_TYPE*)malloc(N * sizeof(DATA_TYPE));
}
}
#endif
static inline
void init_array()
{
int i, j;
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
{
X[i][j] = ((DATA_TYPE) i*(j+1) + 1) / N;
A[i][j] = ((DATA_TYPE) (i-1)*(j+4) + 2) / N;
B[i][j] = ((DATA_TYPE) (i+3)*(j+7) + 3) / N;
}
}
/* Define the live-out variables. Code is not executed unless
POLYBENCH_DUMP_ARRAYS is defined. */
static inline
void print_array(int argc, char** argv)
{
int i, j;
#ifndef POLYBENCH_DUMP_ARRAYS
if (argc > 42 && ! strcmp(argv[0], ""))
#endif
{
for (i = 0; i < N; i++)
for (j = 0; j < N; j++) {
fprintf(stderr, DATA_PRINTF_MODIFIER, A[i][j]);
if ((i * N + j) % 80 == 20) fprintf(stderr, "\n");
}
fprintf(stderr, "\n");
}
}
double rtclock()
{
struct timezone Tzp;
struct timeval Tp;
int stat;
stat = gettimeofday (&Tp, &Tzp);
if (stat != 0) printf("Error return from gettimeofday: %d",stat);
return(Tp.tv_sec + Tp.tv_usec*1.0e-6);
}
double t_start, t_end;
int main(int argc, char** argv)
{
int t, i1, i2;
int n = N;
int tsteps = TSTEPS;
/* Initialize array. */
init_array();
/* Start timer. */
for (t = 0; t < tsteps; t++)
{
for (i1 = 0; i1 < n; i1++)
for (i2 = 1; i2 < n; i2++)
{
X[i1][i2] = X[i1][i2] - X[i1][i2-1] * A[i1][i2] / B[i1][i2-1];
B[i1][i2] = B[i1][i2] - A[i1][i2] * A[i1][i2] / B[i1][i2-1];
}
for (i1 = 0; i1 < n; i1++)
X[i1][n-1] = X[i1][n-1] / B[i1][n-1];
for (i1 = 0; i1 < n; i1++)
for (i2 = 0; i2 < n-2; i2++)
X[i1][n-i2-2] = (X[i1][n-2-i2] - X[i1][n-2-i2-1] * A[i1][n-i2-3]) / B[i1][n-3-i2];
for (i1 = 1; i1 < n; i1++)
for (i2 = 0; i2 < n; i2++) {
X[i1][i2] = X[i1][i2] - X[i1-1][i2] * A[i1][i2] / B[i1-1][i2];
B[i1][i2] = B[i1][i2] - A[i1][i2] * A[i1][i2] / B[i1-1][i2];
}
for (i2 = 0; i2 < n; i2++)
X[n-1][i2] = X[n-1][i2] / B[n-1][i2];
for (i1 = 0; i1 < n-2; i1++)
for (i2 = 0; i2 < n; i2++)
X[n-2-i1][i2] = (X[n-2-i1][i2] - X[n-i1-3][i2] * A[n-3-i1][i2]) / B[n-2-i1][i2];
}
print_array(argc, argv);
return 0;
}
|
the_stack_data/40763014.c | /*
* 32 bit
*/
char *str = "Hello world!\n";
void print()
{
asm("movl $13, %%edx \n\t"
"movl %0, %%ecx \n\t"
"movl $0, %%ebx \n\t"
"movl $4, %%eax \n\t"
"int $0x80 \n\t"
::"r"(str):"edx","ecx","ebx");
}
void exit()
{
asm("movl $42, %ebx \n\t"
"movl $1, %eax \n\t"
"int $0x80 \n\t");
}
void nomain()
{
print();
exit();
}
|
the_stack_data/737213.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
double avg(double x,double y);
void riemann_MP(double a,double b);
double f(double x);
int main(void){
double a=1;double b=2;
puts("the integral of 1/x from 1 to 2 is: ");
riemann_MP(1,2);
return 0;
}
//midpoint version of riemann sum
void riemann_MP(double a,double b){
double numOfTerms,integration,step,midP,delta_x;
numOfTerms=10000;
step=(b-a)/numOfTerms;
midP=avg(a,a+step);
// delta_x=1;
integration = 0;
for (int i=1;i<numOfTerms;i++){
integration = integration + f(midP)*step;
// delta_x=((a+step*i) - (a+step*(i-1)));
midP=avg(a+step*(i+1),a+step*i);
}
printf("%.15lf\n", integration);
}
double avg(double x,double y){
return (x+y)/2;
}
double f(double x) {return 1/x;}
|
the_stack_data/8811.c | /* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: esuguimo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/21 09:24:29 by esuguimo #+# #+# */
/* Updated: 2019/10/21 19:51:51 by esuguimo ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
unsigned int i;
i = 0;
while (str[i] != '\0')
{
ft_putchar(str[i]);
i++;
}
ft_putchar('\n');
}
int main(int argc, char **argv)
{
(void)argc;
(void)argv;
ft_putstr(argv[0]);
return (0);
}
|
the_stack_data/50916.c | // all classification
#include <math.h>
int main()
{
double d1, _d1;
d1=_d1;
__ESBMC_assume(isnormal(d1));
assert(!isnan(d1));
assert(!isinf(d1));
assert(isfinite(d1));
double d2, _d2;
d2=_d2;
__ESBMC_assume(isinf(d2));
assert(!isnormal(d2));
assert(!isnan(d2));
double d3, _d3;
d3=_d3;
__ESBMC_assume(isnan(d3));
assert(!isnormal(d3));
assert(!isinf(d3));
assert(d3!=d3);
double d4, _d4;
d4=_d4;
__ESBMC_assume(isfinite(d4));
assert(!isnan(d4));
assert(!isinf(d4));
double d5, _d5;
d5=_d5;
__ESBMC_assume(!isnan(d5) && !isinf(d5));
assert(isfinite(d5));
}
|
the_stack_data/38354.c | // RUN: %clang -O2 %s -o %t && %run %t
// UNSUPPORTED: android, netbsd, darwin, solaris
//
#include <sys/types.h>
#if !defined(__GLIBC_PREREQ)
#define __GLIBC_PREREQ(a, b) 0
#endif
#if (defined(__linux__) && __GLIBC_PREREQ(2, 25)) || defined(__FreeBSD__)
#define HAS_GETRANDOM
#endif
#if defined(HAS_GETRANDOM)
#include <sys/random.h>
#endif
int main() {
char buf[16];
ssize_t n = 1;
#if defined(HAS_GETRANDOM)
n = getrandom(buf, sizeof(buf), 0);
#endif
return (int)(n <= 0);
}
|
the_stack_data/598511.c | #include <stdio.h>
int in_a = 1, in_b = 2, out_sum;
void main() {
asm("pusha; \
movl in_a, %eax; \
movl in_b, %ebx; \
addl %ebx, %eax; \
movl %eax, out_sum; \
popa");
printf("sum is %d\n", out_sum);
} |
the_stack_data/37342.c | #include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* aggregate_superstring(char* superstring, char* k)
{
int newlength = strlen(superstring) + strlen(k) + 1;
char* result = (char*)malloc(newlength * sizeof(char));
int first_i = 0;
int second_i = 0;
while (superstring[first_i] != '\0' && k[second_i] != '\0')
{
if (superstring[first_i] != k[second_i])
{
first_i -= second_i;
second_i = -1;
}
result[first_i] = superstring[first_i];
first_i++;
second_i++;
}
if (k[second_i] != '\0')
{
while (k[second_i] != '\0')
{
result[first_i] = k[second_i];
first_i++;
second_i++;
}
}
else
{
while (superstring[first_i] != '\0')
{
result[first_i] = superstring[first_i];
first_i++;
}
}
result[first_i] = '\0';
return result;
}
int pere(char* superstring, char** strarray, int n)
{
int i;
int j;
if (n == 0)
{
return strlen(superstring);
}
int minimal_super_length = 10 * 256;
for (i = 0; i < n; i++)
{
char** subarr = (char**)malloc((n-1) * sizeof(char*));
char* k = strarray[i];
int z = 0;
for (j = 0 ; j < n; j++)
{
if (i != j)
{
subarr[z] = strarray[j];
z++;
}
}
char* aggregated = aggregate_superstring(superstring, k);
int current_length = pere(aggregated, subarr, n-1);
free (aggregated);
minimal_super_length = minimal_super_length < current_length ? minimal_super_length : current_length;
free(subarr);
}
return minimal_super_length;
}
int main()
{
int i;
int n;
scanf ("%d", &n);
char** s = (char**)malloc(n*sizeof(char*));
for (i = 0; i < n; i++)
{
char* current_s = (char*)malloc(256*sizeof(char));
scanf ("%s", current_s);
s[i] = current_s;
}
char* superstring = (char*)malloc(sizeof(char));
superstring[0] = '\0';
int t = pere(superstring, s, n);
for (i = 0; i < n; i++)
{
free(s[i]);
}
free(s);
free(superstring);
printf("%d", t);
return 0;
} |
the_stack_data/10404.c | /* Test for case handling in regex.
Copyright (C) 2001-2020 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Jakub Jelinek <[email protected]>, 2001.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include <sys/types.h>
#include <regex.h>
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
regex_t re;
int n;
n = regcomp (&re, "[a-bA-B]", REG_ICASE);
if (n != 0)
{
char buf[500];
regerror (n, &re, buf, sizeof (buf));
printf ("regcomp failed: %s\n", buf);
exit (1);
}
regfree (&re);
return 0;
}
|
the_stack_data/242330763.c | #ifdef CS333_P2
#include "types.h"
#include "user.h"
#include "uproc.h"
static void normalrun(void);
static void dotests(void);
static void printtable(uint, const struct uproc*);
static void printtime(uint time);
int
main(int argc, char* argv[])
{
if(1==argc)
normalrun();
if(1<argc)
dotests();
exit();
}
static void
normalrun(void)
{
int rc;
uint max = 64;
struct uproc* table;
table = malloc(sizeof(struct uproc) * max);
if(0 == table){
printf(2, "Error: malloc call failed. %s at line %d\n", __FILE__, __LINE__);
exit ();
}
rc = getprocs(max, table);
if(0 > rc){
printf(2, "Error: getprocs call failed. %s at line %d\n",
__FILE__, __LINE__);
free((void*)table);
exit ();
}
printtable(rc, table);
free((void*)table);
exit();
}
static void
dotests(void)
{
int max[] = {1, 16, 64, 72};
int MAXCOUNT = 4;
int i, rc;
uint m;
struct uproc* table;
for (i=0; i<MAXCOUNT; i++) {
printf(1, "\n**** MAX: %d\n", max[i]);
table = malloc(sizeof(struct uproc) * max[i]);
m = max[i];
if(0 == table){
printf(2, "Error: malloc call failed. %s at line %d\n",
__FILE__, __LINE__);
exit();
}
rc = getprocs(m, table);
if(0 > rc){
printf(2, "Error: getprocs call failed. %s at line %d\n",
__FILE__, __LINE__);
free((void*)table);
exit();
}
printtable(rc, table);
free((void*)table);
}
}
/* Prints the information in the uprocs table */
/* with one process per line. */
static void
printtable(uint num, const struct uproc* table)
{
int i;
printf(2, "PID\tName\t\tUID\tGID\tPPID\t");
#ifdef CS333_P3P4
printf(2, "Prio\t");
#endif
printf(2,"Elapsed\tCPU\tState\tSize\n");
for (i = 0; i < num; i++){
printf(2, "%d\t", table[i].pid);
if(7 > strlen((char *) table[i].name))
printf(2, "%s\t\t", table[i].name);
else
printf(2, "%s\t", table[i].name);
printf(2, "%d\t%d\t%d\t",
table[i].uid,
table[i].gid,
table[i].ppid);
#ifdef CS333_P3P4
printf(2, "%d\t", table[i].prio);
#endif
printtime(table[i].elapsed_ticks);
printtime(table[i].CPU_total_ticks);
printf(2, "%s\t%d\n", table[i].state, table[i].size);
}
}
/* Converts the ticks vales to seconds. */
/* Ticks are milisecs so will use 1000 as converison rate */
/* The prints display accounting for 0s */
static void
printtime (uint time)
{
uint q, r;
q = time / 1000;
r = time % 1000;
if (100 > r && 9 < r)
printf(2, "%d.0%d\t", q, r);
else if (10 > r)
printf(2, "%d.00%d\t", q, r);
else
printf(2, "%d.%d\t", q, r);
}
#endif
|
the_stack_data/211079910.c | /**
* @Author Trevor.Z
* @Date:2020/02/29
* @Desc:输出1光年长度,单位为米
*/
#include "stdio.h"
const long long lightSpeed = 3e8;
long long disPerLightYear;
int main()
{
disPerLightYear = lightSpeed * 60 * 60 * 24 * 365; // Assume not 闰年
printf("%lld\n", disPerLightYear);
return 0;
} |
the_stack_data/456764.c |
struct test_empty {
} e;
int Esize = sizeof(e);
struct rtx_def {
unsigned short code;
long long :3;
int mode : 8;
long long :0;
long long x :31;
long long y:31;
} N = {2, 7, 1 }; int Nsize = sizeof(N); // Size = 8
struct test1 {
char x:1;
long long :0;
} F1; int F1size = sizeof(F1); // Size = 4
struct test2 {
long long x :4;
} F2; int F2size = sizeof(F2); // Size = 4
struct test3 {
char x:1;
long long :20;
} F3; int F3size = sizeof(F3); // Size = 3
struct test4 {
char x:1;
long long :21;
short Y : 14;
} F4; int F4size = sizeof(F4); // Size = 6
struct test5 {
char x:1;
long long :17;
char Y : 1;
} F5; int F5size = sizeof(F5); // Size = 3
struct test6 {
char x:1;
long long :42;
long Y : 21;
} F6; int F6size = sizeof(F6); // Size = 8
struct test {
char c;
char d : 3;
char e: 3;
int : 0;
char f;
char :0;
long long x : 4;
} M; int Msize = sizeof(M); // Size = 8
extern int printf(const char *str, ...);
int main() {
printf("N: %d %d %d %d\n", N.code, N.mode, N.x, N.y);
printf("F1: %d\n", F1.x);
printf("F2: %d\n", F2.x);
printf("F3: %d\n", F3.x);
printf("F4: %d %d\n", F4.x, F4.Y);
printf("F5: %d %d\n", F5.x, F5.Y);
printf("F6: %d %d\n", F6.x, F6.Y);
printf("M: %d %d %d %d %d\n", M.c, M.d, M.e, M.f, (int)M.x);
return 0;
}
|
the_stack_data/97013387.c | #include <stdio.h>
int main() {
int a,b,c,d,x,y;
scanf("%d%d%d%d", &a, &x, &b, &y);
if(a==y && b==y && y==x)
{
c=x-y;
d=24+a-b;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(a==b && y>x)
{
c=y-x;
d=a-b;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(a==b && x>y)
{
c=60-x+y;
d=24-a+b-1;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(x==y && a<b)
{
c=0;
d=b-a;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(x==y && a>b)
{
c=0;
d=24-a+b;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(b>a && y>x)
{
c=y-x;
d=b-a;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(a<b && x>y)
{
c=60-x+y;
d=b-a-1;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(a>b && x<y)
{
c=y-x;
d=24-a-1+b;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
else if(a>b && x>y)
{
c=60+y-x;
d=24+b-a-1;
printf("O JOGO DUROU %d HORA(S) E %d MINUTO(S)\n", d, c);
}
return 0;
}
|
the_stack_data/99888.c | #include<stdio.h>
#include<stdlib.h>
int main()
{
int a,b,c;
scanf("%d%d",&a,&b);
c=a+b;
if(c>0)
printf("%d",c);
else{
printf("you are so fucking stupid just get out,please!");
}
system("pause");
return 0;
}
|
the_stack_data/7807.c | #include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
};
struct node *createNode(){
struct node *ptr,*head;
ptr= (struct node *)malloc(sizeof(struct node));
ptr->next = NULL;
return(ptr);
}
struct node *input(){
int num;
struct node *p,*head,*temp;
for(int i=0;i<5;i++){
scanf("%d",&num);
temp=createNode();
temp->data=num;
if(head == NULL){
p=head=temp;
}
else{
p=temp;
}
}
return head;
}
void insertNode(int value){
struct node *p,*head,*neww;
neww = createNode();
neww ->data=value;
if(head==NULL){
head = neww;
}
else{
while(p!=NULL){
p->next=p;
p = neww;
}
}
}
void display(struct node * head){
struct node * ptr=head;
while(ptr!=NULL){
printf("%d ",ptr->data);
ptr=ptr->next;
}
}
int main(){
struct node *head = input();
insertNode(3);
display(head);
return(0);
}
|
the_stack_data/269598.c | /* Generated by CIL v. 1.3.7 */
/* print_CIL_Input is true */
#line 214 "/usr/lib/gcc/i486-linux-gnu/4.3.3/include/stddef.h"
typedef unsigned int size_t;
#line 56 "/usr/include/bits/types.h"
typedef long long __quad_t;
#line 141 "/usr/include/bits/types.h"
typedef long __off_t;
#line 142 "/usr/include/bits/types.h"
typedef __quad_t __off64_t;
#line 45 "/usr/include/stdio.h"
struct _IO_FILE;
#line 45
struct _IO_FILE;
#line 49 "/usr/include/stdio.h"
typedef struct _IO_FILE FILE;
#line 170 "/usr/include/libio.h"
struct _IO_FILE;
#line 180 "/usr/include/libio.h"
typedef void _IO_lock_t;
#line 186 "/usr/include/libio.h"
struct _IO_marker {
struct _IO_marker *_next ;
struct _IO_FILE *_sbuf ;
int _pos ;
};
#line 271 "/usr/include/libio.h"
struct _IO_FILE {
int _flags ;
char *_IO_read_ptr ;
char *_IO_read_end ;
char *_IO_read_base ;
char *_IO_write_base ;
char *_IO_write_ptr ;
char *_IO_write_end ;
char *_IO_buf_base ;
char *_IO_buf_end ;
char *_IO_save_base ;
char *_IO_backup_base ;
char *_IO_save_end ;
struct _IO_marker *_markers ;
struct _IO_FILE *_chain ;
int _fileno ;
int _flags2 ;
__off_t _old_offset ;
unsigned short _cur_column ;
signed char _vtable_offset ;
char _shortbuf[1] ;
_IO_lock_t *_lock ;
__off64_t _offset ;
void *__pad1 ;
void *__pad2 ;
void *__pad3 ;
void *__pad4 ;
size_t __pad5 ;
int _mode ;
char _unused2[(15U * sizeof(int ) - 4U * sizeof(void *)) - sizeof(size_t )] ;
};
#line 21 "em3d.h"
struct node_t {
double value ;
struct node_t *next ;
struct node_t **to_nodes ;
struct node_t **from_nodes ;
double *coeffs ;
int from_count ;
};
#line 21 "em3d.h"
typedef struct node_t node_t;
#line 30 "em3d.h"
struct graph_t {
node_t *e_nodes ;
node_t *h_nodes ;
};
#line 30 "em3d.h"
typedef struct graph_t graph_t;
#line 147 "/usr/include/stdio.h"
extern struct _IO_FILE *stderr ;
#line 331
extern int fprintf(FILE * __restrict __stream , char const * __restrict __format
, ...) ;
#line 337
extern int printf(char const * __restrict __format , ...) ;
#line 11 "em3d.h"
int n_nodes ;
#line 12 "em3d.h"
int d_nodes ;
#line 13 "em3d.h"
int iters ;
#line 36
void compute_nodes(node_t *nodelist ) ;
#line 13 "make_graph.h"
graph_t initialize_graph(void) ;
#line 148 "/usr/include/stdlib.h"
extern __attribute__((__nothrow__)) int atoi(char const *__nptr ) __attribute__((__pure__,
__nonnull__(1))) ;
#line 395
extern __attribute__((__nothrow__)) double drand48(void) ;
#line 399
extern __attribute__((__nothrow__)) long lrand48(void) ;
#line 409
extern __attribute__((__nothrow__)) void srand48(long __seedval ) ;
#line 471
extern __attribute__((__nothrow__)) void *malloc(size_t __size ) __attribute__((__malloc__)) ;
#line 488
extern __attribute__((__nothrow__)) void free(void *__ptr ) ;
#line 531
extern __attribute__((__nothrow__, __noreturn__)) void exit(int __status ) ;
#line 5 "util.c"
void init_random(int myid )
{ int __cil_tmp2 ;
long __cil_tmp3 ;
{
{
#line 7
__cil_tmp2 = myid * 45;
#line 7
__cil_tmp3 = (long )__cil_tmp2;
#line 7
srand48(__cil_tmp3);
}
#line 8
return;
}
}
#line 11 "util.c"
int gen_number(int range )
{ long tmp ;
long __cil_tmp3 ;
long __cil_tmp4 ;
{
{
#line 13
tmp = lrand48();
}
{
#line 13
__cil_tmp3 = (long )range;
#line 13
__cil_tmp4 = tmp % __cil_tmp3;
#line 13
return ((int )__cil_tmp4);
}
}
}
#line 17 "util.c"
int gen_signed_number(int range )
{ int temp ;
long tmp ;
int __cil_tmp4 ;
int __cil_tmp5 ;
long __cil_tmp6 ;
long __cil_tmp7 ;
int __cil_tmp8 ;
{
{
#line 21
tmp = lrand48();
#line 21
__cil_tmp4 = 2 * range;
#line 21
__cil_tmp5 = __cil_tmp4 - 1;
#line 21
__cil_tmp6 = (long )__cil_tmp5;
#line 21
__cil_tmp7 = tmp % __cil_tmp6;
#line 21
temp = (int )__cil_tmp7;
}
{
#line 22
__cil_tmp8 = range - 1;
#line 22
return (temp - __cil_tmp8);
}
}
}
#line 26 "util.c"
double gen_uniform_double(void)
{ double tmp ;
{
{
#line 28
tmp = drand48();
}
#line 28
return (tmp);
}
}
#line 31 "util.c"
int check_percent(int percent )
{ double tmp ;
double __cil_tmp3 ;
double __cil_tmp4 ;
{
{
#line 33
tmp = drand48();
}
{
#line 33
__cil_tmp3 = (double )percent;
#line 33
__cil_tmp4 = __cil_tmp3 / 100.0;
#line 33
return (tmp < __cil_tmp4);
}
}
}
#line 3 "em3d.c"
void compute_nodes(node_t *nodelist )
{ int i ;
node_t *other_node ;
double coeff ;
double value ;
unsigned int __cil_tmp6 ;
unsigned int __cil_tmp7 ;
int __cil_tmp8 ;
unsigned int __cil_tmp9 ;
unsigned int __cil_tmp10 ;
struct node_t **__cil_tmp11 ;
struct node_t **__cil_tmp12 ;
unsigned int __cil_tmp13 ;
unsigned int __cil_tmp14 ;
double *__cil_tmp15 ;
double *__cil_tmp16 ;
double __cil_tmp17 ;
double __cil_tmp18 ;
unsigned int __cil_tmp19 ;
unsigned int __cil_tmp20 ;
int *mem_21 ;
struct node_t ***mem_22 ;
double **mem_23 ;
double *mem_24 ;
double *mem_25 ;
double *mem_26 ;
struct node_t **mem_27 ;
{
{
#line 7
while (1) {
while_0_continue: /* CIL Label */ ;
#line 7
if (nodelist) {
} else {
goto while_0_break;
}
#line 8
i = 0;
{
#line 8
while (1) {
while_1_continue: /* CIL Label */ ;
{
#line 8
__cil_tmp6 = (unsigned int )nodelist;
#line 8
__cil_tmp7 = __cil_tmp6 + 24;
#line 8
mem_21 = (int *)__cil_tmp7;
#line 8
__cil_tmp8 = *mem_21;
#line 8
if (i < __cil_tmp8) {
} else {
goto while_1_break;
}
}
#line 10
__cil_tmp9 = (unsigned int )nodelist;
#line 10
__cil_tmp10 = __cil_tmp9 + 16;
#line 10
mem_22 = (struct node_t ***)__cil_tmp10;
#line 10
__cil_tmp11 = *mem_22;
#line 10
__cil_tmp12 = __cil_tmp11 + i;
#line 10
other_node = *__cil_tmp12;
#line 11
__cil_tmp13 = (unsigned int )nodelist;
#line 11
__cil_tmp14 = __cil_tmp13 + 20;
#line 11
mem_23 = (double **)__cil_tmp14;
#line 11
__cil_tmp15 = *mem_23;
#line 11
__cil_tmp16 = __cil_tmp15 + i;
#line 11
coeff = *__cil_tmp16;
#line 12
mem_24 = (double *)other_node;
#line 12
value = *mem_24;
#line 14
__cil_tmp17 = coeff * value;
#line 14
mem_25 = (double *)nodelist;
#line 14
__cil_tmp18 = *mem_25;
#line 14
mem_26 = (double *)nodelist;
#line 14
*mem_26 = __cil_tmp18 - __cil_tmp17;
#line 8
i = i + 1;
}
while_1_break: /* CIL Label */ ;
}
#line 7
__cil_tmp19 = (unsigned int )nodelist;
#line 7
__cil_tmp20 = __cil_tmp19 + 8;
#line 7
mem_27 = (struct node_t **)__cil_tmp20;
#line 7
nodelist = *mem_27;
}
while_0_break: /* CIL Label */ ;
}
#line 16
return;
}
}
#line 23 "make_graph.c"
node_t **make_table(int size )
{ node_t **retval ;
void *tmp ;
unsigned int __cil_tmp4 ;
unsigned int __cil_tmp5 ;
char const * __restrict __cil_tmp6 ;
{
{
#line 27
__cil_tmp4 = (unsigned int )size;
#line 27
__cil_tmp5 = __cil_tmp4 * 4U;
#line 27
tmp = malloc(__cil_tmp5);
#line 27
retval = (node_t **)tmp;
}
#line 28
if (! retval) {
{
#line 28
__cil_tmp6 = (char const * __restrict )"Assertion failure\n";
#line 28
printf(__cil_tmp6);
#line 28
exit(-1);
}
} else {
}
#line 29
return (retval);
}
}
#line 35 "make_graph.c"
void fill_table(node_t **table , int size )
{ int i ;
void *tmp ;
node_t **__cil_tmp5 ;
node_t **__cil_tmp6 ;
node_t *__cil_tmp7 ;
node_t **__cil_tmp8 ;
node_t *__cil_tmp9 ;
unsigned int __cil_tmp10 ;
unsigned int __cil_tmp11 ;
int __cil_tmp12 ;
node_t **__cil_tmp13 ;
node_t *__cil_tmp14 ;
unsigned int __cil_tmp15 ;
unsigned int __cil_tmp16 ;
node_t **__cil_tmp17 ;
int __cil_tmp18 ;
node_t **__cil_tmp19 ;
node_t *__cil_tmp20 ;
unsigned int __cil_tmp21 ;
unsigned int __cil_tmp22 ;
void *__cil_tmp23 ;
double *mem_24 ;
int *mem_25 ;
struct node_t **mem_26 ;
struct node_t **mem_27 ;
{
#line 40
i = 0;
{
#line 40
while (1) {
while_2_continue: /* CIL Label */ ;
#line 40
if (i < size) {
} else {
goto while_2_break;
}
{
#line 42
tmp = malloc(28U);
#line 42
__cil_tmp5 = table + i;
#line 42
*__cil_tmp5 = (node_t *)tmp;
#line 43
__cil_tmp6 = table + i;
#line 43
__cil_tmp7 = *__cil_tmp6;
#line 43
mem_24 = (double *)__cil_tmp7;
#line 43
*mem_24 = gen_uniform_double();
#line 44
__cil_tmp8 = table + i;
#line 44
__cil_tmp9 = *__cil_tmp8;
#line 44
__cil_tmp10 = (unsigned int )__cil_tmp9;
#line 44
__cil_tmp11 = __cil_tmp10 + 24;
#line 44
mem_25 = (int *)__cil_tmp11;
#line 44
*mem_25 = 0;
}
#line 46
if (i > 0) {
#line 47
__cil_tmp12 = i - 1;
#line 47
__cil_tmp13 = table + __cil_tmp12;
#line 47
__cil_tmp14 = *__cil_tmp13;
#line 47
__cil_tmp15 = (unsigned int )__cil_tmp14;
#line 47
__cil_tmp16 = __cil_tmp15 + 8;
#line 47
__cil_tmp17 = table + i;
#line 47
mem_26 = (struct node_t **)__cil_tmp16;
#line 47
*mem_26 = *__cil_tmp17;
} else {
}
#line 40
i = i + 1;
}
while_2_break: /* CIL Label */ ;
}
#line 49
__cil_tmp18 = size - 1;
#line 49
__cil_tmp19 = table + __cil_tmp18;
#line 49
__cil_tmp20 = *__cil_tmp19;
#line 49
__cil_tmp21 = (unsigned int )__cil_tmp20;
#line 49
__cil_tmp22 = __cil_tmp21 + 8;
#line 49
__cil_tmp23 = (void *)0;
#line 49
mem_27 = (struct node_t **)__cil_tmp22;
#line 49
*mem_27 = (struct node_t *)__cil_tmp23;
#line 50
return;
}
}
#line 57 "make_graph.c"
void make_neighbors(node_t *nodelist , node_t **table , int tablesz , int degree )
{ node_t *cur_node ;
node_t *other_node ;
int j ;
int k ;
void *tmp ;
int tmp___0 ;
unsigned int __cil_tmp11 ;
unsigned int __cil_tmp12 ;
unsigned int __cil_tmp13 ;
unsigned int __cil_tmp14 ;
node_t **__cil_tmp15 ;
unsigned int __cil_tmp16 ;
unsigned int __cil_tmp17 ;
struct node_t **__cil_tmp18 ;
struct node_t **__cil_tmp19 ;
struct node_t *__cil_tmp20 ;
unsigned int __cil_tmp21 ;
unsigned int __cil_tmp22 ;
unsigned int __cil_tmp23 ;
unsigned int __cil_tmp24 ;
struct node_t **__cil_tmp25 ;
struct node_t **__cil_tmp26 ;
unsigned int __cil_tmp27 ;
unsigned int __cil_tmp28 ;
unsigned int __cil_tmp29 ;
unsigned int __cil_tmp30 ;
int __cil_tmp31 ;
unsigned int __cil_tmp32 ;
unsigned int __cil_tmp33 ;
struct node_t ***mem_34 ;
struct node_t ***mem_35 ;
struct node_t ***mem_36 ;
int *mem_37 ;
int *mem_38 ;
struct node_t **mem_39 ;
{
#line 62
cur_node = nodelist;
{
#line 62
while (1) {
while_3_continue: /* CIL Label */ ;
#line 62
if (cur_node) {
} else {
goto while_3_break;
}
{
#line 67
__cil_tmp11 = (unsigned int )degree;
#line 67
__cil_tmp12 = __cil_tmp11 * 4U;
#line 67
tmp = malloc(__cil_tmp12);
#line 67
__cil_tmp13 = (unsigned int )cur_node;
#line 67
__cil_tmp14 = __cil_tmp13 + 12;
#line 67
mem_34 = (struct node_t ***)__cil_tmp14;
#line 67
*mem_34 = (node_t **)tmp;
#line 68
j = 0;
}
{
#line 68
while (1) {
while_4_continue: /* CIL Label */ ;
#line 68
if (j < degree) {
} else {
goto while_4_break;
}
{
#line 71
while (1) {
while_5_continue: /* CIL Label */ ;
{
#line 73
tmp___0 = gen_number(tablesz);
#line 73
__cil_tmp15 = table + tmp___0;
#line 73
other_node = *__cil_tmp15;
#line 74
k = 0;
}
{
#line 74
while (1) {
while_6_continue: /* CIL Label */ ;
#line 74
if (k < j) {
} else {
goto while_6_break;
}
{
#line 75
__cil_tmp16 = (unsigned int )cur_node;
#line 75
__cil_tmp17 = __cil_tmp16 + 12;
#line 75
mem_35 = (struct node_t ***)__cil_tmp17;
#line 75
__cil_tmp18 = *mem_35;
#line 75
__cil_tmp19 = __cil_tmp18 + k;
#line 75
__cil_tmp20 = *__cil_tmp19;
#line 75
__cil_tmp21 = (unsigned int )__cil_tmp20;
#line 75
__cil_tmp22 = (unsigned int )other_node;
#line 75
if (__cil_tmp22 == __cil_tmp21) {
goto while_6_break;
} else {
}
}
#line 74
k = k + 1;
}
while_6_break: /* CIL Label */ ;
}
#line 71
if (k < j) {
} else {
goto while_5_break;
}
}
while_5_break: /* CIL Label */ ;
}
#line 78
__cil_tmp23 = (unsigned int )cur_node;
#line 78
__cil_tmp24 = __cil_tmp23 + 12;
#line 78
mem_36 = (struct node_t ***)__cil_tmp24;
#line 78
__cil_tmp25 = *mem_36;
#line 78
__cil_tmp26 = __cil_tmp25 + j;
#line 78
*__cil_tmp26 = other_node;
#line 79
__cil_tmp27 = (unsigned int )other_node;
#line 79
__cil_tmp28 = __cil_tmp27 + 24;
#line 79
__cil_tmp29 = (unsigned int )other_node;
#line 79
__cil_tmp30 = __cil_tmp29 + 24;
#line 79
mem_37 = (int *)__cil_tmp30;
#line 79
__cil_tmp31 = *mem_37;
#line 79
mem_38 = (int *)__cil_tmp28;
#line 79
*mem_38 = __cil_tmp31 + 1;
#line 68
j = j + 1;
}
while_4_break: /* CIL Label */ ;
}
#line 62
__cil_tmp32 = (unsigned int )cur_node;
#line 62
__cil_tmp33 = __cil_tmp32 + 8;
#line 62
mem_39 = (struct node_t **)__cil_tmp33;
#line 62
cur_node = *mem_39;
}
while_3_break: /* CIL Label */ ;
}
#line 82
return;
}
}
#line 88 "make_graph.c"
void update_from_coeffs(node_t *nodelist )
{ node_t *cur_node ;
int from_count ;
int k ;
void *tmp ;
void *tmp___0 ;
unsigned int __cil_tmp7 ;
unsigned int __cil_tmp8 ;
unsigned int __cil_tmp9 ;
unsigned int __cil_tmp10 ;
unsigned int __cil_tmp11 ;
unsigned int __cil_tmp12 ;
unsigned int __cil_tmp13 ;
unsigned int __cil_tmp14 ;
unsigned int __cil_tmp15 ;
unsigned int __cil_tmp16 ;
unsigned int __cil_tmp17 ;
unsigned int __cil_tmp18 ;
double *__cil_tmp19 ;
double *__cil_tmp20 ;
unsigned int __cil_tmp21 ;
unsigned int __cil_tmp22 ;
unsigned int __cil_tmp23 ;
unsigned int __cil_tmp24 ;
int *mem_25 ;
struct node_t ***mem_26 ;
double **mem_27 ;
double **mem_28 ;
int *mem_29 ;
struct node_t **mem_30 ;
{
#line 93
cur_node = nodelist;
{
#line 93
while (1) {
while_7_continue: /* CIL Label */ ;
#line 93
if (cur_node) {
} else {
goto while_7_break;
}
{
#line 95
__cil_tmp7 = (unsigned int )cur_node;
#line 95
__cil_tmp8 = __cil_tmp7 + 24;
#line 95
mem_25 = (int *)__cil_tmp8;
#line 95
from_count = *mem_25;
#line 98
__cil_tmp9 = (unsigned int )from_count;
#line 98
__cil_tmp10 = __cil_tmp9 * 4U;
#line 98
tmp = malloc(__cil_tmp10);
#line 98
__cil_tmp11 = (unsigned int )cur_node;
#line 98
__cil_tmp12 = __cil_tmp11 + 16;
#line 98
mem_26 = (struct node_t ***)__cil_tmp12;
#line 98
*mem_26 = (node_t **)tmp;
#line 99
__cil_tmp13 = (unsigned int )from_count;
#line 99
__cil_tmp14 = __cil_tmp13 * 8U;
#line 99
tmp___0 = malloc(__cil_tmp14);
#line 99
__cil_tmp15 = (unsigned int )cur_node;
#line 99
__cil_tmp16 = __cil_tmp15 + 20;
#line 99
mem_27 = (double **)__cil_tmp16;
#line 99
*mem_27 = (double *)tmp___0;
#line 100
k = 0;
}
{
#line 100
while (1) {
while_8_continue: /* CIL Label */ ;
#line 100
if (k < from_count) {
} else {
goto while_8_break;
}
{
#line 101
__cil_tmp17 = (unsigned int )cur_node;
#line 101
__cil_tmp18 = __cil_tmp17 + 20;
#line 101
mem_28 = (double **)__cil_tmp18;
#line 101
__cil_tmp19 = *mem_28;
#line 101
__cil_tmp20 = __cil_tmp19 + k;
#line 101
*__cil_tmp20 = gen_uniform_double();
#line 100
k = k + 1;
}
}
while_8_break: /* CIL Label */ ;
}
#line 103
__cil_tmp21 = (unsigned int )cur_node;
#line 103
__cil_tmp22 = __cil_tmp21 + 24;
#line 103
mem_29 = (int *)__cil_tmp22;
#line 103
*mem_29 = 0;
#line 93
__cil_tmp23 = (unsigned int )cur_node;
#line 93
__cil_tmp24 = __cil_tmp23 + 8;
#line 93
mem_30 = (struct node_t **)__cil_tmp24;
#line 93
cur_node = *mem_30;
}
while_7_break: /* CIL Label */ ;
}
#line 105
return;
}
}
#line 114 "make_graph.c"
void fill_from_fields(node_t *nodelist , int degree )
{ node_t *cur_node ;
int j ;
node_t *other_node ;
unsigned int __cil_tmp6 ;
unsigned int __cil_tmp7 ;
struct node_t **__cil_tmp8 ;
struct node_t **__cil_tmp9 ;
unsigned int __cil_tmp10 ;
unsigned int __cil_tmp11 ;
int __cil_tmp12 ;
unsigned int __cil_tmp13 ;
unsigned int __cil_tmp14 ;
struct node_t **__cil_tmp15 ;
struct node_t **__cil_tmp16 ;
unsigned int __cil_tmp17 ;
unsigned int __cil_tmp18 ;
unsigned int __cil_tmp19 ;
unsigned int __cil_tmp20 ;
int __cil_tmp21 ;
unsigned int __cil_tmp22 ;
unsigned int __cil_tmp23 ;
struct node_t ***mem_24 ;
int *mem_25 ;
struct node_t ***mem_26 ;
int *mem_27 ;
int *mem_28 ;
struct node_t **mem_29 ;
{
#line 117
cur_node = nodelist;
{
#line 117
while (1) {
while_9_continue: /* CIL Label */ ;
#line 117
if (cur_node) {
} else {
goto while_9_break;
}
#line 121
j = 0;
{
#line 121
while (1) {
while_10_continue: /* CIL Label */ ;
#line 121
if (j < degree) {
} else {
goto while_10_break;
}
#line 123
__cil_tmp6 = (unsigned int )cur_node;
#line 123
__cil_tmp7 = __cil_tmp6 + 12;
#line 123
mem_24 = (struct node_t ***)__cil_tmp7;
#line 123
__cil_tmp8 = *mem_24;
#line 123
__cil_tmp9 = __cil_tmp8 + j;
#line 123
other_node = *__cil_tmp9;
#line 124
__cil_tmp10 = (unsigned int )other_node;
#line 124
__cil_tmp11 = __cil_tmp10 + 24;
#line 124
mem_25 = (int *)__cil_tmp11;
#line 124
__cil_tmp12 = *mem_25;
#line 124
__cil_tmp13 = (unsigned int )other_node;
#line 124
__cil_tmp14 = __cil_tmp13 + 16;
#line 124
mem_26 = (struct node_t ***)__cil_tmp14;
#line 124
__cil_tmp15 = *mem_26;
#line 124
__cil_tmp16 = __cil_tmp15 + __cil_tmp12;
#line 124
*__cil_tmp16 = cur_node;
#line 125
__cil_tmp17 = (unsigned int )other_node;
#line 125
__cil_tmp18 = __cil_tmp17 + 24;
#line 125
__cil_tmp19 = (unsigned int )other_node;
#line 125
__cil_tmp20 = __cil_tmp19 + 24;
#line 125
mem_27 = (int *)__cil_tmp20;
#line 125
__cil_tmp21 = *mem_27;
#line 125
mem_28 = (int *)__cil_tmp18;
#line 125
*mem_28 = __cil_tmp21 + 1;
#line 121
j = j + 1;
}
while_10_break: /* CIL Label */ ;
}
#line 117
__cil_tmp22 = (unsigned int )cur_node;
#line 117
__cil_tmp23 = __cil_tmp22 + 8;
#line 117
mem_29 = (struct node_t **)__cil_tmp23;
#line 117
cur_node = *mem_29;
}
while_9_break: /* CIL Label */ ;
}
#line 128
return;
}
}
#line 136 "make_graph.c"
graph_t initialize_graph(void)
{ node_t **h_table ;
node_t **e_table ;
graph_t retval ;
node_t **__cil_tmp4 ;
node_t *__cil_tmp5 ;
node_t **__cil_tmp6 ;
node_t *__cil_tmp7 ;
node_t **__cil_tmp8 ;
node_t *__cil_tmp9 ;
node_t **__cil_tmp10 ;
node_t *__cil_tmp11 ;
node_t **__cil_tmp12 ;
node_t *__cil_tmp13 ;
node_t **__cil_tmp14 ;
node_t *__cil_tmp15 ;
node_t **__cil_tmp16 ;
node_t **__cil_tmp17 ;
void *__cil_tmp18 ;
void *__cil_tmp19 ;
{
{
#line 143
h_table = make_table(n_nodes);
#line 144
fill_table(h_table, n_nodes);
#line 147
e_table = make_table(n_nodes);
#line 148
fill_table(e_table, n_nodes);
#line 152
__cil_tmp4 = h_table + 0;
#line 152
__cil_tmp5 = *__cil_tmp4;
#line 152
make_neighbors(__cil_tmp5, e_table, n_nodes, d_nodes);
#line 153
__cil_tmp6 = e_table + 0;
#line 153
__cil_tmp7 = *__cil_tmp6;
#line 153
make_neighbors(__cil_tmp7, h_table, n_nodes, d_nodes);
#line 156
__cil_tmp8 = h_table + 0;
#line 156
__cil_tmp9 = *__cil_tmp8;
#line 156
update_from_coeffs(__cil_tmp9);
#line 157
__cil_tmp10 = e_table + 0;
#line 157
__cil_tmp11 = *__cil_tmp10;
#line 157
update_from_coeffs(__cil_tmp11);
#line 160
__cil_tmp12 = h_table + 0;
#line 160
__cil_tmp13 = *__cil_tmp12;
#line 160
fill_from_fields(__cil_tmp13, d_nodes);
#line 161
__cil_tmp14 = e_table + 0;
#line 161
__cil_tmp15 = *__cil_tmp14;
#line 161
fill_from_fields(__cil_tmp15, d_nodes);
#line 163
__cil_tmp16 = e_table + 0;
#line 163
retval.e_nodes = *__cil_tmp16;
#line 164
__cil_tmp17 = h_table + 0;
#line 164
retval.h_nodes = *__cil_tmp17;
#line 166
__cil_tmp18 = (void *)h_table;
#line 166
free(__cil_tmp18);
#line 167
__cil_tmp19 = (void *)e_table;
#line 167
free(__cil_tmp19);
}
#line 169
return (retval);
}
}
#line 5 "args.c"
void dealwithargs(int argc , char **argv )
{ char **__cil_tmp3 ;
char *__cil_tmp4 ;
char const *__cil_tmp5 ;
char **__cil_tmp6 ;
char *__cil_tmp7 ;
char const *__cil_tmp8 ;
char **__cil_tmp9 ;
char *__cil_tmp10 ;
char const *__cil_tmp11 ;
{
#line 7
if (argc > 1) {
{
#line 8
__cil_tmp3 = argv + 1;
#line 8
__cil_tmp4 = *__cil_tmp3;
#line 8
__cil_tmp5 = (char const *)__cil_tmp4;
#line 8
n_nodes = atoi(__cil_tmp5);
}
} else {
#line 10
n_nodes = 10;
}
#line 12
if (argc > 2) {
{
#line 13
__cil_tmp6 = argv + 2;
#line 13
__cil_tmp7 = *__cil_tmp6;
#line 13
__cil_tmp8 = (char const *)__cil_tmp7;
#line 13
d_nodes = atoi(__cil_tmp8);
}
} else {
#line 15
d_nodes = 3;
}
#line 17
if (argc > 3) {
{
#line 18
__cil_tmp9 = argv + 3;
#line 18
__cil_tmp10 = *__cil_tmp9;
#line 18
__cil_tmp11 = (char const *)__cil_tmp10;
#line 18
iters = atoi(__cil_tmp11);
}
} else {
#line 20
iters = 100;
}
#line 21
return;
}
}
#line 12 "main.c"
void print_graph(node_t *graph_e_nodes3 , node_t *graph_h_nodes2 )
{
{
#line 28
return;
}
}
#line 32 "main.c"
int main(int argc , char **argv )
{ int i ;
graph_t graph ;
FILE * __restrict __cil_tmp5 ;
char const * __restrict __cil_tmp6 ;
{
{
#line 37
dealwithargs(argc, argv);
#line 38
graph = initialize_graph();
#line 39
print_graph(graph.e_nodes, graph.h_nodes);
#line 41
i = 0;
}
{
#line 41
while (1) {
while_11_continue: /* CIL Label */ ;
#line 41
if (i < iters) {
} else {
goto while_11_break;
}
{
#line 43
compute_nodes(graph.e_nodes);
#line 44
compute_nodes(graph.h_nodes);
#line 45
__cil_tmp5 = (FILE * __restrict )stderr;
#line 45
__cil_tmp6 = (char const * __restrict )"Completed a computation phase: %d\n";
#line 45
fprintf(__cil_tmp5, __cil_tmp6, i);
#line 46
print_graph(graph.e_nodes, graph.h_nodes);
#line 41
i = i + 1;
}
}
while_11_break: /* CIL Label */ ;
}
#line 48
return (0);
}
}
|
the_stack_data/82950570.c | int foo() {
#pragma spf transform propagate
int A[3], X, Y, Z;
for (int I = 0; I < 3; ++I)
A[I] = I;
X = A[0];
Y = A[1];
Z = A[2];
return X + Y + Z;
}
|
the_stack_data/701787.c | #include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <stdlib.h>
void clearLine(FILE* fp) {
int c = 0;
while ((c = getchar()) != EOF && c != '\n');
}
bool isTestFailed(float function(float, int), float base, int power, float result) {
if (function(base, power) != result) {
printf("Failed\n");
printf("base = %f\n", base);
printf("power = %i\n", power);
printf("result = %f\n", result);
printf("output = %f\n\n", function(base, power));
return true;
}
return false;
}
bool areTestsFailed(float function(float, int)) {
bool test = false;
test = test || isTestFailed(function, -5, 0, 1);
test = test || isTestFailed(function, 2, 4, 16);
test = test || isTestFailed(function, 5, 2, 25);
test = test || isTestFailed(function, 7, 3, 343);
test = test || isTestFailed(function, -5, 3, -125);
test = test || isTestFailed(function, 2, -2, 0.25);
test = test || isTestFailed(function, 10, -3, 0.001);
test = test || isTestFailed(function, -10, 3, -1000);
test = test || isTestFailed(function, -5, 2, 25);
test = test || isTestFailed(function, -50000, 2001, -INFINITY);
test = test || isTestFailed(function, 50000, 2000, INFINITY);
test = test || isTestFailed(function, 50000, -2000, 0);
test = test || isTestFailed(function, 0, 20, 0);
test = test || isTestFailed(function, 0, 0, 0);
test = test || isTestFailed(function, 0.25, 2, 0.0625);
test = test || isTestFailed(function, 0.25, -2, 16);
test = test || isTestFailed(function, 2, 5, 32);
test = test || isTestFailed(function, 2, 6, 64);
test = test || isTestFailed(function, 2, 7, 128);
return test;
}
float exponentiationForLineTime(float base, int power) {
if (base != 0 && power == 0) {
return 1;
}
if (power == 1) {
return base;
}
if (power == -1) {
return 1 / base;
}
float result = base;
if (abs(power) > 1) {
for (int i = 1; i < abs(power); ++i) {
result *= base;
}
if (power < 0) {
result = 1 / result;
}
return result;
}
return 0;
}
float exponentiationForLogarithmTime(float base, int power) {
if (base != 0 && power == 0) {
return 1;
}
if (power == 1) {
return base;
}
if (power == -1) {
return 1 / base;
}
if (abs(power) > 1) {
float result = 1;
float subResult = base;
int subPower = abs(power);
while (subPower > 0) {
if ((subPower & 1) == 1) {
result *= subResult;
}
subResult *= subResult;
subPower >>= 1;
}
if (power < 0) {
result = 1 / result;
}
return result;
}
return 0;
}
void outputFunction(float base, int power, float num) {
if (num == 0 || num == INFINITY || num == -INFINITY) {
printf("Invalid input\n");
return;
}
printf("%f to the power of %i equals %f\n", base, power, num);
}
void main() {
bool stop = false;
if (areTestsFailed(exponentiationForLineTime)) {
printf("exponentiationForLineTime\n\n");
stop = true;
}
if (areTestsFailed(exponentiationForLogarithmTime)) {
printf("exponentiationForLogarithmTime\n\n");
stop = true;
}
if (stop) {
return;
}
printf("What algorithm should I use?\n\n");
printf("'F' - exponentiationForLineTime\n\n");
printf("'S' - exponentiationForLogarithmTime\n\n");
char answer = 'W';
scanf("%c", &answer);
while (answer != 'F' && answer != 'S') {
clearLine(stdin);
printf("Invalid input. Try again\n");
scanf("%c", &answer);
}
printf("\nEnter base != 0\n");
float base = 0;
scanf("%f", &base);
printf("Enter integer power\n");
int power = 0;
scanf("%i", &power);
printf("\n");
if (answer == 'F') {
outputFunction(base, power, exponentiationForLineTime(base, power));
return;
}
if (answer == 'S') {
outputFunction(base, power, exponentiationForLogarithmTime(base, power));
return;
}
} |
the_stack_data/76699201.c | /*
* @file startup_efm32lg.c
* @brief CMSIS Compatible EFM32LG startup file in C.
* Should be used with GCC 'GNU Tools ARM Embedded'
* @version 5.1.3
* Date: 12 June 2014
*
*/
/* Copyright (c) 2011 - 2014 ARM LIMITED
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 ARM 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 COPYRIGHT HOLDERS AND 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 <stdint.h>
/*----------------------------------------------------------------------------
Linker generated Symbols
*----------------------------------------------------------------------------*/
extern uint32_t __etext;
extern uint32_t __data_start__;
extern uint32_t __data_end__;
extern uint32_t __copy_table_start__;
extern uint32_t __copy_table_end__;
extern uint32_t __zero_table_start__;
extern uint32_t __zero_table_end__;
extern uint32_t __bss_start__;
extern uint32_t __bss_end__;
extern uint32_t __StackTop;
/*----------------------------------------------------------------------------
Exception / Interrupt Handler Function Prototype
*----------------------------------------------------------------------------*/
typedef void( *pFunc )( void );
/*----------------------------------------------------------------------------
External References
*----------------------------------------------------------------------------*/
#ifndef __START
extern void _start(void) __attribute__((noreturn)); /* Pre Main (C library entry point) */
#else
extern int __START(void) __attribute__((noreturn)); /* main entry point */
#endif
#ifndef __NO_SYSTEM_INIT
extern void SystemInit (void); /* CMSIS System Initialization */
#endif
/*----------------------------------------------------------------------------
Internal References
*----------------------------------------------------------------------------*/
void Default_Handler(void); /* Default empty handler */
void Reset_Handler(void); /* Reset Handler */
/*----------------------------------------------------------------------------
User Initial Stack & Heap
*----------------------------------------------------------------------------*/
#ifndef __STACK_SIZE
#define __STACK_SIZE 0x00000400
#endif
static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));
#ifndef __HEAP_SIZE
#define __HEAP_SIZE 0x00000C00
#endif
#if __HEAP_SIZE > 0
static uint8_t heap[__HEAP_SIZE] __attribute__ ((aligned(8), used, section(".heap")));
#endif
/*----------------------------------------------------------------------------
Exception / Interrupt Handler
*----------------------------------------------------------------------------*/
/* Cortex-M Processor Exceptions */
void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
/* Part Specific Interrupts */
void DMA_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void GPIO_EVEN_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void TIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USART0_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USART0_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USB_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void ACMP0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void ADC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void DAC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void I2C0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void I2C1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void GPIO_ODD_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void TIMER1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void TIMER2_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void TIMER3_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USART1_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USART1_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void LESENSE_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USART2_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void USART2_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void UART0_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void UART0_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void UART1_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void UART1_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void LEUART0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void LEUART1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void LETIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void PCNT0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void PCNT1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void PCNT2_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void RTC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void BURTC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void CMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void VCMP_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void LCD_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void MSC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void AES_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void EBI_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
void EMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
/*----------------------------------------------------------------------------
Exception / Interrupt Vector table
*----------------------------------------------------------------------------*/
const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {
/* Cortex-M Exception Handlers */
(pFunc)&__StackTop, /* Initial Stack Pointer */
Reset_Handler, /* Reset Handler */
NMI_Handler, /* NMI Handler */
HardFault_Handler, /* Hard Fault Handler */
MemManage_Handler, /* MPU Fault Handler */
BusFault_Handler, /* Bus Fault Handler */
UsageFault_Handler, /* Usage Fault Handler */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
Default_Handler, /* Reserved */
SVC_Handler, /* SVCall Handler */
DebugMon_Handler, /* Debug Monitor Handler */
Default_Handler, /* Reserved */
PendSV_Handler, /* PendSV Handler */
SysTick_Handler, /* SysTick Handler */
/* External interrupts */
DMA_IRQHandler, /* 0 - DMA */
GPIO_EVEN_IRQHandler, /* 1 - GPIO_EVEN */
TIMER0_IRQHandler, /* 2 - TIMER0 */
USART0_RX_IRQHandler, /* 3 - USART0_RX */
USART0_TX_IRQHandler, /* 4 - USART0_TX */
USB_IRQHandler, /* 5 - USB */
ACMP0_IRQHandler, /* 6 - ACMP0 */
ADC0_IRQHandler, /* 7 - ADC0 */
DAC0_IRQHandler, /* 8 - DAC0 */
I2C0_IRQHandler, /* 9 - I2C0 */
I2C1_IRQHandler, /* 10 - I2C1 */
GPIO_ODD_IRQHandler, /* 11 - GPIO_ODD */
TIMER1_IRQHandler, /* 12 - TIMER1 */
TIMER2_IRQHandler, /* 13 - TIMER2 */
TIMER3_IRQHandler, /* 14 - TIMER3 */
USART1_RX_IRQHandler, /* 15 - USART1_RX */
USART1_TX_IRQHandler, /* 16 - USART1_TX */
LESENSE_IRQHandler, /* 17 - LESENSE */
USART2_RX_IRQHandler, /* 18 - USART2_RX */
USART2_TX_IRQHandler, /* 19 - USART2_TX */
UART0_RX_IRQHandler, /* 20 - UART0_RX */
UART0_TX_IRQHandler, /* 21 - UART0_TX */
UART1_RX_IRQHandler, /* 22 - UART1_RX */
UART1_TX_IRQHandler, /* 23 - UART1_TX */
LEUART0_IRQHandler, /* 24 - LEUART0 */
LEUART1_IRQHandler, /* 25 - LEUART1 */
LETIMER0_IRQHandler, /* 26 - LETIMER0 */
PCNT0_IRQHandler, /* 27 - PCNT0 */
PCNT1_IRQHandler, /* 28 - PCNT1 */
PCNT2_IRQHandler, /* 29 - PCNT2 */
RTC_IRQHandler, /* 30 - RTC */
BURTC_IRQHandler, /* 31 - BURTC */
CMU_IRQHandler, /* 32 - CMU */
VCMP_IRQHandler, /* 33 - VCMP */
LCD_IRQHandler, /* 34 - LCD */
MSC_IRQHandler, /* 35 - MSC */
AES_IRQHandler, /* 36 - AES */
EBI_IRQHandler, /* 37 - EBI */
EMU_IRQHandler, /* 38 - EMU */
Default_Handler, /* 39 - Reserved */
};
/*----------------------------------------------------------------------------
Reset Handler called on controller reset
*----------------------------------------------------------------------------*/
void Reset_Handler(void) {
uint32_t *pSrc, *pDest;
uint32_t *pTable __attribute__((unused));
#ifndef __NO_SYSTEM_INIT
SystemInit();
#endif
/* Firstly it copies data from read only memory to RAM. There are two schemes
* to copy. One can copy more than one sections. Another can only copy
* one section. The former scheme needs more instructions and read-only
* data to implement than the latter.
* Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
#ifdef __STARTUP_COPY_MULTIPLE
/* Multiple sections scheme.
*
* Between symbol address __copy_table_start__ and __copy_table_end__,
* there are array of triplets, each of which specify:
* offset 0: LMA of start of a section to copy from
* offset 4: VMA of start of a section to copy to
* offset 8: size of the section to copy. Must be multiply of 4
*
* All addresses must be aligned to 4 bytes boundary.
*/
pTable = &__copy_table_start__;
for (; pTable < &__copy_table_end__; pTable = pTable + 3)
{
pSrc = (uint32_t*)*(pTable + 0);
pDest = (uint32_t*)*(pTable + 1);
for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; )
{
*pDest++ = *pSrc++;
}
}
#else
/* Single section scheme.
*
* The ranges of copy from/to are specified by following symbols
* __etext: LMA of start of the section to copy from. Usually end of text
* __data_start__: VMA of start of the section to copy to
* __data_end__: VMA of end of the section to copy to
*
* All addresses must be aligned to 4 bytes boundary.
*/
pSrc = &__etext;
pDest = &__data_start__;
for ( ; pDest < &__data_end__ ; )
{
*pDest++ = *pSrc++;
}
#endif /*__STARTUP_COPY_MULTIPLE */
/* This part of work usually is done in C library startup code. Otherwise,
* define this macro to enable it in this startup.
*
* There are two schemes too. One can clear multiple BSS sections. Another
* can only clear one section. The former is more size expensive than the
* latter.
*
* Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
* Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
*/
#ifdef __STARTUP_CLEAR_BSS_MULTIPLE
/* Multiple sections scheme.
*
* Between symbol address __zero_table_start__ and __zero_table_end__,
* there are array of tuples specifying:
* offset 0: Start of a BSS section
* offset 4: Size of this BSS section. Must be multiply of 4
*/
pTable = &__zero_table_start__;
for (; pTable < &__zero_table_end__; pTable = pTable + 2)
{
pDest = (uint32_t*)*(pTable + 0);
for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )
{
*pDest++ = 0;
}
}
#elif defined (__STARTUP_CLEAR_BSS)
/* Single BSS section scheme.
*
* The BSS section is specified by following symbols
* __bss_start__: start of the BSS section.
* __bss_end__: end of the BSS section.
*
* Both addresses must be aligned to 4 bytes boundary.
*/
pDest = &__bss_start__;
for ( ; pDest < &__bss_end__ ; )
{
*pDest++ = 0ul;
}
#endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
#ifndef __START
#define __START _start
#endif
__START();
}
/*----------------------------------------------------------------------------
Default Handler for Exceptions / Interrupts
*----------------------------------------------------------------------------*/
void Default_Handler(void)
{
while(1);
}
|
the_stack_data/184519383.c | #include <stdio.h>
#include <stdlib.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define GREATER 1
#define EQUAL 0
#define LESS -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
// assume the elements are of type int
typedef int ElemType;
typedef int Status;
typedef struct {
ElemType *elem;
int length;
int listsize;
} SqList;
int precede(ElemType x, ElemType y) {
return x < y;
}
Status InitList_Sq(SqList *L) {
L -> elem = (ElemType*)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if (!L -> elem) exit(OVERFLOW);
L -> length = 0;
L -> listsize = LIST_INIT_SIZE;
return OK;
}
// compare two sequential lists
Status CompareList_Sq(SqList *A, SqList *B) {
int p = 0;
while (A -> elem[p] == B -> elem[p]) {
++p;
if (p == A -> length)
return (p == B -> length)? EQUAL: LESS;
}
if (precede(A -> elem[p], B -> elem[p]))
return LESS;
return GREATER;
}
void DestroyList_Sq(SqList *L) {
free(L);
}
int main() {
SqList L, M, N, O;
int l[] = {1, 2, 3, 4, 5, 6, 7};
int m[] = {1, 2, 3, 5, 6, 7, 8};
int n[] = {1, 2, 3, 5, 6, 7, 8, 9};
if (InitList_Sq(&L) && InitList_Sq(&M) && InitList_Sq(&N) && InitList_Sq(&O)) {
int i;
Status result;
for (i = 0; i < 7; i++)
L.elem[i] = l[i];
L.length = 7;
for (i = 0; i < 7; i++)
M.elem[i] = m[i];
M.length = 7;
for (i = 0; i < 8; i++) {
N.elem[i] = n[i];
O.elem[i] = n[i];
}
N.length = 8;
O.length = 8;
printf("L %c M\n", ((result = CompareList_Sq(&L, &M)) == GREATER)? '>': (result == LESS)? '<': '=');
printf("M %c N\n", ((result = CompareList_Sq(&M, &N)) == GREATER)? '>': (result == LESS)? '<': '=');
printf("M %c L\n", ((result = CompareList_Sq(&M, &L)) == GREATER)? '>': (result == LESS)? '<': '=');
printf("N %c O\n", ((result = CompareList_Sq(&N, &O)) == GREATER)? '>': (result == LESS)? '<': '=');
}
else {
printf("Error");
exit(ERROR);
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.